[AC_HELP_STRING([--disable-mem-pools],
[disable all glib memory pools])],,
[disable_mem_pools=no])
-AC_ARG_ENABLE(threads,
- [AC_HELP_STRING([--enable-threads],
- [turn on basic thread support [default=yes]
-([=no] will override --with-threads)])],,
- [enable_threads=yes])
AC_ARG_ENABLE(rebuilds,
[AC_HELP_STRING([--disable-rebuilds],
[disable all source autogeneration rules])],,
[enable_rebuilds=yes])
-if test "x$enable_threads" != "xyes"; then
- enable_threads=no
-fi
-
AC_MSG_CHECKING([whether to enable garbage collector friendliness])
if test "x$enable_gc_friendly" = "xyes"; then
AC_DEFINE(ENABLE_GC_FRIENDLY_DEFAULT, 1, [Whether to enable GC friendliness by default])
dnl ***********************
AC_ARG_WITH(threads,
- [AC_HELP_STRING([--with-threads=@<:@none/posix/dce/win32@:>@],
+ [AC_HELP_STRING([--with-threads=@<:@posix/dce/win32@:>@],
[specify a thread implementation to use])],
[if test "x$with_threads" = x; then
want_threads=yes
want_threads=$with_threads
fi],
[want_threads=yes])
-if test "x$enable_threads" = "xno"; then
- want_threads=no
-fi
dnl error and warning message
dnl *************************
THREAD_NO_IMPLEMENTATION="You do not have any known thread system on your
- computer. GLib will not have a default thread implementation."
+ computer."
FLAG_DOES_NOT_WORK="I can't find the MACRO to enable thread safety on your
platform (normally it's "_REENTRANT"). I'll not use any flag on
"
LIBS_NOT_FOUND_2=". Please choose another thread implementation or
- provide information on your thread implementation.
- You can also run 'configure --disable-threads'
- to compile without thread support."
+ provide information on your thread implementation."
FUNC_NO_GETPWUID_R="the 'g_get_(user_name|real_name|home_dir|tmp_dir)'
functions will not be MT-safe during their first call because
dnl determination of thread implementation
dnl ***************************************
-# have_threads=no means no thread support
-# have_threads=none means no default thread implementation
-
have_threads=no
if test "x$want_threads" = xyes || test "x$want_threads" = xposix \
|| test "x$want_threads" = xdce; then
;;
esac
fi
-if test "x$want_threads" = xnone; then
- have_threads=none
-fi
AC_MSG_CHECKING(for thread implementation)
-if test "x$have_threads" = xno && test "x$want_threads" != xno; then
+if test "x$have_threads" = xno; then
AC_MSG_RESULT(none available)
- AC_MSG_WARN($THREAD_NO_IMPLEMENTATION)
+ AC_MSG_ERROR($THREAD_NO_IMPLEMENTATION)
else
AC_MSG_RESULT($have_threads)
fi
&& errno != 0;
}])
-if test x"$have_threads" != xno; then
-
- if test x"$have_threads" = xposix; then
- # First we test for posix, whether -pthread or -pthreads do the trick as
- # both CPPFLAG and LIBS.
- # One of them does for most gcc versions and some other platforms/compilers
- # too and could be considered as the canonical way to go.
- case $host in
- *-*-cygwin*|*-*-darwin*)
- # skip cygwin and darwin -pthread or -pthreads test
- ;;
- *-solaris*)
- # These compiler/linker flags work with both Sun Studio and gcc
- # Sun Studio expands -mt to -D_REENTRANT and -lthread
- # gcc expands -pthreads to -D_REENTRANT -D_PTHREADS -lpthread
- G_THREAD_CFLAGS="-D_REENTRANT -D_PTHREADS"
- G_THREAD_LIBS="-lpthread -lthread"
- ;;
- *)
- for flag in pthread pthreads mt; do
- glib_save_CFLAGS="$CFLAGS"
- CFLAGS="$CFLAGS -$flag"
- AC_TRY_RUN(glib_thread_test(0),
- glib_flag_works=yes,
- glib_flag_works=no,
- [AC_LINK_IFELSE([AC_LANG_SOURCE(glib_thread_test(0))],
- glib_flag_works=yes,
- glib_flag_works=no)])
- CFLAGS="$glib_save_CFLAGS"
- if test $glib_flag_works = yes ; then
- G_THREAD_CFLAGS=-$flag
- G_THREAD_LIBS=-$flag
- break;
- fi
- done
- ;;
- esac
- fi
+if test x"$have_threads" = xposix; then
+ # First we test for posix, whether -pthread or -pthreads do the trick as
+ # both CPPFLAG and LIBS.
+ # One of them does for most gcc versions and some other platforms/compilers
+ # too and could be considered as the canonical way to go.
+ case $host in
+ *-*-cygwin*|*-*-darwin*)
+ # skip cygwin and darwin -pthread or -pthreads test
+ ;;
+ *-solaris*)
+ # These compiler/linker flags work with both Sun Studio and gcc
+ # Sun Studio expands -mt to -D_REENTRANT and -lthread
+ # gcc expands -pthreads to -D_REENTRANT -D_PTHREADS -lpthread
+ G_THREAD_CFLAGS="-D_REENTRANT -D_PTHREADS"
+ G_THREAD_LIBS="-lpthread -lthread"
+ ;;
+ *)
+ for flag in pthread pthreads mt; do
+ glib_save_CFLAGS="$CFLAGS"
+ CFLAGS="$CFLAGS -$flag"
+ AC_TRY_RUN(glib_thread_test(0),
+ glib_flag_works=yes,
+ glib_flag_works=no,
+ [AC_LINK_IFELSE([AC_LANG_SOURCE(glib_thread_test(0))],
+ glib_flag_works=yes,
+ glib_flag_works=no)])
+ CFLAGS="$glib_save_CFLAGS"
+ if test $glib_flag_works = yes ; then
+ G_THREAD_CFLAGS=-$flag
+ G_THREAD_LIBS=-$flag
+ break;
+ fi
+ done
+ ;;
+ esac
+fi
- if test x"$G_THREAD_CFLAGS" = x; then
+if test x"$G_THREAD_CFLAGS" = x; then
- # The canonical -pthread[s] does not work. Try something different.
+ # The canonical -pthread[s] does not work. Try something different.
- case $host in
+ case $host in
*-aix*)
if test x"$GCC" = xyes; then
# GCC 3.0 and above needs -pthread.
*)
G_THREAD_CFLAGS="-D_REENTRANT" # good default guess otherwise
;;
- esac
-
- fi
+ esac
+
+fi
- # if we are not finding the localtime_r function, then we probably are
- # not using the proper multithread flag
+# if we are not finding the localtime_r function, then we probably are
+# not using the proper multithread flag
- glib_save_CPPFLAGS="$CPPFLAGS"
- CPPFLAGS="$CPPFLAGS $G_THREAD_CFLAGS"
+glib_save_CPPFLAGS="$CPPFLAGS"
+CPPFLAGS="$CPPFLAGS $G_THREAD_CFLAGS"
- # First we test, whether localtime_r is declared in time.h
- # directly. Then we test whether a macro localtime_r exists, in
- # which case localtime_r in the test program is replaced and thus
- # if we still find localtime_r in the output, it is not defined as
- # a macro.
+# First we test, whether localtime_r is declared in time.h
+# directly. Then we test whether a macro localtime_r exists, in
+# which case localtime_r in the test program is replaced and thus
+# if we still find localtime_r in the output, it is not defined as
+# a macro.
- AC_EGREP_CPP([[^a-zA-Z1-9_]localtime_r[^a-zA-Z1-9_]], [#include <time.h>], ,
- [AC_EGREP_CPP([[^a-zA-Z1-9_]localtime_r[^a-zA-Z1-9_]], [#include <time.h>
+AC_EGREP_CPP([[^a-zA-Z1-9_]localtime_r[^a-zA-Z1-9_]], [#include <time.h>], ,
+ [AC_EGREP_CPP([[^a-zA-Z1-9_]localtime_r[^a-zA-Z1-9_]], [#include <time.h>
localtime_r(a,b)],
- AC_MSG_WARN($FLAG_DOES_NOT_WORK))])
+ AC_MSG_WARN($FLAG_DOES_NOT_WORK))])
- CPPFLAGS="$glib_save_CPPFLAGS"
+CPPFLAGS="$glib_save_CPPFLAGS"
- AC_MSG_CHECKING(thread related cflags)
- AC_MSG_RESULT($G_THREAD_CFLAGS)
- CPPFLAGS="$CPPFLAGS $G_THREAD_CFLAGS"
-fi
+AC_MSG_CHECKING(thread related cflags)
+AC_MSG_RESULT($G_THREAD_CFLAGS)
+CPPFLAGS="$CPPFLAGS $G_THREAD_CFLAGS"
dnl determination of G_THREAD_LIBS
dnl ******************************
win32)
g_threads_impl="WIN32"
;;
- none|no)
- g_threads_impl="NONE"
- ;;
*)
g_threads_impl="NONE"
G_THREAD_LIBS=error
dnl check for mt safe function variants and some posix functions
dnl ************************************************************
-if test x"$have_threads" != xno; then
- glib_save_LIBS="$LIBS"
- # we are not doing the following for now, as this might require glib
- # to always be linked with the thread libs on some platforms.
- # LIBS="$LIBS $G_THREAD_LIBS"
- AC_CHECK_FUNCS(localtime_r gmtime_r)
- if test "$ac_cv_header_pwd_h" = "yes"; then
- AC_CACHE_CHECK([for posix getpwuid_r],
- ac_cv_func_posix_getpwuid_r,
- [AC_TRY_RUN([
+glib_save_LIBS="$LIBS"
+# we are not doing the following for now, as this might require glib
+# to always be linked with the thread libs on some platforms.
+# LIBS="$LIBS $G_THREAD_LIBS"
+AC_CHECK_FUNCS(localtime_r gmtime_r)
+if test "$ac_cv_header_pwd_h" = "yes"; then
+ AC_CACHE_CHECK([for posix getpwuid_r],
+ ac_cv_func_posix_getpwuid_r,
+ [AC_TRY_RUN([
#include <errno.h>
#include <pwd.h>
int main () {
return (error < 0 && errno == ENOSYS)
|| error == ENOSYS;
} ],
- [ac_cv_func_posix_getpwuid_r=yes],
- [ac_cv_func_posix_getpwuid_r=no])])
- GLIB_ASSERT_SET(ac_cv_func_posix_getpwuid_r)
- if test "$ac_cv_func_posix_getpwuid_r" = yes; then
- AC_DEFINE(HAVE_POSIX_GETPWUID_R,1,
- [Have POSIX function getpwuid_r])
- else
- AC_CACHE_CHECK([for nonposix getpwuid_r],
- ac_cv_func_nonposix_getpwuid_r,
- [AC_TRY_LINK([#include <pwd.h>],
- [char buffer[10000];
- struct passwd pwd;
- getpwuid_r (0, &pwd, buffer,
- sizeof (buffer));],
- [ac_cv_func_nonposix_getpwuid_r=yes],
- [ac_cv_func_nonposix_getpwuid_r=no])])
- GLIB_ASSERT_SET(ac_cv_func_nonposix_getpwuid_r)
- if test "$ac_cv_func_nonposix_getpwuid_r" = yes; then
- AC_DEFINE(HAVE_NONPOSIX_GETPWUID_R,1,
- [Have non-POSIX function getpwuid_r])
- fi
+ [ac_cv_func_posix_getpwuid_r=yes],
+ [ac_cv_func_posix_getpwuid_r=no])])
+ GLIB_ASSERT_SET(ac_cv_func_posix_getpwuid_r)
+ if test "$ac_cv_func_posix_getpwuid_r" = yes; then
+ AC_DEFINE(HAVE_POSIX_GETPWUID_R,1,
+ [Have POSIX function getpwuid_r])
+ else
+ AC_CACHE_CHECK([for nonposix getpwuid_r],
+ ac_cv_func_nonposix_getpwuid_r,
+ [AC_TRY_LINK([#include <pwd.h>],
+ [char buffer[10000];
+ struct passwd pwd;
+ getpwuid_r (0, &pwd, buffer,
+ sizeof (buffer));],
+ [ac_cv_func_nonposix_getpwuid_r=yes],
+ [ac_cv_func_nonposix_getpwuid_r=no])])
+ GLIB_ASSERT_SET(ac_cv_func_nonposix_getpwuid_r)
+ if test "$ac_cv_func_nonposix_getpwuid_r" = yes; then
+ AC_DEFINE(HAVE_NONPOSIX_GETPWUID_R,1,
+ [Have non-POSIX function getpwuid_r])
fi
fi
- if test "$ac_cv_header_grp_h" = "yes"; then
- AC_CACHE_CHECK([for posix getgrgid_r],
- ac_cv_func_posix_getgrgid_r,
- [AC_TRY_RUN([
+fi
+if test "$ac_cv_header_grp_h" = "yes"; then
+ AC_CACHE_CHECK([for posix getgrgid_r],
+ ac_cv_func_posix_getgrgid_r,
+ [AC_TRY_RUN([
#include <errno.h>
#include <grp.h>
int main () {
return (error < 0 && errno == ENOSYS)
|| error == ENOSYS;
} ],
- [ac_cv_func_posix_getgrgid_r=yes],
- [ac_cv_func_posix_getgrgid_r=no])])
- GLIB_ASSERT_SET(ac_cv_func_posix_getgrgid_r)
- if test "$ac_cv_func_posix_getgrgid_r" = yes; then
- AC_DEFINE(HAVE_POSIX_GETGRGID_R,1,
- [Have POSIX function getgrgid_r])
- else
- AC_CACHE_CHECK([for nonposix getgrgid_r],
- ac_cv_func_nonposix_getgrgid_r,
- [AC_TRY_LINK([#include <grp.h>],
- [char buffer[10000];
- struct group grp;
- getgrgid_r (0, &grp, buffer,
- sizeof (buffer));],
- [ac_cv_func_nonposix_getgrgid_r=yes],
- [ac_cv_func_nonposix_getgrgid_r=no])])
- GLIB_ASSERT_SET(ac_cv_func_nonposix_getgrgid_r)
- if test "$ac_cv_func_nonposix_getgrgid_r" = yes; then
- AC_DEFINE(HAVE_NONPOSIX_GETGRGID_R,1,
- [Have non-POSIX function getgrgid_r])
- fi
+ [ac_cv_func_posix_getgrgid_r=yes],
+ [ac_cv_func_posix_getgrgid_r=no])])
+ GLIB_ASSERT_SET(ac_cv_func_posix_getgrgid_r)
+ if test "$ac_cv_func_posix_getgrgid_r" = yes; then
+ AC_DEFINE(HAVE_POSIX_GETGRGID_R,1,
+ [Have POSIX function getgrgid_r])
+ else
+ AC_CACHE_CHECK([for nonposix getgrgid_r],
+ ac_cv_func_nonposix_getgrgid_r,
+ [AC_TRY_LINK([#include <grp.h>],
+ [char buffer[10000];
+ struct group grp;
+ getgrgid_r (0, &grp, buffer,
+ sizeof (buffer));],
+ [ac_cv_func_nonposix_getgrgid_r=yes],
+ [ac_cv_func_nonposix_getgrgid_r=no])])
+ GLIB_ASSERT_SET(ac_cv_func_nonposix_getgrgid_r)
+ if test "$ac_cv_func_nonposix_getgrgid_r" = yes; then
+ AC_DEFINE(HAVE_NONPOSIX_GETGRGID_R,1,
+ [Have non-POSIX function getgrgid_r])
fi
fi
- LIBS="$G_THREAD_LIBS $LIBS"
- if test x"$have_threads" = xposix; then
- glib_save_CPPFLAGS="$CPPFLAGS"
- CPPFLAGS="$CPPFLAGS $GTHREAD_COMPILE_IMPL_DEFINES"
- dnl we might grow sizeof(pthread_t) later on, so use a dummy name here
- GLIB_SIZEOF([#include <pthread.h>], pthread_t, system_thread)
- # This is not AC_CHECK_FUNC to also work with function
- # name mangling in header files.
- AC_MSG_CHECKING(for pthread_attr_setstacksize)
+fi
+LIBS="$G_THREAD_LIBS $LIBS"
+if test x"$have_threads" = xposix; then
+ glib_save_CPPFLAGS="$CPPFLAGS"
+ CPPFLAGS="$CPPFLAGS $GTHREAD_COMPILE_IMPL_DEFINES"
+ dnl we might grow sizeof(pthread_t) later on, so use a dummy name here
+ GLIB_SIZEOF([#include <pthread.h>], pthread_t, system_thread)
+ # This is not AC_CHECK_FUNC to also work with function
+ # name mangling in header files.
+ AC_MSG_CHECKING(for pthread_attr_setstacksize)
+ AC_TRY_LINK([#include <pthread.h>],
+ [pthread_attr_t t; pthread_attr_setstacksize(&t,0)],
+ [AC_MSG_RESULT(yes)
+ AC_DEFINE(HAVE_PTHREAD_ATTR_SETSTACKSIZE,1,
+ [Have function pthread_attr_setstacksize])],
+ [AC_MSG_RESULT(no)])
+ AC_MSG_CHECKING(for minimal/maximal thread priority)
+ if test x"$posix_priority_min" = x; then
+ AC_EGREP_CPP(PX_PRIO_MIN,[#include <pthread.h>
+ PX_PRIO_MIN],,[
+ posix_priority_min=PX_PRIO_MIN
+ posix_priority_max=PX_PRIO_MAX])
+ fi
+ if test x"$posix_priority_min" = x; then
+ # AIX
+ AC_EGREP_CPP(PTHREAD_PRIO_MIN,[#include <pthread.h>
+ PTHREAD_PRIO_MIN],,[
+ posix_priority_min=PTHREAD_PRIO_MIN
+ posix_priority_max=PTHREAD_PRIO_MAX])
+ fi
+ if test x"$posix_priority_min" = x; then
+ AC_EGREP_CPP(PRI_OTHER_MIN,[#include <pthread.h>
+ PRI_OTHER_MIN],,[
+ posix_priority_min=PRI_OTHER_MIN
+ posix_priority_max=PRI_OTHER_MAX])
+ fi
+ if test x"$posix_priority_min" = x; then
+ AC_MSG_RESULT(none found)
+ AC_MSG_WARN($POSIX_NO_PRIORITIES)
+ posix_priority_min=-1
+ posix_priority_max=-1
+ else
+ AC_MSG_RESULT($posix_priority_min/$posix_priority_max)
+ AC_MSG_CHECKING(for pthread_setschedparam)
AC_TRY_LINK([#include <pthread.h>],
- [pthread_attr_t t; pthread_attr_setstacksize(&t,0)],
- [AC_MSG_RESULT(yes)
- AC_DEFINE(HAVE_PTHREAD_ATTR_SETSTACKSIZE,1,
- [Have function pthread_attr_setstacksize])],
- [AC_MSG_RESULT(no)])
- AC_MSG_CHECKING(for minimal/maximal thread priority)
- if test x"$posix_priority_min" = x; then
- AC_EGREP_CPP(PX_PRIO_MIN,[#include <pthread.h>
- PX_PRIO_MIN],,[
- posix_priority_min=PX_PRIO_MIN
- posix_priority_max=PX_PRIO_MAX])
- fi
- if test x"$posix_priority_min" = x; then
- # AIX
- AC_EGREP_CPP(PTHREAD_PRIO_MIN,[#include <pthread.h>
- PTHREAD_PRIO_MIN],,[
- posix_priority_min=PTHREAD_PRIO_MIN
- posix_priority_max=PTHREAD_PRIO_MAX])
- fi
- if test x"$posix_priority_min" = x; then
- AC_EGREP_CPP(PRI_OTHER_MIN,[#include <pthread.h>
- PRI_OTHER_MIN],,[
- posix_priority_min=PRI_OTHER_MIN
- posix_priority_max=PRI_OTHER_MAX])
- fi
- if test x"$posix_priority_min" = x; then
- AC_MSG_RESULT(none found)
- AC_MSG_WARN($POSIX_NO_PRIORITIES)
- posix_priority_min=-1
- posix_priority_max=-1
- else
- AC_MSG_RESULT($posix_priority_min/$posix_priority_max)
- AC_MSG_CHECKING(for pthread_setschedparam)
- AC_TRY_LINK([#include <pthread.h>],
- [pthread_t t; pthread_setschedparam(t, 0, NULL)],
- [AC_MSG_RESULT(yes)
- AC_DEFINE_UNQUOTED(POSIX_MIN_PRIORITY,$posix_priority_min,[Minimum POSIX RT priority])
- AC_DEFINE_UNQUOTED(POSIX_MAX_PRIORITY,$posix_priority_max,[Maximum POSIX RT priority])],
- [AC_MSG_RESULT(no)
- AC_MSG_WARN($POSIX_NO_PRIORITIES)])
- fi
- posix_yield_func=none
- AC_MSG_CHECKING(for posix yield function)
- for yield_func in sched_yield pthread_yield_np pthread_yield \
- thr_yield; do
- AC_TRY_LINK([#include <pthread.h>],
- [$yield_func()],
- [posix_yield_func="$yield_func"
- break])
- done
- if test x"$posix_yield_func" = xnone; then
- AC_MSG_RESULT(none found)
- AC_MSG_WARN($POSIX_NO_YIELD)
- posix_yield_func="g_usleep(1000)"
- else
- AC_MSG_RESULT($posix_yield_func)
- posix_yield_func="$posix_yield_func()"
- fi
- AC_DEFINE_UNQUOTED(POSIX_YIELD_FUNC,$posix_yield_func,[The POSIX RT yield function])
- CPPFLAGS="$glib_save_CPPFLAGS"
-
- elif test x"$have_threads" = xwin32; then
- # It's a pointer to a private struct
- GLIB_SIZEOF(,struct _GThreadData *, system_thread)
+ [pthread_t t; pthread_setschedparam(t, 0, NULL)],
+ [AC_MSG_RESULT(yes)
+ AC_DEFINE_UNQUOTED(POSIX_MIN_PRIORITY,$posix_priority_min,[Minimum POSIX RT priority])
+ AC_DEFINE_UNQUOTED(POSIX_MAX_PRIORITY,$posix_priority_max,[Maximum POSIX RT priority])],
+ [AC_MSG_RESULT(no)
+ AC_MSG_WARN($POSIX_NO_PRIORITIES)])
fi
+ posix_yield_func=none
+ AC_MSG_CHECKING(for posix yield function)
+ for yield_func in sched_yield pthread_yield_np pthread_yield \
+ thr_yield; do
+ AC_TRY_LINK([#include <pthread.h>],
+ [$yield_func()],
+ [posix_yield_func="$yield_func"
+ break])
+ done
+ if test x"$posix_yield_func" = xnone; then
+ AC_MSG_RESULT(none found)
+ AC_MSG_WARN($POSIX_NO_YIELD)
+ posix_yield_func="g_usleep(1000)"
+ else
+ AC_MSG_RESULT($posix_yield_func)
+ posix_yield_func="$posix_yield_func()"
+ fi
+ AC_DEFINE_UNQUOTED(POSIX_YIELD_FUNC,$posix_yield_func,[The POSIX RT yield function])
+ CPPFLAGS="$glib_save_CPPFLAGS"
+
+elif test x"$have_threads" = xwin32; then
+ # It's a pointer to a private struct
+ GLIB_SIZEOF(,struct _GThreadData *, system_thread)
+fi
- LIBS="$glib_save_LIBS"
+LIBS="$glib_save_LIBS"
- # now spit out all the warnings.
- if test "$ac_cv_func_posix_getpwuid_r" != "yes" &&
- test "$ac_cv_func_nonposix_getpwuid_r" != "yes"; then
- AC_MSG_WARN($FUNC_NO_GETPWUID_R)
- fi
- if test "$ac_cv_func_localtime_r" != "yes"; then
- AC_MSG_WARN($FUNC_NO_LOCALTIME_R)
- fi
-fi
+# now spit out all the warnings.
+if test "$ac_cv_func_posix_getpwuid_r" != "yes" &&
+ test "$ac_cv_func_nonposix_getpwuid_r" != "yes"; then
+ AC_MSG_WARN($FUNC_NO_GETPWUID_R)
+fi
+if test "$ac_cv_func_localtime_r" != "yes"; then
+ AC_MSG_WARN($FUNC_NO_LOCALTIME_R)
+fi
if test x"$glib_cv_sizeof_system_thread" = x; then
# use a pointer as a fallback.
;;
esac
-AM_CONDITIONAL(HAVE_THREADS, [test "$have_threads" != "none"])
AC_DEFINE_UNQUOTED(G_THREAD_SOURCE,"gthread-$have_threads.c",
- [Source file containing theread implementation])
+ [Source file containing thread implementation])
AC_SUBST(G_THREAD_CFLAGS)
AC_SUBST(G_THREAD_LIBS)
AC_SUBST(G_THREAD_LIBS_FOR_GTHREAD)
echo >>$outfile
if test x$g_mutex_has_default = xyes; then
cat >>$outfile <<_______EOF
-$g_enable_threads_def G_THREADS_ENABLED
+#define G_THREADS_ENABLED
#define G_THREADS_IMPL_$g_threads_impl_def
typedef struct _GStaticMutex GStaticMutex;
struct _GStaticMutex
_______EOF
else
cat >>$outfile <<_______EOF
-$g_enable_threads_def G_THREADS_ENABLED
+#define G_THREADS_ENABLED
#define G_THREADS_IMPL_$g_threads_impl_def
typedef struct _GMutex* GStaticMutex;
#define G_STATIC_MUTEX_INIT NULL
g_have_eilseq=$have_eilseq
-case x$have_threads in
-xno) g_enable_threads_def="#undef";;
-*) g_enable_threads_def="#define";;
-esac
-
g_threads_impl_def=$g_threads_impl
g_mutex_has_default="$mutex_has_default"
G_SOURCE_CAN_RECURSE = 1 << (G_HOOK_FLAG_USER_SHIFT + 1)
} GSourceFlags;
-#ifdef G_THREADS_ENABLED
typedef struct _GMainWaiter GMainWaiter;
struct _GMainWaiter
GCond *cond;
GMutex *mutex;
};
-#endif
typedef struct _GMainDispatch GMainDispatch;
struct _GMainContext
{
-#ifdef G_THREADS_ENABLED
/* The following lock is used for both the list of sources
* and the list of poll records
*/
GThread *owner;
guint owner_count;
GSList *waiters;
-#endif
gint ref_count;
GPollFD *cached_poll_array;
guint cached_poll_array_size;
-#ifdef G_THREADS_ENABLED
GWakeup *wakeup;
GPollFD wake_up_rec;
/* Flag indicating whether the set of fd's changed during a poll */
gboolean poll_changed;
-#endif /* G_THREADS_ENABLED */
GPollFunc poll_func;
GSource *parent_source;
};
-#ifdef G_THREADS_ENABLED
#define LOCK_CONTEXT(context) g_static_mutex_lock (&context->mutex)
#define UNLOCK_CONTEXT(context) g_static_mutex_unlock (&context->mutex)
#define G_THREAD_SELF g_thread_self ()
-#else
-#define LOCK_CONTEXT(context) (void)0
-#define UNLOCK_CONTEXT(context) (void)0
-#define G_THREAD_SELF NULL
-#endif
#define SOURCE_DESTROYED(source) (((source)->flags & G_HOOK_FLAG_ACTIVE) == 0)
#define SOURCE_BLOCKED(source) (((source)->flags & G_HOOK_FLAG_IN_CALL) != 0 && \
source = next;
}
-#ifdef G_THREADS_ENABLED
g_static_mutex_free (&context->mutex);
-#endif
g_ptr_array_free (context->pending_dispatches, TRUE);
g_free (context->cached_poll_array);
poll_rec_list_free (context, context->poll_records);
-#ifdef G_THREADS_ENABLED
if (g_thread_supported())
g_wakeup_free (context->wakeup);
if (context->cond != NULL)
g_cond_free (context->cond);
-#endif
g_free (context);
}
-#ifdef G_THREADS_ENABLED
static void
g_main_context_init_pipe (GMainContext *context)
{
g_slist_free (main_contexts_without_pipe);
main_contexts_without_pipe = NULL;
}
-#endif /* G_THREADS_ENABLED */
/**
* g_main_context_new:
}
#endif
-#ifdef G_THREADS_ENABLED
g_static_mutex_init (&context->mutex);
context->owner = NULL;
context->waiters = NULL;
-#endif
context->ref_count = 1;
context->time_is_fresh = FALSE;
context->real_time_is_fresh = FALSE;
-#ifdef G_THREADS_ENABLED
if (g_thread_supported ())
g_main_context_init_pipe (context);
else
main_contexts_without_pipe = g_slist_prepend (main_contexts_without_pipe,
context);
-#endif
G_LOCK (main_context_list);
main_context_list = g_slist_append (main_context_list, context);
result = g_source_attach_unlocked (source, context);
-#ifdef G_THREADS_ENABLED
/* Now wake up the main loop if it is waiting in the poll() */
g_main_context_wakeup_unlocked (context);
-#endif
UNLOCK_CONTEXT (context);
gboolean
g_main_context_acquire (GMainContext *context)
{
-#ifdef G_THREADS_ENABLED
gboolean result = FALSE;
GThread *self = G_THREAD_SELF;
UNLOCK_CONTEXT (context);
return result;
-#else /* !G_THREADS_ENABLED */
- return TRUE;
-#endif /* G_THREADS_ENABLED */
}
/**
void
g_main_context_release (GMainContext *context)
{
-#ifdef G_THREADS_ENABLED
if (context == NULL)
context = g_main_context_default ();
}
UNLOCK_CONTEXT (context);
-#endif /* G_THREADS_ENABLED */
}
/**
GCond *cond,
GMutex *mutex)
{
-#ifdef G_THREADS_ENABLED
gboolean result = FALSE;
GThread *self = G_THREAD_SELF;
gboolean loop_internal_waiter;
UNLOCK_CONTEXT (context);
return result;
-#else /* !G_THREADS_ENABLED */
- return TRUE;
-#endif /* G_THREADS_ENABLED */
}
/**
return FALSE;
}
-#ifdef G_THREADS_ENABLED
if (context->poll_waiting)
{
g_warning("g_main_context_prepare(): main loop already active in another thread");
}
context->poll_waiting = TRUE;
-#endif /* G_THREADS_ENABLED */
#if 0
/* If recursing, finish up current dispatch, before starting over */
n_poll++;
}
-#ifdef G_THREADS_ENABLED
context->poll_changed = FALSE;
-#endif
if (timeout)
{
return FALSE;
}
-#ifdef G_THREADS_ENABLED
if (!context->poll_waiting)
g_wakeup_acknowledge (context->wakeup);
UNLOCK_CONTEXT (context);
return FALSE;
}
-#endif /* G_THREADS_ENABLED */
pollrec = context->poll_records;
i = 0;
UNLOCK_CONTEXT (context);
-#ifdef G_THREADS_ENABLED
if (!g_main_context_acquire (context))
{
gboolean got_ownership;
}
else
LOCK_CONTEXT (context);
-#endif /* G_THREADS_ENABLED */
if (!context->cached_poll_array)
{
if (dispatch)
g_main_context_dispatch (context);
-#ifdef G_THREADS_ENABLED
g_main_context_release (context);
-#endif /* G_THREADS_ENABLED */
LOCK_CONTEXT (context);
g_return_if_fail (loop != NULL);
g_return_if_fail (g_atomic_int_get (&loop->ref_count) > 0);
-#ifdef G_THREADS_ENABLED
if (!g_main_context_acquire (loop->context))
{
gboolean got_ownership = FALSE;
}
else
LOCK_CONTEXT (loop->context);
-#endif /* G_THREADS_ENABLED */
if (loop->context->in_check_or_prepare)
{
UNLOCK_CONTEXT (loop->context);
-#ifdef G_THREADS_ENABLED
g_main_context_release (loop->context);
-#endif /* G_THREADS_ENABLED */
g_main_loop_unref (loop);
}
loop->is_running = FALSE;
g_main_context_wakeup_unlocked (loop->context);
-#ifdef G_THREADS_ENABLED
if (loop->context->cond)
g_cond_broadcast (loop->context->cond);
-#endif /* G_THREADS_ENABLED */
UNLOCK_CONTEXT (loop->context);
}
context->n_poll_records++;
-#ifdef G_THREADS_ENABLED
context->poll_changed = TRUE;
/* Now wake up the main loop if it is waiting in the poll() */
g_main_context_wakeup_unlocked (context);
-#endif
}
/**
pollrec = nextrec;
}
-#ifdef G_THREADS_ENABLED
context->poll_changed = TRUE;
/* Now wake up the main loop if it is waiting in the poll() */
g_main_context_wakeup_unlocked (context);
-#endif
}
/**
static void
g_main_context_wakeup_unlocked (GMainContext *context)
{
-#ifdef G_THREADS_ENABLED
if (g_thread_supported() && context->poll_waiting)
{
context->poll_waiting = FALSE;
g_wakeup_signal (context->wakeup);
}
-#endif
}
/**
if (!context)
context = g_main_context_default ();
-#ifdef G_THREADS_ENABLED
LOCK_CONTEXT (context);
is_owner = context->owner == G_THREAD_SELF;
UNLOCK_CONTEXT (context);
-#else
- is_owner = TRUE;
-#endif
return is_owner;
}