mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-06-06 12:50:07 +02:00
GStaticPrivate: implement via GPrivate
Thanks to the modifications in 3d4846d92309d001697c2827660fa41b5c63dbc4, GStaticPrivate is not so directly tied in with GThread anymore. It is now a simple matter to cut it out completely by using a GPrivate to store the GArray instead of storing it in the GThread.
This commit is contained in:
parent
c6016458ba
commit
9bb5a55bda
@ -1221,6 +1221,24 @@ struct _GStaticPrivateNode
|
|||||||
GStaticPrivate *owner;
|
GStaticPrivate *owner;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
void
|
||||||
|
g_static_private_cleanup (gpointer data)
|
||||||
|
{
|
||||||
|
GArray *array = data;
|
||||||
|
guint i;
|
||||||
|
|
||||||
|
for (i = 0; i < array->len; i++ )
|
||||||
|
{
|
||||||
|
GStaticPrivateNode *node = &g_array_index (array, GStaticPrivateNode, i);
|
||||||
|
if (node->destroy)
|
||||||
|
node->destroy (node->data);
|
||||||
|
}
|
||||||
|
|
||||||
|
g_array_free (array, TRUE);
|
||||||
|
}
|
||||||
|
|
||||||
|
GPrivate static_private_private = G_PRIVATE_INIT (g_static_private_cleanup);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* GStaticPrivate:
|
* GStaticPrivate:
|
||||||
*
|
*
|
||||||
@ -1292,10 +1310,10 @@ g_static_private_init (GStaticPrivate *private_key)
|
|||||||
gpointer
|
gpointer
|
||||||
g_static_private_get (GStaticPrivate *private_key)
|
g_static_private_get (GStaticPrivate *private_key)
|
||||||
{
|
{
|
||||||
GRealThread *self = (GRealThread*) g_thread_self ();
|
|
||||||
GArray *array;
|
GArray *array;
|
||||||
gpointer ret = NULL;
|
gpointer ret = NULL;
|
||||||
array = self->private_data;
|
|
||||||
|
array = g_private_get (&static_private_private);
|
||||||
|
|
||||||
if (array && private_key->index != 0 && private_key->index <= array->len)
|
if (array && private_key->index != 0 && private_key->index <= array->len)
|
||||||
{
|
{
|
||||||
@ -1347,7 +1365,6 @@ g_static_private_set (GStaticPrivate *private_key,
|
|||||||
gpointer data,
|
gpointer data,
|
||||||
GDestroyNotify notify)
|
GDestroyNotify notify)
|
||||||
{
|
{
|
||||||
GRealThread *self = (GRealThread*) g_thread_self ();
|
|
||||||
GArray *array;
|
GArray *array;
|
||||||
static guint next_index = 0;
|
static guint next_index = 0;
|
||||||
GStaticPrivateNode *node;
|
GStaticPrivateNode *node;
|
||||||
@ -1371,11 +1388,11 @@ g_static_private_set (GStaticPrivate *private_key,
|
|||||||
G_UNLOCK (g_thread);
|
G_UNLOCK (g_thread);
|
||||||
}
|
}
|
||||||
|
|
||||||
array = self->private_data;
|
array = g_private_get (&static_private_private);
|
||||||
if (!array)
|
if (!array)
|
||||||
{
|
{
|
||||||
array = g_array_new (FALSE, TRUE, sizeof (GStaticPrivateNode));
|
array = g_array_new (FALSE, TRUE, sizeof (GStaticPrivateNode));
|
||||||
self->private_data = array;
|
g_private_set (&static_private_private, array);
|
||||||
}
|
}
|
||||||
if (private_key->index > array->len)
|
if (private_key->index > array->len)
|
||||||
g_array_set_size (array, private_key->index);
|
g_array_set_size (array, private_key->index);
|
||||||
@ -1421,28 +1438,6 @@ g_static_private_free (GStaticPrivate *private_key)
|
|||||||
G_UNLOCK (g_thread);
|
G_UNLOCK (g_thread);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
|
||||||
g_static_private_cleanup (GRealThread *thread)
|
|
||||||
{
|
|
||||||
GArray *array;
|
|
||||||
|
|
||||||
array = thread->private_data;
|
|
||||||
thread->private_data = NULL;
|
|
||||||
|
|
||||||
if (array)
|
|
||||||
{
|
|
||||||
guint i;
|
|
||||||
|
|
||||||
for (i = 0; i < array->len; i++ )
|
|
||||||
{
|
|
||||||
GStaticPrivateNode *node = &g_array_index (array, GStaticPrivateNode, i);
|
|
||||||
if (node->destroy)
|
|
||||||
node->destroy (node->data);
|
|
||||||
}
|
|
||||||
g_array_free (array, TRUE);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* GMutex {{{1 ------------------------------------------------------ */
|
/* GMutex {{{1 ------------------------------------------------------ */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -673,8 +673,6 @@ g_thread_cleanup (gpointer data)
|
|||||||
{
|
{
|
||||||
GRealThread* thread = data;
|
GRealThread* thread = data;
|
||||||
|
|
||||||
g_static_private_cleanup (thread);
|
|
||||||
|
|
||||||
/* We only free the thread structure if it isn't joinable.
|
/* We only free the thread structure if it isn't joinable.
|
||||||
* If it is, the structure is freed in g_thread_join()
|
* If it is, the structure is freed in g_thread_join()
|
||||||
*/
|
*/
|
||||||
@ -818,7 +816,6 @@ g_thread_new_internal (const gchar *name,
|
|||||||
result->thread.joinable = joinable;
|
result->thread.joinable = joinable;
|
||||||
result->thread.func = func;
|
result->thread.func = func;
|
||||||
result->thread.data = data;
|
result->thread.data = data;
|
||||||
result->private_data = NULL;
|
|
||||||
result->enumerable = enumerable;
|
result->enumerable = enumerable;
|
||||||
result->name = name;
|
result->name = name;
|
||||||
G_LOCK (g_thread_new);
|
G_LOCK (g_thread_new);
|
||||||
@ -941,7 +938,6 @@ g_thread_self (void)
|
|||||||
thread->thread.joinable = FALSE; /* This is a safe guess */
|
thread->thread.joinable = FALSE; /* This is a safe guess */
|
||||||
thread->thread.func = NULL;
|
thread->thread.func = NULL;
|
||||||
thread->thread.data = NULL;
|
thread->thread.data = NULL;
|
||||||
thread->private_data = NULL;
|
|
||||||
thread->enumerable = FALSE;
|
thread->enumerable = FALSE;
|
||||||
|
|
||||||
g_system_thread_self (&thread->system_thread);
|
g_system_thread_self (&thread->system_thread);
|
||||||
|
@ -64,7 +64,6 @@ typedef struct _GRealThread GRealThread;
|
|||||||
struct _GRealThread
|
struct _GRealThread
|
||||||
{
|
{
|
||||||
GThread thread;
|
GThread thread;
|
||||||
GArray *private_data;
|
|
||||||
GRealThread *next;
|
GRealThread *next;
|
||||||
const gchar *name;
|
const gchar *name;
|
||||||
gboolean enumerable;
|
gboolean enumerable;
|
||||||
@ -75,7 +74,6 @@ struct _GRealThread
|
|||||||
G_GNUC_INTERNAL extern GSystemThread zero_thread;
|
G_GNUC_INTERNAL extern GSystemThread zero_thread;
|
||||||
G_GNUC_INTERNAL extern GMutex g_once_mutex;
|
G_GNUC_INTERNAL extern GMutex g_once_mutex;
|
||||||
|
|
||||||
G_GNUC_INTERNAL void g_static_private_cleanup (GRealThread *thread);
|
|
||||||
G_GNUC_INTERNAL void g_enumerable_thread_add (GRealThread *thread);
|
G_GNUC_INTERNAL void g_enumerable_thread_add (GRealThread *thread);
|
||||||
G_GNUC_INTERNAL void g_enumerable_thread_remove (GRealThread *thread);
|
G_GNUC_INTERNAL void g_enumerable_thread_remove (GRealThread *thread);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user