mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-07-31 22:23:39 +02:00
implemented g_once_init_enter(), g_once_init_enter_impl() and
Tue Jul 10 12:24:35 2007 Tim Janik <timj@imendio.com> * glib/gthread.[hc]: implemented g_once_init_enter(), g_once_init_enter_impl() and g_once_init_leave(), based on a patch by Antoine Tremblay, fixes #65041. adapted exported inline function mechanism from gutils.[hc] for inlining g_once_init_enter_impl() in gthread.[hc]. svn path=/trunk/; revision=5616
This commit is contained in:
@@ -32,6 +32,10 @@
|
||||
* MT safe
|
||||
*/
|
||||
|
||||
/* implement gthread.h's inline functions */
|
||||
#define G_IMPLEMENT_INLINES 1
|
||||
#define __G_THREAD_C__
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "glib.h"
|
||||
@@ -121,6 +125,7 @@ static GCond *g_once_cond = NULL;
|
||||
static GPrivate *g_thread_specific_private = NULL;
|
||||
static GRealThread *g_thread_all_threads = NULL;
|
||||
static GSList *g_thread_free_indeces = NULL;
|
||||
static GSList* g_once_init_list = NULL;
|
||||
|
||||
G_LOCK_DEFINE_STATIC (g_thread);
|
||||
|
||||
@@ -194,6 +199,41 @@ g_once_impl (GOnce *once,
|
||||
return once->retval;
|
||||
}
|
||||
|
||||
gboolean
|
||||
g_once_init_enter_impl (volatile gsize *value_location)
|
||||
{
|
||||
gboolean need_init;
|
||||
g_mutex_lock (g_once_mutex);
|
||||
if (!g_once_init_list || !g_slist_find (g_once_init_list, (void*) value_location))
|
||||
{
|
||||
g_once_init_list = g_slist_prepend (g_once_init_list, (void*) value_location);
|
||||
need_init = TRUE;
|
||||
}
|
||||
else
|
||||
{
|
||||
while (g_slist_find (g_once_init_list, (void*) value_location))
|
||||
g_cond_wait (g_once_cond, g_once_mutex);
|
||||
need_init = FALSE;
|
||||
}
|
||||
g_mutex_unlock (g_once_mutex);
|
||||
return need_init;
|
||||
}
|
||||
|
||||
void
|
||||
g_once_init_leave (volatile gsize *value_location,
|
||||
gsize initialization_value)
|
||||
{
|
||||
g_return_if_fail (g_atomic_pointer_get (value_location) == 0);
|
||||
g_return_if_fail (initialization_value != 0);
|
||||
g_return_if_fail (g_once_init_list != NULL);
|
||||
|
||||
g_atomic_pointer_set (value_location, initialization_value);
|
||||
g_mutex_lock (g_once_mutex);
|
||||
g_once_init_list = g_slist_remove (g_once_init_list, (void*) value_location);
|
||||
g_cond_broadcast (g_once_cond);
|
||||
g_mutex_unlock (g_once_mutex);
|
||||
}
|
||||
|
||||
void
|
||||
g_static_mutex_init (GStaticMutex *mutex)
|
||||
{
|
||||
|
Reference in New Issue
Block a user