diff --git a/configure.ac b/configure.ac index eaeeec5ec..3ca84d8f5 100644 --- a/configure.ac +++ b/configure.ac @@ -225,20 +225,11 @@ AC_ARG_ENABLE(mem_pools, [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]) @@ -1892,7 +1883,7 @@ dnl *** g_thread checks *** 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 @@ -1900,15 +1891,12 @@ AC_ARG_WITH(threads, 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 @@ -1919,9 +1907,7 @@ LIBS_NOT_FOUND_1="I can't find the libraries for the thread implementation " 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 @@ -1950,9 +1936,6 @@ AIX_COMPILE_INFO="AIX's C compiler needs to be called by a different name, when 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 @@ -1988,15 +1971,12 @@ if test "x$want_threads" = xyes || test "x$want_threads" = xwin32; 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 @@ -2036,50 +2016,48 @@ int main() { && 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. @@ -2119,34 +2097,33 @@ if test x"$have_threads" != xno; then *) G_THREAD_CFLAGS="-D_REENTRANT" # good default guess otherwise ;; - esac - - fi + esac - # 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" - - # 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 ], , - [AC_EGREP_CPP([[^a-zA-Z1-9_]localtime_r[^a-zA-Z1-9_]], [#include - localtime_r(a,b)], - AC_MSG_WARN($FLAG_DOES_NOT_WORK))]) - - CPPFLAGS="$glib_save_CPPFLAGS" - - AC_MSG_CHECKING(thread related cflags) - AC_MSG_RESULT($G_THREAD_CFLAGS) - CPPFLAGS="$CPPFLAGS $G_THREAD_CFLAGS" fi +# 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" + +# 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 ], , + [AC_EGREP_CPP([[^a-zA-Z1-9_]localtime_r[^a-zA-Z1-9_]], [#include + localtime_r(a,b)], + AC_MSG_WARN($FLAG_DOES_NOT_WORK))]) + +CPPFLAGS="$glib_save_CPPFLAGS" + +AC_MSG_CHECKING(thread related cflags) +AC_MSG_RESULT($G_THREAD_CFLAGS) +CPPFLAGS="$CPPFLAGS $G_THREAD_CFLAGS" + dnl determination of G_THREAD_LIBS dnl ****************************** @@ -2247,9 +2224,6 @@ case $have_threads in win32) g_threads_impl="WIN32" ;; - none|no) - g_threads_impl="NONE" - ;; *) g_threads_impl="NONE" G_THREAD_LIBS=error @@ -2275,16 +2249,15 @@ AC_MSG_RESULT($G_THREAD_LIBS) 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 #include int main () { @@ -2297,33 +2270,33 @@ 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 ], - [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 ], + [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 #include int main () { @@ -2336,116 +2309,115 @@ 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 ], - [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 ], + [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_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_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_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 + 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_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 + 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_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 - 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_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 - 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_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 ], - [$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 ], + [$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. @@ -2468,9 +2440,8 @@ case $host in ;; 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) @@ -3301,7 +3272,7 @@ _______EOF 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 @@ -3321,7 +3292,7 @@ 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 @@ -3715,11 +3686,6 @@ g_stack_grows=$glib_cv_stack_grows 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" diff --git a/gio/Makefile.am b/gio/Makefile.am index ed49e6215..42fac228d 100644 --- a/gio/Makefile.am +++ b/gio/Makefile.am @@ -33,15 +33,11 @@ TESTS = abicheck.sh endif endif -if HAVE_THREADS -THREAD_FLAGS=-DG_THREADS_MANDATORY -endif - AM_CPPFLAGS = \ -DG_LOG_DOMAIN=\"GLib-GIO\" \ $(gmodule_INCLUDES) \ $(GLIB_DEBUG_FLAGS) \ - $(THREAD_FLAGS) \ + -DG_THREADS_MANDATORY \ -DG_DISABLE_DEPRECATED \ -DGIO_COMPILATION \ -DGIO_MODULE_DIR=\"$(GIO_MODULE_DIR)\" diff --git a/glib/gmain.c b/glib/gmain.c index 6662a093c..9c65c5aa5 100644 --- a/glib/gmain.c +++ b/glib/gmain.c @@ -188,7 +188,6 @@ typedef enum G_SOURCE_CAN_RECURSE = 1 << (G_HOOK_FLAG_USER_SHIFT + 1) } GSourceFlags; -#ifdef G_THREADS_ENABLED typedef struct _GMainWaiter GMainWaiter; struct _GMainWaiter @@ -196,7 +195,6 @@ struct _GMainWaiter GCond *cond; GMutex *mutex; }; -#endif typedef struct _GMainDispatch GMainDispatch; @@ -212,7 +210,6 @@ gboolean _g_main_poll_debug = FALSE; struct _GMainContext { -#ifdef G_THREADS_ENABLED /* The following lock is used for both the list of sources * and the list of poll records */ @@ -221,7 +218,6 @@ struct _GMainContext GThread *owner; guint owner_count; GSList *waiters; -#endif gint ref_count; @@ -237,7 +233,6 @@ struct _GMainContext GPollFD *cached_poll_array; guint cached_poll_array_size; -#ifdef G_THREADS_ENABLED GWakeup *wakeup; GPollFD wake_up_rec; @@ -245,7 +240,6 @@ struct _GMainContext /* Flag indicating whether the set of fd's changed during a poll */ gboolean poll_changed; -#endif /* G_THREADS_ENABLED */ GPollFunc poll_func; @@ -312,15 +306,9 @@ struct _GSourcePrivate 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 && \ @@ -515,16 +503,13 @@ g_main_context_unref (GMainContext *context) 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); @@ -534,12 +519,10 @@ g_main_context_unref (GMainContext *context) 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) { @@ -562,7 +545,6 @@ _g_main_thread_init (void) g_slist_free (main_contexts_without_pipe); main_contexts_without_pipe = NULL; } -#endif /* G_THREADS_ENABLED */ /** * g_main_context_new: @@ -589,12 +571,10 @@ g_main_context_new (void) } #endif -#ifdef G_THREADS_ENABLED g_static_mutex_init (&context->mutex); context->owner = NULL; context->waiters = NULL; -#endif context->ref_count = 1; @@ -612,13 +592,11 @@ g_main_context_new (void) 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); @@ -955,10 +933,8 @@ g_source_attach (GSource *source, 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); @@ -2518,7 +2494,6 @@ next_valid_source (GMainContext *context, gboolean g_main_context_acquire (GMainContext *context) { -#ifdef G_THREADS_ENABLED gboolean result = FALSE; GThread *self = G_THREAD_SELF; @@ -2542,9 +2517,6 @@ g_main_context_acquire (GMainContext *context) UNLOCK_CONTEXT (context); return result; -#else /* !G_THREADS_ENABLED */ - return TRUE; -#endif /* G_THREADS_ENABLED */ } /** @@ -2559,7 +2531,6 @@ g_main_context_acquire (GMainContext *context) void g_main_context_release (GMainContext *context) { -#ifdef G_THREADS_ENABLED if (context == NULL) context = g_main_context_default (); @@ -2588,7 +2559,6 @@ g_main_context_release (GMainContext *context) } UNLOCK_CONTEXT (context); -#endif /* G_THREADS_ENABLED */ } /** @@ -2611,7 +2581,6 @@ g_main_context_wait (GMainContext *context, GCond *cond, GMutex *mutex) { -#ifdef G_THREADS_ENABLED gboolean result = FALSE; GThread *self = G_THREAD_SELF; gboolean loop_internal_waiter; @@ -2658,9 +2627,6 @@ g_main_context_wait (GMainContext *context, UNLOCK_CONTEXT (context); return result; -#else /* !G_THREADS_ENABLED */ - return TRUE; -#endif /* G_THREADS_ENABLED */ } /** @@ -2700,7 +2666,6 @@ g_main_context_prepare (GMainContext *context, return FALSE; } -#ifdef G_THREADS_ENABLED if (context->poll_waiting) { g_warning("g_main_context_prepare(): main loop already active in another thread"); @@ -2709,7 +2674,6 @@ g_main_context_prepare (GMainContext *context, } context->poll_waiting = TRUE; -#endif /* G_THREADS_ENABLED */ #if 0 /* If recursing, finish up current dispatch, before starting over */ @@ -2855,9 +2819,7 @@ g_main_context_query (GMainContext *context, n_poll++; } -#ifdef G_THREADS_ENABLED context->poll_changed = FALSE; -#endif if (timeout) { @@ -2907,7 +2869,6 @@ g_main_context_check (GMainContext *context, return FALSE; } -#ifdef G_THREADS_ENABLED if (!context->poll_waiting) g_wakeup_acknowledge (context->wakeup); @@ -2922,7 +2883,6 @@ g_main_context_check (GMainContext *context, UNLOCK_CONTEXT (context); return FALSE; } -#endif /* G_THREADS_ENABLED */ pollrec = context->poll_records; i = 0; @@ -3029,7 +2989,6 @@ g_main_context_iterate (GMainContext *context, UNLOCK_CONTEXT (context); -#ifdef G_THREADS_ENABLED if (!g_main_context_acquire (context)) { gboolean got_ownership; @@ -3053,7 +3012,6 @@ g_main_context_iterate (GMainContext *context, } else LOCK_CONTEXT (context); -#endif /* G_THREADS_ENABLED */ if (!context->cached_poll_array) { @@ -3088,9 +3046,7 @@ g_main_context_iterate (GMainContext *context, if (dispatch) g_main_context_dispatch (context); -#ifdef G_THREADS_ENABLED g_main_context_release (context); -#endif /* G_THREADS_ENABLED */ LOCK_CONTEXT (context); @@ -3241,7 +3197,6 @@ g_main_loop_run (GMainLoop *loop) 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; @@ -3282,7 +3237,6 @@ g_main_loop_run (GMainLoop *loop) } else LOCK_CONTEXT (loop->context); -#endif /* G_THREADS_ENABLED */ if (loop->context->in_check_or_prepare) { @@ -3298,9 +3252,7 @@ g_main_loop_run (GMainLoop *loop) UNLOCK_CONTEXT (loop->context); -#ifdef G_THREADS_ENABLED g_main_context_release (loop->context); -#endif /* G_THREADS_ENABLED */ g_main_loop_unref (loop); } @@ -3325,10 +3277,8 @@ g_main_loop_quit (GMainLoop *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); } @@ -3523,12 +3473,10 @@ g_main_context_add_poll_unlocked (GMainContext *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 } /** @@ -3587,12 +3535,10 @@ g_main_context_remove_poll_unlocked (GMainContext *context, 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 } /** @@ -3754,13 +3700,11 @@ _g_main_wake_up_all_contexts (void) 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 } /** @@ -3804,13 +3748,9 @@ g_main_context_is_owner (GMainContext *context) 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; } diff --git a/glib/gthread.c b/glib/gthread.c index 694697561..ff56f2f94 100644 --- a/glib/gthread.c +++ b/glib/gthread.c @@ -136,12 +136,9 @@ /** * G_THREADS_ENABLED: * - * This macro is defined if GLib was compiled with thread support. This - * does not necessarily mean that there is a thread implementation - * available, but it does mean that the infrastructure is in place and - * that once you provide a thread implementation to g_thread_init(), - * GLib will be multi-thread safe. If #G_THREADS_ENABLED is not - * defined, then Glib is not, and cannot be, multi-thread safe. + * This macro is defined, for backward compatibility, to indicate that + * GLib has been compiled with thread support. As of glib 2.28, it is + * always defined. **/ /** @@ -886,7 +883,6 @@ G_LOCK_DEFINE_STATIC (g_thread); /* Initialisation {{{1 ---------------------------------------------------- */ -#ifdef G_THREADS_ENABLED /** * g_thread_init: * @vtable: a function table of type #GThreadFunctions, that provides @@ -962,7 +958,6 @@ g_thread_init_glib (void) _g_win32_thread_init (); #endif } -#endif /* G_THREADS_ENABLED */ /* The following sections implement: GOnce, GStaticMutex, GStaticRecMutex, * GStaticPrivate, diff --git a/glib/gthread.h b/glib/gthread.h index 9f5b34b54..1239c2d09 100644 --- a/glib/gthread.h +++ b/glib/gthread.h @@ -197,7 +197,7 @@ GMutex* g_static_mutex_get_mutex_impl (GMutex **mutex); (cond, mutex, abs_time, G_MUTEX_DEBUG_MAGIC, G_STRLOC) : TRUE) #endif /* G_ERRORCHECK_MUTEXES */ -#if defined(G_THREADS_ENABLED) && defined(G_THREADS_MANDATORY) +#if defined(G_THREADS_MANDATORY) #define g_thread_supported() 1 #else #define g_thread_supported() (g_threads_got_initialized) @@ -362,45 +362,36 @@ g_once_init_enter (volatile gsize *value_location) */ extern void glib_dummy_decl (void); #define G_LOCK_NAME(name) g__ ## name ## _lock -#ifdef G_THREADS_ENABLED -# define G_LOCK_DEFINE_STATIC(name) static G_LOCK_DEFINE (name) -# define G_LOCK_DEFINE(name) \ - GStaticMutex G_LOCK_NAME (name) = G_STATIC_MUTEX_INIT -# define G_LOCK_EXTERN(name) extern GStaticMutex G_LOCK_NAME (name) +#define G_LOCK_DEFINE_STATIC(name) static G_LOCK_DEFINE (name) +#define G_LOCK_DEFINE(name) \ + GStaticMutex G_LOCK_NAME (name) = G_STATIC_MUTEX_INIT +#define G_LOCK_EXTERN(name) extern GStaticMutex G_LOCK_NAME (name) -# ifdef G_DEBUG_LOCKS -# define G_LOCK(name) G_STMT_START{ \ - g_log (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, \ - "file %s: line %d (%s): locking: %s ", \ - __FILE__, __LINE__, G_STRFUNC, \ - #name); \ - g_static_mutex_lock (&G_LOCK_NAME (name)); \ - }G_STMT_END -# define G_UNLOCK(name) G_STMT_START{ \ - g_log (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, \ - "file %s: line %d (%s): unlocking: %s ", \ - __FILE__, __LINE__, G_STRFUNC, \ - #name); \ - g_static_mutex_unlock (&G_LOCK_NAME (name)); \ - }G_STMT_END -# define G_TRYLOCK(name) \ - (g_log (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, \ - "file %s: line %d (%s): try locking: %s ", \ - __FILE__, __LINE__, G_STRFUNC, \ - #name), g_static_mutex_trylock (&G_LOCK_NAME (name))) -# else /* !G_DEBUG_LOCKS */ -# define G_LOCK(name) g_static_mutex_lock (&G_LOCK_NAME (name)) -# define G_UNLOCK(name) g_static_mutex_unlock (&G_LOCK_NAME (name)) -# define G_TRYLOCK(name) g_static_mutex_trylock (&G_LOCK_NAME (name)) -# endif /* !G_DEBUG_LOCKS */ -#else /* !G_THREADS_ENABLED */ -# define G_LOCK_DEFINE_STATIC(name) extern void glib_dummy_decl (void) -# define G_LOCK_DEFINE(name) extern void glib_dummy_decl (void) -# define G_LOCK_EXTERN(name) extern void glib_dummy_decl (void) -# define G_LOCK(name) -# define G_UNLOCK(name) -# define G_TRYLOCK(name) (TRUE) -#endif /* !G_THREADS_ENABLED */ +#ifdef G_DEBUG_LOCKS +# define G_LOCK(name) G_STMT_START{ \ + g_log (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, \ + "file %s: line %d (%s): locking: %s ", \ + __FILE__, __LINE__, G_STRFUNC, \ + #name); \ + g_static_mutex_lock (&G_LOCK_NAME (name)); \ + }G_STMT_END +# define G_UNLOCK(name) G_STMT_START{ \ + g_log (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, \ + "file %s: line %d (%s): unlocking: %s ", \ + __FILE__, __LINE__, G_STRFUNC, \ + #name); \ + g_static_mutex_unlock (&G_LOCK_NAME (name)); \ + }G_STMT_END +# define G_TRYLOCK(name) \ + (g_log (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, \ + "file %s: line %d (%s): try locking: %s ", \ + __FILE__, __LINE__, G_STRFUNC, \ + #name), g_static_mutex_trylock (&G_LOCK_NAME (name))) +#else /* !G_DEBUG_LOCKS */ +# define G_LOCK(name) g_static_mutex_lock (&G_LOCK_NAME (name)) +# define G_UNLOCK(name) g_static_mutex_unlock (&G_LOCK_NAME (name)) +# define G_TRYLOCK(name) g_static_mutex_trylock (&G_LOCK_NAME (name)) +#endif /* !G_DEBUG_LOCKS */ G_END_DECLS diff --git a/gobject/Makefile.am b/gobject/Makefile.am index 10b0e2f34..7e02c83ab 100644 --- a/gobject/Makefile.am +++ b/gobject/Makefile.am @@ -9,15 +9,11 @@ SUBDIRS = . tests BUILT_SOURCES= CLEANFILES= -if HAVE_THREADS -THREAD_FLAGS=-DG_THREADS_MANDATORY -endif - AM_CPPFLAGS = \ -DG_LOG_DOMAIN=\"GLib-GObject\" \ $(gthread_INCLUDES) \ $(GLIB_DEBUG_FLAGS) \ - $(THREAD_FLAGS) \ + -DG_THREADS_MANDATORY \ -DG_DISABLE_DEPRECATED \ -DGOBJECT_COMPILATION diff --git a/gobject/gtype.c b/gobject/gtype.c index 44fc39dae..0cbb06fb2 100644 --- a/gobject/gtype.c +++ b/gobject/gtype.c @@ -4261,10 +4261,8 @@ g_type_init_with_debug_flags (GTypeDebugFlags debug_flags) TypeNode *node; volatile GType votype; -#ifdef G_THREADS_ENABLED if (!g_thread_get_initialized()) g_thread_init (NULL); -#endif G_LOCK (type_init_lock); diff --git a/gthread/gthread-impl.c b/gthread/gthread-impl.c index b4836577c..678b3b8fe 100644 --- a/gthread/gthread-impl.c +++ b/gthread/gthread-impl.c @@ -36,8 +36,6 @@ #include "glib.h" #include "gthreadprivate.h" -#ifdef G_THREADS_ENABLED - static GSystemThread zero_thread; /* This is initialized to all zero */ static gboolean thread_system_already_initialized = FALSE; static gint g_thread_priority_map [G_THREAD_PRIORITY_URGENT + 1]; @@ -359,19 +357,3 @@ g_thread_init (GThreadFunctions* init) g_thread_init_glib (); } - -#else /* !G_THREADS_ENABLED */ - -void -g_thread_init (GThreadFunctions* init) -{ - g_error ("GLib thread support is disabled."); -} - -void -g_thread_init_with_errorcheck_mutexes (GThreadFunctions* init) -{ - g_error ("GLib thread support is disabled."); -} - -#endif /* !G_THREADS_ENABLED */ diff --git a/tests/asyncqueue-test.c b/tests/asyncqueue-test.c index 588baa3d1..bdc53033f 100644 --- a/tests/asyncqueue-test.c +++ b/tests/asyncqueue-test.c @@ -178,7 +178,6 @@ basic_tests (void) int main (int argc, char *argv[]) { -#if defined(G_THREADS_ENABLED) && ! defined(G_THREADS_IMPL_NONE) gint i; gint max_threads = MAX_THREADS; gint max_unused_threads = MAX_THREADS; @@ -239,7 +238,6 @@ main (int argc, char *argv[]) main_loop = g_main_loop_new (NULL, FALSE); g_main_loop_run (main_loop); -#endif return EXIT_SUCCESS; } diff --git a/tests/child-test.c b/tests/child-test.c index a6e307dfa..2fbc741d8 100644 --- a/tests/child-test.c +++ b/tests/child-test.c @@ -163,10 +163,7 @@ main (int argc, char *argv[]) exit (STILL_ACTIVE); } #endif - /* Only run the test, if threads are enabled and a default thread - * implementation is available. - */ -#if defined(G_THREADS_ENABLED) && ! defined(G_THREADS_IMPL_NONE) + #ifdef TEST_THREAD g_thread_init (NULL); #endif @@ -201,6 +198,5 @@ main (int argc, char *argv[]) return 1; } -#endif return 0; } diff --git a/tests/mainloop-test.c b/tests/mainloop-test.c index cf38e090b..206f80e17 100644 --- a/tests/mainloop-test.c +++ b/tests/mainloop-test.c @@ -402,9 +402,6 @@ int main (int argc, char *argv[]) { - /* Only run the test, if threads are enabled and a default thread - implementation is available */ -#if defined(G_THREADS_ENABLED) && ! defined(G_THREADS_IMPL_NONE) gint i; g_thread_init (NULL); @@ -437,6 +434,5 @@ main (int argc, g_main_loop_run (main_loop); g_main_loop_unref (main_loop); -#endif return 0; } diff --git a/tests/thread-test.c b/tests/thread-test.c index 63f7e02be..709c38718 100644 --- a/tests/thread-test.c +++ b/tests/thread-test.c @@ -384,9 +384,6 @@ int main (int argc, char *argv[]) { - /* Only run the test, if threads are enabled and a default thread - implementation is available */ -#if defined(G_THREADS_ENABLED) && ! defined(G_THREADS_IMPL_NONE) g_thread_init (NULL); run_all_tests (); @@ -397,6 +394,5 @@ main (int argc, g_thread_use_default_impl = FALSE; run_all_tests (); -#endif return 0; } diff --git a/tests/threadpool-test.c b/tests/threadpool-test.c index cc22103ef..bb96c9e3a 100644 --- a/tests/threadpool-test.c +++ b/tests/threadpool-test.c @@ -466,10 +466,6 @@ test_check_start_and_stop (gpointer user_data) int main (int argc, char *argv[]) { - /* Only run the test, if threads are enabled and a default thread - implementation is available */ - -#if defined(G_THREADS_ENABLED) && ! defined(G_THREADS_IMPL_NONE) g_thread_init (NULL); DEBUG_MSG (("Starting... (in one second)")); @@ -477,7 +473,6 @@ main (int argc, char *argv[]) main_loop = g_main_loop_new (NULL, FALSE); g_main_loop_run (main_loop); -#endif return 0; }