empty G_ATOMIC_MEMORY_BARRIER() definition for !G_THREADS_ENABLED

2004-02-26  Sebastian Wilhelmi  <seppi@seppi.de>

	* glib/gatomic.h: empty G_ATOMIC_MEMORY_BARRIER() definition for
	!G_THREADS_ENABLED

	* glib/gthread.h: Define g_once and
	g_static_mutex_get_mutex_impl_shortcut in terms of
	G_MEMORY_BARRIER, if defined and if we can inline.

	* configure.in: Remove double checked locking feature check.
This commit is contained in:
Sebastian Wilhelmi 2004-02-26 16:53:55 +00:00 committed by Sebastian Wilhelmi
parent 76c213543a
commit ea9d13892e
9 changed files with 84 additions and 43 deletions

View File

@ -1,5 +1,14 @@
2004-02-26 Sebastian Wilhelmi <seppi@seppi.de> 2004-02-26 Sebastian Wilhelmi <seppi@seppi.de>
* glib/gatomic.h: empty G_ATOMIC_MEMORY_BARRIER() definition for
!G_THREADS_ENABLED
* glib/gthread.h: Define g_once and
g_static_mutex_get_mutex_impl_shortcut in terms of
G_MEMORY_BARRIER, if defined and if we can inline.
* configure.in: Remove double checked locking feature check.
* configure.in, config.h.win32.in, glib/gthread.c: Removed the PID * configure.in, config.h.win32.in, glib/gthread.c: Removed the PID
niceness surrogate for thread priorities as requested by Tim. It niceness surrogate for thread priorities as requested by Tim. It
does more harm than good. does more harm than good.

View File

@ -1,5 +1,14 @@
2004-02-26 Sebastian Wilhelmi <seppi@seppi.de> 2004-02-26 Sebastian Wilhelmi <seppi@seppi.de>
* glib/gatomic.h: empty G_ATOMIC_MEMORY_BARRIER() definition for
!G_THREADS_ENABLED
* glib/gthread.h: Define g_once and
g_static_mutex_get_mutex_impl_shortcut in terms of
G_MEMORY_BARRIER, if defined and if we can inline.
* configure.in: Remove double checked locking feature check.
* configure.in, config.h.win32.in, glib/gthread.c: Removed the PID * configure.in, config.h.win32.in, glib/gthread.c: Removed the PID
niceness surrogate for thread priorities as requested by Tim. It niceness surrogate for thread priorities as requested by Tim. It
does more harm than good. does more harm than good.

View File

@ -1,5 +1,14 @@
2004-02-26 Sebastian Wilhelmi <seppi@seppi.de> 2004-02-26 Sebastian Wilhelmi <seppi@seppi.de>
* glib/gatomic.h: empty G_ATOMIC_MEMORY_BARRIER() definition for
!G_THREADS_ENABLED
* glib/gthread.h: Define g_once and
g_static_mutex_get_mutex_impl_shortcut in terms of
G_MEMORY_BARRIER, if defined and if we can inline.
* configure.in: Remove double checked locking feature check.
* configure.in, config.h.win32.in, glib/gthread.c: Removed the PID * configure.in, config.h.win32.in, glib/gthread.c: Removed the PID
niceness surrogate for thread priorities as requested by Tim. It niceness surrogate for thread priorities as requested by Tim. It
does more harm than good. does more harm than good.

View File

@ -1,5 +1,14 @@
2004-02-26 Sebastian Wilhelmi <seppi@seppi.de> 2004-02-26 Sebastian Wilhelmi <seppi@seppi.de>
* glib/gatomic.h: empty G_ATOMIC_MEMORY_BARRIER() definition for
!G_THREADS_ENABLED
* glib/gthread.h: Define g_once and
g_static_mutex_get_mutex_impl_shortcut in terms of
G_MEMORY_BARRIER, if defined and if we can inline.
* configure.in: Remove double checked locking feature check.
* configure.in, config.h.win32.in, glib/gthread.c: Removed the PID * configure.in, config.h.win32.in, glib/gthread.c: Removed the PID
niceness surrogate for thread priorities as requested by Tim. It niceness surrogate for thread priorities as requested by Tim. It
does more harm than good. does more harm than good.

View File

@ -1,5 +1,14 @@
2004-02-26 Sebastian Wilhelmi <seppi@seppi.de> 2004-02-26 Sebastian Wilhelmi <seppi@seppi.de>
* glib/gatomic.h: empty G_ATOMIC_MEMORY_BARRIER() definition for
!G_THREADS_ENABLED
* glib/gthread.h: Define g_once and
g_static_mutex_get_mutex_impl_shortcut in terms of
G_MEMORY_BARRIER, if defined and if we can inline.
* configure.in: Remove double checked locking feature check.
* configure.in, config.h.win32.in, glib/gthread.c: Removed the PID * configure.in, config.h.win32.in, glib/gthread.c: Removed the PID
niceness surrogate for thread priorities as requested by Tim. It niceness surrogate for thread priorities as requested by Tim. It
does more harm than good. does more harm than good.

