static GLogLevelFlags g_log_always_fatal = G_LOG_FATAL_MASK;
static GPrintFunc glib_print_func = NULL;
static GPrintFunc glib_printerr_func = NULL;
-static GPrivate *g_log_depth = NULL;
+static GPrivate g_log_depth;
static GLogLevelFlags g_log_msg_prefix = G_LOG_LEVEL_ERROR | G_LOG_LEVEL_WARNING | G_LOG_LEVEL_CRITICAL | G_LOG_LEVEL_DEBUG;
static GLogFunc default_log_func = g_log_default_handler;
static gpointer default_log_data = NULL;
test_level = 1 << i;
if (log_level & test_level)
{
- guint depth = GPOINTER_TO_UINT (g_private_get (g_log_depth));
+ guint depth = GPOINTER_TO_UINT (g_private_get (&g_log_depth));
GLogDomain *domain;
GLogFunc log_func;
GLogLevelFlags domain_fatal_mask;
domain = NULL;
g_mutex_unlock (&g_messages_lock);
- g_private_set (g_log_depth, GUINT_TO_POINTER (depth));
+ g_private_set (&g_log_depth, GUINT_TO_POINTER (depth));
/* had to defer debug initialization until we can keep track of recursion */
if (!(test_level & G_LOG_FLAG_RECURSION) && !g_debug_initialized)
}
depth--;
- g_private_set (g_log_depth, GUINT_TO_POINTER (depth));
+ g_private_set (&g_log_depth, GUINT_TO_POINTER (depth));
}
}
}
void
_g_messages_thread_init_nomessage (void)
{
- g_log_depth = g_private_new (NULL);
+ g_private_init (&g_log_depth, NULL);
g_messages_prefixed_init ();
g_debug_init ();
}
size_t size);
/* --- variables --- */
-static GPrivate *private_thread_memory = NULL;
+static GPrivate private_thread_memory;
static gsize sys_page_size = 0;
static Allocator allocator[1] = { { 0, }, };
static SliceConfig slice_config = {
* to a g_slice_alloc1() before g_thread_init().
*/
}
- private_thread_memory = g_private_new (private_thread_memory_cleanup);
+ g_private_init (&private_thread_memory, private_thread_memory_cleanup);
}
static inline void
static inline ThreadMemory*
thread_memory_from_self (void)
{
- ThreadMemory *tmem = g_private_get (private_thread_memory);
+ ThreadMemory *tmem = g_private_get (&private_thread_memory);
if (G_UNLIKELY (!tmem))
{
static ThreadMemory *single_thread_memory = NULL; /* remember single-thread info for multi-threaded case */
* threaded case. but not *across* g_thread_init(), after multi-thread
* initialization it returns NULL for previously set single-thread data.
*/
- g_private_set (private_thread_memory, tmem);
+ g_private_set (&private_thread_memory, tmem);
/* save single-thread thread memory structure, in case we need to
* pick it up again after multi-thread initialization happened.
*/
/* {{{1 GPrivate */
GPrivate *
-(g_private_new) (GDestroyNotify notify)
+g_private_new (GDestroyNotify notify)
{
GPrivate *key;
GDestroyNotify notify)
{
pthread_key_create (&key->key, notify);
+ key->ready = TRUE;
}
gpointer
-(g_private_get) (GPrivate *key)
+g_private_get (GPrivate *key)
{
+ if (!key->ready)
+ return key->single_value;
+
/* quote POSIX: No errors are returned from pthread_getspecific(). */
return pthread_getspecific (key->key);
}
void
-(g_private_set) (GPrivate *key,
- gpointer value)
+g_private_set (GPrivate *key,
+ gpointer value)
{
gint status;
+ if (!key->ready)
+ {
+ key->single_value = value;
+ return;
+ }
+
if G_UNLIKELY ((status = pthread_setspecific (key->key, value)) != 0)
g_thread_abort (status, "pthread_setspecific");
}
static GPrivateDestructor * volatile g_private_destructors;
GPrivate *
-(g_private_new) (GDestroyNotify notify)
+g_private_new (GDestroyNotify notify)
{
GPrivate *key;
do
destructor->next = g_private_destructors;
while (InterlockedCompareExchangePointer (&g_private_destructors, destructor->next, destructor) != destructor->next);
+
+ key->ready = TRUE;
}
gpointer
-(g_private_get) (GPrivate *key)
+g_private_get (GPrivate *key)
{
+ if (!key->ready)
+ return key->single_value;
+
return TlsGetValue (key->index);
}
void
-(g_private_set) (GPrivate *key,
+g_private_set (GPrivate *key,
gpointer value)
{
+ if (!key->ready)
+ {
+ key->single_value = value;
+ return;
+ }
+
TlsSetValue (key->index, value);
}
static GMutex g_once_mutex = G_MUTEX_INIT;
static GCond g_once_cond = G_COND_INIT;
-static GPrivate *g_thread_specific_private = NULL;
+static GPrivate g_thread_specific_private;
static GRealThread *g_thread_all_threads = NULL;
static GSList *g_thread_free_indices = NULL;
static GSList* g_once_init_list = NULL;
/* setup the basic threading system */
g_threads_got_initialized = TRUE;
- g_thread_specific_private = g_private_new (g_thread_cleanup);
- g_private_set (g_thread_specific_private, main_thread);
+ g_private_init (&g_thread_specific_private, g_thread_cleanup);
+ g_private_set (&g_thread_specific_private, main_thread);
G_THREAD_UF (thread_self, (&main_thread->system_thread));
/* complete memory system initialization, g_private_*() works now */
g_assert (data);
/* This has to happen before G_LOCK, as that might call g_thread_self */
- g_private_set (g_thread_specific_private, data);
+ g_private_set (&g_thread_specific_private, data);
/* the lock makes sure, that thread->system_thread is written,
before thread->thread.func is called. See g_thread_create. */
GThread*
g_thread_self (void)
{
- GRealThread* thread = g_private_get (g_thread_specific_private);
+ GRealThread* thread = g_private_get (&g_thread_specific_private);
if (!thread)
{
if (g_thread_supported ())
G_THREAD_UF (thread_self, (&thread->system_thread));
- g_private_set (g_thread_specific_private, thread);
+ g_private_set (&g_thread_specific_private, thread);
G_LOCK (g_thread);
thread->next = g_thread_all_threads;
#else
#define g_thread_supported() (g_threads_got_initialized)
#endif
-#define g_private_new(destructor) G_THREAD_UF (private_new, (destructor))
-#define g_private_get(private_key) G_THREAD_CF (private_get, \
- ((gpointer)private_key), \
- (private_key))
-#define g_private_set(private_key, value) G_THREAD_CF (private_set, \
- (void) (private_key = \
- (GPrivate*) (value)), \
- (private_key, value))
#define g_thread_yield() G_THREAD_CF (thread_yield, (void)0, ())
#define g_thread_create(func, data, joinable, error) \
GCond * g_cond_new (void);
void g_cond_free (GCond *cond);
-GPrivate * (g_private_new) (GDestroyNotify notify);
-gpointer (g_private_get) (GPrivate *key);
-void (g_private_set) (GPrivate *key,
+GPrivate * g_private_new (GDestroyNotify notify);
+gpointer g_private_get (GPrivate *key);
+void g_private_set (GPrivate *key,
gpointer value);
G_END_DECLS
struct _GPrivate
{
+ gpointer single_value;
+ gboolean ready;
#ifdef G_OS_WIN32
gint index;
#else