mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-06-07 13:20:06 +02:00
gmain: use GPrivate instead of GStaticPrivate
This commit is contained in:
parent
b3e3914062
commit
baa394910b
25
glib/gmain.c
25
glib/gmain.c
@ -87,7 +87,6 @@
|
|||||||
#include "gqueue.h"
|
#include "gqueue.h"
|
||||||
#include "gstrfuncs.h"
|
#include "gstrfuncs.h"
|
||||||
#include "gtestutils.h"
|
#include "gtestutils.h"
|
||||||
#include "gthreadprivate.h"
|
|
||||||
|
|
||||||
#ifdef G_OS_WIN32
|
#ifdef G_OS_WIN32
|
||||||
#include "gwin32.h"
|
#include "gwin32.h"
|
||||||
@ -607,8 +606,6 @@ g_main_context_default (void)
|
|||||||
return default_main_context;
|
return default_main_context;
|
||||||
}
|
}
|
||||||
|
|
||||||
static GStaticPrivate thread_context_stack = G_STATIC_PRIVATE_INIT;
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
free_context_stack (gpointer data)
|
free_context_stack (gpointer data)
|
||||||
{
|
{
|
||||||
@ -620,11 +617,13 @@ free_context_stack (gpointer data)
|
|||||||
context = g_queue_pop_head (stack);
|
context = g_queue_pop_head (stack);
|
||||||
g_main_context_release (context);
|
g_main_context_release (context);
|
||||||
if (context)
|
if (context)
|
||||||
g_main_context_unref (context);
|
g_main_context_unref (context);
|
||||||
}
|
}
|
||||||
g_queue_free (stack);
|
g_queue_free (stack);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static GPrivate thread_context_stack = G_PRIVATE_INIT (free_context_stack);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* g_main_context_push_thread_default:
|
* g_main_context_push_thread_default:
|
||||||
* @context: a #GMainContext, or %NULL for the global default context
|
* @context: a #GMainContext, or %NULL for the global default context
|
||||||
@ -674,12 +673,11 @@ g_main_context_push_thread_default (GMainContext *context)
|
|||||||
else if (context)
|
else if (context)
|
||||||
g_main_context_ref (context);
|
g_main_context_ref (context);
|
||||||
|
|
||||||
stack = g_static_private_get (&thread_context_stack);
|
stack = g_private_get (&thread_context_stack);
|
||||||
if (!stack)
|
if (!stack)
|
||||||
{
|
{
|
||||||
stack = g_queue_new ();
|
stack = g_queue_new ();
|
||||||
g_static_private_set (&thread_context_stack, stack,
|
g_private_set (&thread_context_stack, stack);
|
||||||
free_context_stack);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
g_queue_push_head (stack, context);
|
g_queue_push_head (stack, context);
|
||||||
@ -702,7 +700,7 @@ g_main_context_pop_thread_default (GMainContext *context)
|
|||||||
if (context == g_main_context_default ())
|
if (context == g_main_context_default ())
|
||||||
context = NULL;
|
context = NULL;
|
||||||
|
|
||||||
stack = g_static_private_get (&thread_context_stack);
|
stack = g_private_get (&thread_context_stack);
|
||||||
|
|
||||||
g_return_if_fail (stack != NULL);
|
g_return_if_fail (stack != NULL);
|
||||||
g_return_if_fail (g_queue_peek_head (stack) == context);
|
g_return_if_fail (g_queue_peek_head (stack) == context);
|
||||||
@ -739,7 +737,7 @@ g_main_context_get_thread_default (void)
|
|||||||
{
|
{
|
||||||
GQueue *stack;
|
GQueue *stack;
|
||||||
|
|
||||||
stack = g_static_private_get (&thread_context_stack);
|
stack = g_private_get (&thread_context_stack);
|
||||||
if (stack)
|
if (stack)
|
||||||
return g_queue_peek_head (stack);
|
return g_queue_peek_head (stack);
|
||||||
else
|
else
|
||||||
@ -2089,12 +2087,15 @@ g_main_dispatch_free (gpointer dispatch)
|
|||||||
static GMainDispatch *
|
static GMainDispatch *
|
||||||
get_dispatch (void)
|
get_dispatch (void)
|
||||||
{
|
{
|
||||||
static GStaticPrivate depth_private = G_STATIC_PRIVATE_INIT;
|
static GPrivate depth_private = G_PRIVATE_INIT (g_main_dispatch_free);
|
||||||
GMainDispatch *dispatch = g_static_private_get (&depth_private);
|
GMainDispatch *dispatch;
|
||||||
|
|
||||||
|
dispatch = g_private_get (&depth_private);
|
||||||
|
|
||||||
if (!dispatch)
|
if (!dispatch)
|
||||||
{
|
{
|
||||||
dispatch = g_slice_new0 (GMainDispatch);
|
dispatch = g_slice_new0 (GMainDispatch);
|
||||||
g_static_private_set (&depth_private, dispatch, g_main_dispatch_free);
|
g_private_set (&depth_private, dispatch);
|
||||||
}
|
}
|
||||||
|
|
||||||
return dispatch;
|
return dispatch;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user