View File

@ -1,5 +1,14 @@
2004-02-26 Sebastian Wilhelmi <seppi@seppi.de> 2004-02-26 Sebastian Wilhelmi <seppi@seppi.de>
* glib/gatomic.h: empty G_ATOMIC_MEMORY_BARRIER() definition for
!G_THREADS_ENABLED
* glib/gthread.h: Define g_once and
g_static_mutex_get_mutex_impl_shortcut in terms of
G_MEMORY_BARRIER, if defined and if we can inline.
* configure.in: Remove double checked locking feature check.
* configure.in, config.h.win32.in, glib/gthread.c: Removed the PID * configure.in, config.h.win32.in, glib/gthread.c: Removed the PID
niceness surrogate for thread priorities as requested by Tim. It niceness surrogate for thread priorities as requested by Tim. It
does more harm than good. does more harm than good.

View File

@ -1188,27 +1188,6 @@ esac
AC_MSG_RESULT($GIO) AC_MSG_RESULT($GIO)
AC_SUBST(GIO) AC_SUBST(GIO)
dnl check for cpu to enable double checked locking when possible
dnl ************************************************************
if test x"$have_threads" != xno; then
AC_MSG_CHECKING(whether double checked locking is safe)
# According to glibc/linuxthreads the following platforms do
# not have the notion of a read or write memory barrier and
# therefore the double checked locking should be safe. Have a
# look at pthread_once in glibc/linuxthreads/mutex.c to see,
# what this means.
case $host_cpu in
arm|hppa|i386|i686|ia64|m68k|sh|cris|x86_64)
g_use_double_checked_locking=yes
;;
*)
g_use_double_checked_locking=no
;;
esac
AC_MSG_RESULT($g_use_double_checked_locking)
fi
dnl **************************************** dnl ****************************************
dnl *** platform dependent source checks *** dnl *** platform dependent source checks ***
dnl **************************************** dnl ****************************************
@ -2233,24 +2212,6 @@ typedef struct _GMutex* GStaticMutex;
_______EOF _______EOF
fi fi
if test x$g_use_double_checked_locking = xyes; then
cat >>$outfile <<_______EOF
/* double checked locking can be used on this platform */
#define g_once(once, func, arg) \\
((once)->status == G_ONCE_STATUS_READY ? (once)->retval : \\
g_once_impl (once, func, arg))
#define g_static_mutex_get_mutex_impl_shortcut(mutex) \\
(*(mutex) ? *(mutex) : g_static_mutex_get_mutex_impl (mutex))
_______EOF
else
cat >>$outfile <<_______EOF
/* double checked locking is unsafe to use on this platform, do full locking */
#define g_once(once, func, arg) (g_once_impl(once, func, arg))
#define g_static_mutex_get_mutex_impl_shortcut(mutex) \\
(g_static_mutex_get_mutex_impl (mutex))
_______EOF
fi
cat >>$outfile <<_______EOF cat >>$outfile <<_______EOF
/* This represents a system thread as used by the implementation. An /* This represents a system thread as used by the implementation. An
* alien implementaion, as loaded by g_thread_init can only count on * alien implementaion, as loaded by g_thread_init can only count on
@ -2565,7 +2526,6 @@ xno) g_enable_threads_def="#undef";;
esac esac
g_threads_impl_def=$g_threads_impl g_threads_impl_def=$g_threads_impl
g_use_double_checked_locking=$g_use_double_checked_locking
g_mutex_has_default="$mutex_has_default" g_mutex_has_default="$mutex_has_default"
g_mutex_sizeof="$glib_cv_sizeof_gmutex" g_mutex_sizeof="$glib_cv_sizeof_gmutex"

View File

@ -341,7 +341,7 @@ g_atomic_pointer_compare_and_exchange (gpointer *atomic,
return result == oldval; return result == oldval;
} }
# define G_ATOMIC_MEMORY_BARRIER() /* Not needed */ # define G_ATOMIC_MEMORY_BARRIER() /* Not needed */
# elif defined(G_ATOMIC_INLINED_IMPLEMENTATION_POWERPC) # elif defined(G_ATOMIC_INLINED_IMPLEMENTATION_POWERPC)
/* Adapted from CVS version 1.12 of glibc's sysdeps/powerpc/bits/atomic.h /* Adapted from CVS version 1.12 of glibc's sysdeps/powerpc/bits/atomic.h
@ -450,7 +450,7 @@ g_atomic_pointer_compare_and_exchange (gpointer *atomic,
# error "Your system has an unsupported pointer size" # error "Your system has an unsupported pointer size"
# endif /* GLIB_SIZEOF_VOID_P */ # endif /* GLIB_SIZEOF_VOID_P */
# define G_ATOMIC_MEMORY_BARRIER() __asm ("sync" : : : "memory") # define G_ATOMIC_MEMORY_BARRIER() __asm ("sync" : : : "memory")
# elif defined(G_ATOMIC_INLINED_IMPLEMENTATION_IA64) # elif defined(G_ATOMIC_INLINED_IMPLEMENTATION_IA64)
/* Adapted from CVS version 1.8 of glibc's sysdeps/ia64/bits/atomic.h /* Adapted from CVS version 1.8 of glibc's sysdeps/ia64/bits/atomic.h
@ -486,7 +486,7 @@ g_atomic_pointer_compare_and_exchange (gpointer *atomic,
(long)oldval, (long)newval); (long)oldval, (long)newval);
} }
# define G_ATOMIC_MEMORY_BARRIER() __sync_synchronize () # define G_ATOMIC_MEMORY_BARRIER() __sync_synchronize ()
# else /* !G_ATOMIC_INLINED_IMPLEMENTATION_... */ # else /* !G_ATOMIC_INLINED_IMPLEMENTATION_... */
# define G_ATOMIC_USE_FALLBACK_IMPLEMENTATION # define G_ATOMIC_USE_FALLBACK_IMPLEMENTATION
@ -503,6 +503,7 @@ gint32 g_atomic_int_exchange_and_add (gint32 *atomic, gint32 val);
(*(atomic) == (oldval) ? (*(atomic) = (newval), TRUE) : FALSE) (*(atomic) == (oldval) ? (*(atomic) = (newval), TRUE) : FALSE)
# define g_atomic_int_get(atomic) (*(atomic)) # define g_atomic_int_get(atomic) (*(atomic))
# define g_atomic_pointer_get(atomic) (*(atomic)) # define g_atomic_pointer_get(atomic) (*(atomic))
# define G_ATOMIC_MEMORY_BARRIER() /* Not needed */
#endif /* G_THREADS_ENABLED */ #endif /* G_THREADS_ENABLED */
#ifdef G_ATOMIC_USE_FALLBACK_IMPLEMENTATION #ifdef G_ATOMIC_USE_FALLBACK_IMPLEMENTATION

View File

@ -29,6 +29,8 @@
#include <glib/gerror.h> #include <glib/gerror.h>
#include <glib/gtypes.h> #include <glib/gtypes.h>
#include <glib/gutils.h> /* for G_CAN_INLINE */
#include <glib/gatomic.h> /* for G_ATOMIC_MEMORY_BARRIER */
G_BEGIN_DECLS G_BEGIN_DECLS
@ -302,6 +304,30 @@ struct _GOnce
gpointer g_once_impl (GOnce *once, GThreadFunc func, gpointer arg); gpointer g_once_impl (GOnce *once, GThreadFunc func, gpointer arg);
#if defined (G_CAN_INLINE) && defined (G_ATOMIC_MEMORY_BARRIER)
static inline gpointer
g_once (GOnce *once, GThreadFunc func, gpointer arg)
{
if (once->status != G_ONCE_STATUS_READY)
return g_once_impl (once, func, arg);
G_ATOMIC_MEMORY_BARRIER ();
return once->retval;
}
static inline GMutex*
g_static_mutex_get_mutex_impl_shortcut (GMutex **mutex)
{
if (! *mutex)
return g_static_mutex_get_mutex_impl (mutex);
G_ATOMIC_MEMORY_BARRIER ();
return *mutex;
}
#else /* !G_CAN_INLINE || !G_ATOMIC_MEMORY_BARRIER */
# define g_once g_once_impl
# define g_static_mutex_get_mutex_impl_shortcut g_static_mutex_get_mutex_impl
#endif /* G_CAN_INLINE && G_ATOMIC_MEMORY_BARRIER*/
/* these are some convenience macros that expand to nothing if GLib /* these are some convenience macros that expand to nothing if GLib
* was configured with --disable-threads. for using StaticMutexes, * was configured with --disable-threads. for using StaticMutexes,
* you define them with G_LOCK_DEFINE_STATIC (name) or G_LOCK_DEFINE (name) * you define them with G_LOCK_DEFINE_STATIC (name) or G_LOCK_DEFINE (name)