mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-01-11 23:16:14 +01:00
Use the new GRealThread member "context" instead of a GStaticPrivate to
2001-04-02 Sebastian Wilhelmi <wilhelmi@ira.uka.de> * gmain.c: Use the new GRealThread member "context" instead of a GStaticPrivate to store the thread specific main loop context. * gthread.c: Added "context" member to GRealThread and updated g_thread_create, g_thread_self and g_thread_cleanup accordingly. * gthread.c, gthread.h: Removed the functions g_static_private_(get|set)_for_thread and adapted g_static_private_(get|set) and g_static_private_free accordingly.
This commit is contained in:
parent
743f49cec9
commit
7b06f826c9
12
ChangeLog
12
ChangeLog
@ -1,3 +1,15 @@
|
|||||||
|
2001-04-02 Sebastian Wilhelmi <wilhelmi@ira.uka.de>
|
||||||
|
|
||||||
|
* gmain.c: Use the new GRealThread member "context" instead of a
|
||||||
|
GStaticPrivate to store the thread specific main loop context.
|
||||||
|
|
||||||
|
* gthread.c: Added "context" member to GRealThread and updated
|
||||||
|
g_thread_create, g_thread_self and g_thread_cleanup accordingly.
|
||||||
|
|
||||||
|
* gthread.c, gthread.h: Removed the functions
|
||||||
|
g_static_private_(get|set)_for_thread and adapted
|
||||||
|
g_static_private_(get|set) and g_static_private_free accordingly.
|
||||||
|
|
||||||
2001-03-30 Sven Neumann <sven@gimp.org>
|
2001-03-30 Sven Neumann <sven@gimp.org>
|
||||||
|
|
||||||
* ghash.[ch]
|
* ghash.[ch]
|
||||||
|
@ -1,3 +1,15 @@
|
|||||||
|
2001-04-02 Sebastian Wilhelmi <wilhelmi@ira.uka.de>
|
||||||
|
|
||||||
|
* gmain.c: Use the new GRealThread member "context" instead of a
|
||||||
|
GStaticPrivate to store the thread specific main loop context.
|
||||||
|
|
||||||
|
* gthread.c: Added "context" member to GRealThread and updated
|
||||||
|
g_thread_create, g_thread_self and g_thread_cleanup accordingly.
|
||||||
|
|
||||||
|
* gthread.c, gthread.h: Removed the functions
|
||||||
|
g_static_private_(get|set)_for_thread and adapted
|
||||||
|
g_static_private_(get|set) and g_static_private_free accordingly.
|
||||||
|
|
||||||
2001-03-30 Sven Neumann <sven@gimp.org>
|
2001-03-30 Sven Neumann <sven@gimp.org>
|
||||||
|
|
||||||
* ghash.[ch]
|
* ghash.[ch]
|
||||||
|
@ -1,3 +1,15 @@
|
|||||||
|
2001-04-02 Sebastian Wilhelmi <wilhelmi@ira.uka.de>
|
||||||
|
|
||||||
|
* gmain.c: Use the new GRealThread member "context" instead of a
|
||||||
|
GStaticPrivate to store the thread specific main loop context.
|
||||||
|
|
||||||
|
* gthread.c: Added "context" member to GRealThread and updated
|
||||||
|
g_thread_create, g_thread_self and g_thread_cleanup accordingly.
|
||||||
|
|
||||||
|
* gthread.c, gthread.h: Removed the functions
|
||||||
|
g_static_private_(get|set)_for_thread and adapted
|
||||||
|
g_static_private_(get|set) and g_static_private_free accordingly.
|
||||||
|
|
||||||
2001-03-30 Sven Neumann <sven@gimp.org>
|
2001-03-30 Sven Neumann <sven@gimp.org>
|
||||||
|
|
||||||
* ghash.[ch]
|
* ghash.[ch]
|
||||||
|
@ -1,3 +1,15 @@
|
|||||||
|
2001-04-02 Sebastian Wilhelmi <wilhelmi@ira.uka.de>
|
||||||
|
|
||||||
|
* gmain.c: Use the new GRealThread member "context" instead of a
|
||||||
|
GStaticPrivate to store the thread specific main loop context.
|
||||||
|
|
||||||
|
* gthread.c: Added "context" member to GRealThread and updated
|
||||||
|
g_thread_create, g_thread_self and g_thread_cleanup accordingly.
|
||||||
|
|
||||||
|
* gthread.c, gthread.h: Removed the functions
|
||||||
|
g_static_private_(get|set)_for_thread and adapted
|
||||||
|
g_static_private_(get|set) and g_static_private_free accordingly.
|
||||||
|
|
||||||
2001-03-30 Sven Neumann <sven@gimp.org>
|
2001-03-30 Sven Neumann <sven@gimp.org>
|
||||||
|
|
||||||
* ghash.[ch]
|
* ghash.[ch]
|
||||||
|
@ -1,3 +1,15 @@
|
|||||||
|
2001-04-02 Sebastian Wilhelmi <wilhelmi@ira.uka.de>
|
||||||
|
|
||||||
|
* gmain.c: Use the new GRealThread member "context" instead of a
|
||||||
|
GStaticPrivate to store the thread specific main loop context.
|
||||||
|
|
||||||
|
* gthread.c: Added "context" member to GRealThread and updated
|
||||||
|
g_thread_create, g_thread_self and g_thread_cleanup accordingly.
|
||||||
|
|
||||||
|
* gthread.c, gthread.h: Removed the functions
|
||||||
|
g_static_private_(get|set)_for_thread and adapted
|
||||||
|
g_static_private_(get|set) and g_static_private_free accordingly.
|
||||||
|
|
||||||
2001-03-30 Sven Neumann <sven@gimp.org>
|
2001-03-30 Sven Neumann <sven@gimp.org>
|
||||||
|
|
||||||
* ghash.[ch]
|
* ghash.[ch]
|
||||||
|
@ -1,3 +1,15 @@
|
|||||||
|
2001-04-02 Sebastian Wilhelmi <wilhelmi@ira.uka.de>
|
||||||
|
|
||||||
|
* gmain.c: Use the new GRealThread member "context" instead of a
|
||||||
|
GStaticPrivate to store the thread specific main loop context.
|
||||||
|
|
||||||
|
* gthread.c: Added "context" member to GRealThread and updated
|
||||||
|
g_thread_create, g_thread_self and g_thread_cleanup accordingly.
|
||||||
|
|
||||||
|
* gthread.c, gthread.h: Removed the functions
|
||||||
|
g_static_private_(get|set)_for_thread and adapted
|
||||||
|
g_static_private_(get|set) and g_static_private_free accordingly.
|
||||||
|
|
||||||
2001-03-30 Sven Neumann <sven@gimp.org>
|
2001-03-30 Sven Neumann <sven@gimp.org>
|
||||||
|
|
||||||
* ghash.[ch]
|
* ghash.[ch]
|
||||||
|
@ -1,3 +1,15 @@
|
|||||||
|
2001-04-02 Sebastian Wilhelmi <wilhelmi@ira.uka.de>
|
||||||
|
|
||||||
|
* gmain.c: Use the new GRealThread member "context" instead of a
|
||||||
|
GStaticPrivate to store the thread specific main loop context.
|
||||||
|
|
||||||
|
* gthread.c: Added "context" member to GRealThread and updated
|
||||||
|
g_thread_create, g_thread_self and g_thread_cleanup accordingly.
|
||||||
|
|
||||||
|
* gthread.c, gthread.h: Removed the functions
|
||||||
|
g_static_private_(get|set)_for_thread and adapted
|
||||||
|
g_static_private_(get|set) and g_static_private_free accordingly.
|
||||||
|
|
||||||
2001-03-30 Sven Neumann <sven@gimp.org>
|
2001-03-30 Sven Neumann <sven@gimp.org>
|
||||||
|
|
||||||
* ghash.[ch]
|
* ghash.[ch]
|
||||||
|
@ -1,3 +1,15 @@
|
|||||||
|
2001-04-02 Sebastian Wilhelmi <wilhelmi@ira.uka.de>
|
||||||
|
|
||||||
|
* gmain.c: Use the new GRealThread member "context" instead of a
|
||||||
|
GStaticPrivate to store the thread specific main loop context.
|
||||||
|
|
||||||
|
* gthread.c: Added "context" member to GRealThread and updated
|
||||||
|
g_thread_create, g_thread_self and g_thread_cleanup accordingly.
|
||||||
|
|
||||||
|
* gthread.c, gthread.h: Removed the functions
|
||||||
|
g_static_private_(get|set)_for_thread and adapted
|
||||||
|
g_static_private_(get|set) and g_static_private_free accordingly.
|
||||||
|
|
||||||
2001-03-30 Sven Neumann <sven@gimp.org>
|
2001-03-30 Sven Neumann <sven@gimp.org>
|
||||||
|
|
||||||
* ghash.[ch]
|
* ghash.[ch]
|
||||||
|
22
glib/gmain.c
22
glib/gmain.c
@ -496,7 +496,7 @@ g_poll (GPollFD *fds,
|
|||||||
|
|
||||||
/* Called to clean up when a thread terminates
|
/* Called to clean up when a thread terminates
|
||||||
*/
|
*/
|
||||||
static void
|
void
|
||||||
g_main_context_destroy (GMainContext *context)
|
g_main_context_destroy (GMainContext *context)
|
||||||
{
|
{
|
||||||
GSource *source;
|
GSource *source;
|
||||||
@ -538,6 +538,18 @@ g_main_context_destroy (GMainContext *context)
|
|||||||
g_free (context);
|
g_free (context);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* This is an imcomplete (only the members up till context) version of
|
||||||
|
* GRealThread from gthread.h. Keep them in sync */
|
||||||
|
typedef struct _GRealThread GRealThread;
|
||||||
|
struct _GRealThread
|
||||||
|
{
|
||||||
|
GThread thread;
|
||||||
|
GThreadFunc func;
|
||||||
|
gpointer arg;
|
||||||
|
gpointer private_data;
|
||||||
|
GMainContext *context;
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* g_main_context_get:
|
* g_main_context_get:
|
||||||
* @thread: a #GThread
|
* @thread: a #GThread
|
||||||
@ -551,13 +563,13 @@ g_main_context_destroy (GMainContext *context)
|
|||||||
GMainContext *
|
GMainContext *
|
||||||
g_main_context_get (GThread *thread)
|
g_main_context_get (GThread *thread)
|
||||||
{
|
{
|
||||||
static GStaticPrivate private_key = G_STATIC_PRIVATE_INIT;
|
GRealThread *real_thread = (GRealThread*)thread;
|
||||||
GMainContext *context;
|
GMainContext *context;
|
||||||
|
|
||||||
g_return_val_if_fail (thread != NULL, NULL);
|
g_return_val_if_fail (thread != NULL, NULL);
|
||||||
|
|
||||||
if (g_thread_supported ())
|
if (g_thread_supported ())
|
||||||
context = g_static_private_get_for_thread (&private_key, thread);
|
context = real_thread->context;
|
||||||
else
|
else
|
||||||
context = default_main_context;
|
context = default_main_context;
|
||||||
|
|
||||||
@ -616,9 +628,7 @@ g_main_context_get (GThread *thread)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (g_thread_supported ())
|
if (g_thread_supported ())
|
||||||
g_static_private_set_for_thread (&private_key, thread,
|
real_thread->context = context;
|
||||||
context,
|
|
||||||
(GDestroyNotify)g_main_context_destroy);
|
|
||||||
else
|
else
|
||||||
default_main_context = context;
|
default_main_context = context;
|
||||||
}
|
}
|
||||||
|
@ -69,6 +69,7 @@ g_thread_error_quark (void)
|
|||||||
return quark;
|
return quark;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Keep this in sync with GRealThread in gmain.c! */
|
||||||
typedef struct _GRealThread GRealThread;
|
typedef struct _GRealThread GRealThread;
|
||||||
struct _GRealThread
|
struct _GRealThread
|
||||||
{
|
{
|
||||||
@ -76,6 +77,7 @@ struct _GRealThread
|
|||||||
GThreadFunc func;
|
GThreadFunc func;
|
||||||
gpointer arg;
|
gpointer arg;
|
||||||
gpointer private_data;
|
gpointer private_data;
|
||||||
|
GMainContext *context;
|
||||||
GSystemThread system_thread;
|
GSystemThread system_thread;
|
||||||
#ifdef G_THREAD_USE_PID_SURROGATE
|
#ifdef G_THREAD_USE_PID_SURROGATE
|
||||||
pid_t pid;
|
pid_t pid;
|
||||||
@ -346,17 +348,8 @@ g_static_private_init (GStaticPrivate *private_key)
|
|||||||
gpointer
|
gpointer
|
||||||
g_static_private_get (GStaticPrivate *private_key)
|
g_static_private_get (GStaticPrivate *private_key)
|
||||||
{
|
{
|
||||||
return g_static_private_get_for_thread (private_key, g_thread_self ());
|
GRealThread *self = (GRealThread*) g_thread_self ();
|
||||||
}
|
|
||||||
|
|
||||||
gpointer
|
|
||||||
g_static_private_get_for_thread (GStaticPrivate *private_key,
|
|
||||||
GThread *thread)
|
|
||||||
{
|
|
||||||
GArray *array;
|
GArray *array;
|
||||||
GRealThread *self = (GRealThread*) thread;
|
|
||||||
|
|
||||||
g_return_val_if_fail (thread, NULL);
|
|
||||||
|
|
||||||
array = self->private_data;
|
array = self->private_data;
|
||||||
if (!array)
|
if (!array)
|
||||||
@ -365,7 +358,8 @@ g_static_private_get_for_thread (GStaticPrivate *private_key,
|
|||||||
if (!private_key->index)
|
if (!private_key->index)
|
||||||
return NULL;
|
return NULL;
|
||||||
else if (private_key->index <= array->len)
|
else if (private_key->index <= array->len)
|
||||||
return g_array_index (array, GStaticPrivateNode, private_key->index - 1).data;
|
return g_array_index (array, GStaticPrivateNode,
|
||||||
|
private_key->index - 1).data;
|
||||||
else
|
else
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@ -375,23 +369,11 @@ g_static_private_set (GStaticPrivate *private_key,
|
|||||||
gpointer data,
|
gpointer data,
|
||||||
GDestroyNotify notify)
|
GDestroyNotify notify)
|
||||||
{
|
{
|
||||||
g_static_private_set_for_thread (private_key, g_thread_self (),
|
GRealThread *self = (GRealThread*) g_thread_self ();
|
||||||
data, notify);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
g_static_private_set_for_thread (GStaticPrivate *private_key,
|
|
||||||
GThread *thread,
|
|
||||||
gpointer data,
|
|
||||||
GDestroyNotify notify)
|
|
||||||
{
|
|
||||||
GArray *array;
|
GArray *array;
|
||||||
GRealThread *self =(GRealThread*) thread;
|
|
||||||
static guint next_index = 0;
|
static guint next_index = 0;
|
||||||
GStaticPrivateNode *node;
|
GStaticPrivateNode *node;
|
||||||
|
|
||||||
g_return_if_fail (thread);
|
|
||||||
|
|
||||||
array = self->private_data;
|
array = self->private_data;
|
||||||
if (!array)
|
if (!array)
|
||||||
{
|
{
|
||||||
@ -444,32 +426,48 @@ g_static_private_set_for_thread (GStaticPrivate *private_key,
|
|||||||
void
|
void
|
||||||
g_static_private_free (GStaticPrivate *private_key)
|
g_static_private_free (GStaticPrivate *private_key)
|
||||||
{
|
{
|
||||||
GStaticPrivate copied_key;
|
guint index = private_key->index;
|
||||||
GSList *list;
|
GSList *list;
|
||||||
|
|
||||||
copied_key.index = private_key->index;
|
if (!index)
|
||||||
private_key->index = 0;
|
|
||||||
|
|
||||||
if (!copied_key.index)
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
private_key->index = 0;
|
||||||
|
|
||||||
G_LOCK (g_thread);
|
G_LOCK (g_thread);
|
||||||
list = g_thread_all_threads;
|
list = g_thread_all_threads;
|
||||||
while (list)
|
while (list)
|
||||||
{
|
{
|
||||||
GThread *thread = list->data;
|
GRealThread *thread = list->data;
|
||||||
|
GArray *array = thread->private_data;
|
||||||
list = list->next;
|
list = list->next;
|
||||||
|
|
||||||
G_UNLOCK (g_thread);
|
if (array && index <= array->len)
|
||||||
g_static_private_set_for_thread (&copied_key, thread, NULL, NULL);
|
{
|
||||||
G_LOCK (g_thread);
|
GStaticPrivateNode *node = &g_array_index (array,
|
||||||
|
GStaticPrivateNode,
|
||||||
|
index - 1);
|
||||||
|
gpointer ddata = node->data;
|
||||||
|
GDestroyNotify ddestroy = node->destroy;
|
||||||
|
|
||||||
|
node->data = NULL;
|
||||||
|
node->destroy = NULL;
|
||||||
|
|
||||||
|
if (ddestroy)
|
||||||
|
{
|
||||||
|
G_UNLOCK (g_thread);
|
||||||
|
ddestroy (ddata);
|
||||||
|
G_LOCK (g_thread);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
g_thread_free_indeces =
|
g_thread_free_indeces = g_slist_prepend (g_thread_free_indeces,
|
||||||
g_slist_prepend (g_thread_free_indeces,
|
GUINT_TO_POINTER (index));
|
||||||
GUINT_TO_POINTER (copied_key.index));
|
|
||||||
G_UNLOCK (g_thread);
|
G_UNLOCK (g_thread);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void g_main_context_destroy (GMainContext *context);
|
||||||
|
|
||||||
static void
|
static void
|
||||||
g_thread_cleanup (gpointer data)
|
g_thread_cleanup (gpointer data)
|
||||||
{
|
{
|
||||||
@ -490,6 +488,9 @@ g_thread_cleanup (gpointer data)
|
|||||||
}
|
}
|
||||||
g_array_free (array, TRUE);
|
g_array_free (array, TRUE);
|
||||||
}
|
}
|
||||||
|
if (thread->context)
|
||||||
|
g_main_context_destroy (thread->context);
|
||||||
|
|
||||||
/* We only free the thread structure, if it isn't joinable. If
|
/* We only free the thread structure, if it isn't joinable. If
|
||||||
it is, the structure is freed in g_thread_join */
|
it is, the structure is freed in g_thread_join */
|
||||||
if (!thread->thread.joinable)
|
if (!thread->thread.joinable)
|
||||||
@ -559,6 +560,7 @@ g_thread_create (GThreadFunc thread_func,
|
|||||||
result->func = thread_func;
|
result->func = thread_func;
|
||||||
result->arg = arg;
|
result->arg = arg;
|
||||||
result->private_data = NULL;
|
result->private_data = NULL;
|
||||||
|
result->context = NULL;
|
||||||
G_LOCK (g_thread);
|
G_LOCK (g_thread);
|
||||||
G_THREAD_UF (thread_create, (g_thread_create_proxy, result,
|
G_THREAD_UF (thread_create, (g_thread_create_proxy, result,
|
||||||
stack_size, joinable, bound, priority,
|
stack_size, joinable, bound, priority,
|
||||||
@ -643,6 +645,7 @@ g_thread_self (void)
|
|||||||
thread->func = NULL;
|
thread->func = NULL;
|
||||||
thread->arg = NULL;
|
thread->arg = NULL;
|
||||||
thread->private_data = NULL;
|
thread->private_data = NULL;
|
||||||
|
thread->context = NULL;
|
||||||
|
|
||||||
if (g_thread_supported ())
|
if (g_thread_supported ())
|
||||||
G_THREAD_UF (thread_self, (&thread->system_thread));
|
G_THREAD_UF (thread_self, (&thread->system_thread));
|
||||||
|
@ -229,12 +229,6 @@ gpointer g_static_private_get (GStaticPrivate *private_key);
|
|||||||
void g_static_private_set (GStaticPrivate *private_key,
|
void g_static_private_set (GStaticPrivate *private_key,
|
||||||
gpointer data,
|
gpointer data,
|
||||||
GDestroyNotify notify);
|
GDestroyNotify notify);
|
||||||
gpointer g_static_private_get_for_thread (GStaticPrivate *private_key,
|
|
||||||
GThread *thread);
|
|
||||||
void g_static_private_set_for_thread (GStaticPrivate *private_key,
|
|
||||||
GThread *thread,
|
|
||||||
gpointer data,
|
|
||||||
GDestroyNotify notify);
|
|
||||||
void g_static_private_free (GStaticPrivate *private_key);
|
void g_static_private_free (GStaticPrivate *private_key);
|
||||||
|
|
||||||
typedef struct _GStaticRecMutex GStaticRecMutex;
|
typedef struct _GStaticRecMutex GStaticRecMutex;
|
||||||
|
22
gmain.c
22
gmain.c
@ -496,7 +496,7 @@ g_poll (GPollFD *fds,
|
|||||||
|
|
||||||
/* Called to clean up when a thread terminates
|
/* Called to clean up when a thread terminates
|
||||||
*/
|
*/
|
||||||
static void
|
void
|
||||||
g_main_context_destroy (GMainContext *context)
|
g_main_context_destroy (GMainContext *context)
|
||||||
{
|
{
|
||||||
GSource *source;
|
GSource *source;
|
||||||
@ -538,6 +538,18 @@ g_main_context_destroy (GMainContext *context)
|
|||||||
g_free (context);
|
g_free (context);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* This is an imcomplete (only the members up till context) version of
|
||||||
|
* GRealThread from gthread.h. Keep them in sync */
|
||||||
|
typedef struct _GRealThread GRealThread;
|
||||||
|
struct _GRealThread
|
||||||
|
{
|
||||||
|
GThread thread;
|
||||||
|
GThreadFunc func;
|
||||||
|
gpointer arg;
|
||||||
|
gpointer private_data;
|
||||||
|
GMainContext *context;
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* g_main_context_get:
|
* g_main_context_get:
|
||||||
* @thread: a #GThread
|
* @thread: a #GThread
|
||||||
@ -551,13 +563,13 @@ g_main_context_destroy (GMainContext *context)
|
|||||||
GMainContext *
|
GMainContext *
|
||||||
g_main_context_get (GThread *thread)
|
g_main_context_get (GThread *thread)
|
||||||
{
|
{
|
||||||
static GStaticPrivate private_key = G_STATIC_PRIVATE_INIT;
|
GRealThread *real_thread = (GRealThread*)thread;
|
||||||
GMainContext *context;
|
GMainContext *context;
|
||||||
|
|
||||||
g_return_val_if_fail (thread != NULL, NULL);
|
g_return_val_if_fail (thread != NULL, NULL);
|
||||||
|
|
||||||
if (g_thread_supported ())
|
if (g_thread_supported ())
|
||||||
context = g_static_private_get_for_thread (&private_key, thread);
|
context = real_thread->context;
|
||||||
else
|
else
|
||||||
context = default_main_context;
|
context = default_main_context;
|
||||||
|
|
||||||
@ -616,9 +628,7 @@ g_main_context_get (GThread *thread)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (g_thread_supported ())
|
if (g_thread_supported ())
|
||||||
g_static_private_set_for_thread (&private_key, thread,
|
real_thread->context = context;
|
||||||
context,
|
|
||||||
(GDestroyNotify)g_main_context_destroy);
|
|
||||||
else
|
else
|
||||||
default_main_context = context;
|
default_main_context = context;
|
||||||
}
|
}
|
||||||
|
77
gthread.c
77
gthread.c
@ -69,6 +69,7 @@ g_thread_error_quark (void)
|
|||||||
return quark;
|
return quark;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Keep this in sync with GRealThread in gmain.c! */
|
||||||
typedef struct _GRealThread GRealThread;
|
typedef struct _GRealThread GRealThread;
|
||||||
struct _GRealThread
|
struct _GRealThread
|
||||||
{
|
{
|
||||||
@ -76,6 +77,7 @@ struct _GRealThread
|
|||||||
GThreadFunc func;
|
GThreadFunc func;
|
||||||
gpointer arg;
|
gpointer arg;
|
||||||
gpointer private_data;
|
gpointer private_data;
|
||||||
|
GMainContext *context;
|
||||||
GSystemThread system_thread;
|
GSystemThread system_thread;
|
||||||
#ifdef G_THREAD_USE_PID_SURROGATE
|
#ifdef G_THREAD_USE_PID_SURROGATE
|
||||||
pid_t pid;
|
pid_t pid;
|
||||||
@ -346,17 +348,8 @@ g_static_private_init (GStaticPrivate *private_key)
|
|||||||
gpointer
|
gpointer
|
||||||
g_static_private_get (GStaticPrivate *private_key)
|
g_static_private_get (GStaticPrivate *private_key)
|
||||||
{
|
{
|
||||||
return g_static_private_get_for_thread (private_key, g_thread_self ());
|
GRealThread *self = (GRealThread*) g_thread_self ();
|
||||||
}
|
|
||||||
|
|
||||||
gpointer
|
|
||||||
g_static_private_get_for_thread (GStaticPrivate *private_key,
|
|
||||||
GThread *thread)
|
|
||||||
{
|
|
||||||
GArray *array;
|
GArray *array;
|
||||||
GRealThread *self = (GRealThread*) thread;
|
|
||||||
|
|
||||||
g_return_val_if_fail (thread, NULL);
|
|
||||||
|
|
||||||
array = self->private_data;
|
array = self->private_data;
|
||||||
if (!array)
|
if (!array)
|
||||||
@ -365,7 +358,8 @@ g_static_private_get_for_thread (GStaticPrivate *private_key,
|
|||||||
if (!private_key->index)
|
if (!private_key->index)
|
||||||
return NULL;
|
return NULL;
|
||||||
else if (private_key->index <= array->len)
|
else if (private_key->index <= array->len)
|
||||||
return g_array_index (array, GStaticPrivateNode, private_key->index - 1).data;
|
return g_array_index (array, GStaticPrivateNode,
|
||||||
|
private_key->index - 1).data;
|
||||||
else
|
else
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@ -375,23 +369,11 @@ g_static_private_set (GStaticPrivate *private_key,
|
|||||||
gpointer data,
|
gpointer data,
|
||||||
GDestroyNotify notify)
|
GDestroyNotify notify)
|
||||||
{
|
{
|
||||||
g_static_private_set_for_thread (private_key, g_thread_self (),
|
GRealThread *self = (GRealThread*) g_thread_self ();
|
||||||
data, notify);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
g_static_private_set_for_thread (GStaticPrivate *private_key,
|
|
||||||
GThread *thread,
|
|
||||||
gpointer data,
|
|
||||||
GDestroyNotify notify)
|
|
||||||
{
|
|
||||||
GArray *array;
|
GArray *array;
|
||||||
GRealThread *self =(GRealThread*) thread;
|
|
||||||
static guint next_index = 0;
|
static guint next_index = 0;
|
||||||
GStaticPrivateNode *node;
|
GStaticPrivateNode *node;
|
||||||
|
|
||||||
g_return_if_fail (thread);
|
|
||||||
|
|
||||||
array = self->private_data;
|
array = self->private_data;
|
||||||
if (!array)
|
if (!array)
|
||||||
{
|
{
|
||||||
@ -444,32 +426,48 @@ g_static_private_set_for_thread (GStaticPrivate *private_key,
|
|||||||
void
|
void
|
||||||
g_static_private_free (GStaticPrivate *private_key)
|
g_static_private_free (GStaticPrivate *private_key)
|
||||||
{
|
{
|
||||||
GStaticPrivate copied_key;
|
guint index = private_key->index;
|
||||||
GSList *list;
|
GSList *list;
|
||||||
|
|
||||||
copied_key.index = private_key->index;
|
if (!index)
|
||||||
private_key->index = 0;
|
|
||||||
|
|
||||||
if (!copied_key.index)
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
private_key->index = 0;
|
||||||
|
|
||||||
G_LOCK (g_thread);
|
G_LOCK (g_thread);
|
||||||
list = g_thread_all_threads;
|
list = g_thread_all_threads;
|
||||||
while (list)
|
while (list)
|
||||||
{
|
{
|
||||||
GThread *thread = list->data;
|
GRealThread *thread = list->data;
|
||||||
|
GArray *array = thread->private_data;
|
||||||
list = list->next;
|
list = list->next;
|
||||||
|
|
||||||
G_UNLOCK (g_thread);
|
if (array && index <= array->len)
|
||||||
g_static_private_set_for_thread (&copied_key, thread, NULL, NULL);
|
{
|
||||||
G_LOCK (g_thread);
|
GStaticPrivateNode *node = &g_array_index (array,
|
||||||
|
GStaticPrivateNode,
|
||||||
|
index - 1);
|
||||||
|
gpointer ddata = node->data;
|
||||||
|
GDestroyNotify ddestroy = node->destroy;
|
||||||
|
|
||||||
|
node->data = NULL;
|
||||||
|
node->destroy = NULL;
|
||||||
|
|
||||||
|
if (ddestroy)
|
||||||
|
{
|
||||||
|
G_UNLOCK (g_thread);
|
||||||
|
ddestroy (ddata);
|
||||||
|
G_LOCK (g_thread);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
g_thread_free_indeces =
|
g_thread_free_indeces = g_slist_prepend (g_thread_free_indeces,
|
||||||
g_slist_prepend (g_thread_free_indeces,
|
GUINT_TO_POINTER (index));
|
||||||
GUINT_TO_POINTER (copied_key.index));
|
|
||||||
G_UNLOCK (g_thread);
|
G_UNLOCK (g_thread);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void g_main_context_destroy (GMainContext *context);
|
||||||
|
|
||||||
static void
|
static void
|
||||||
g_thread_cleanup (gpointer data)
|
g_thread_cleanup (gpointer data)
|
||||||
{
|
{
|
||||||
@ -490,6 +488,9 @@ g_thread_cleanup (gpointer data)
|
|||||||
}
|
}
|
||||||
g_array_free (array, TRUE);
|
g_array_free (array, TRUE);
|
||||||
}
|
}
|
||||||
|
if (thread->context)
|
||||||
|
g_main_context_destroy (thread->context);
|
||||||
|
|
||||||
/* We only free the thread structure, if it isn't joinable. If
|
/* We only free the thread structure, if it isn't joinable. If
|
||||||
it is, the structure is freed in g_thread_join */
|
it is, the structure is freed in g_thread_join */
|
||||||
if (!thread->thread.joinable)
|
if (!thread->thread.joinable)
|
||||||
@ -559,6 +560,7 @@ g_thread_create (GThreadFunc thread_func,
|
|||||||
result->func = thread_func;
|
result->func = thread_func;
|
||||||
result->arg = arg;
|
result->arg = arg;
|
||||||
result->private_data = NULL;
|
result->private_data = NULL;
|
||||||
|
result->context = NULL;
|
||||||
G_LOCK (g_thread);
|
G_LOCK (g_thread);
|
||||||
G_THREAD_UF (thread_create, (g_thread_create_proxy, result,
|
G_THREAD_UF (thread_create, (g_thread_create_proxy, result,
|
||||||
stack_size, joinable, bound, priority,
|
stack_size, joinable, bound, priority,
|
||||||
@ -643,6 +645,7 @@ g_thread_self (void)
|
|||||||
thread->func = NULL;
|
thread->func = NULL;
|
||||||
thread->arg = NULL;
|
thread->arg = NULL;
|
||||||
thread->private_data = NULL;
|
thread->private_data = NULL;
|
||||||
|
thread->context = NULL;
|
||||||
|
|
||||||
if (g_thread_supported ())
|
if (g_thread_supported ())
|
||||||
G_THREAD_UF (thread_self, (&thread->system_thread));
|
G_THREAD_UF (thread_self, (&thread->system_thread));
|
||||||
|
@ -229,12 +229,6 @@ gpointer g_static_private_get (GStaticPrivate *private_key);
|
|||||||
void g_static_private_set (GStaticPrivate *private_key,
|
void g_static_private_set (GStaticPrivate *private_key,
|
||||||
gpointer data,
|
gpointer data,
|
||||||
GDestroyNotify notify);
|
GDestroyNotify notify);
|
||||||
gpointer g_static_private_get_for_thread (GStaticPrivate *private_key,
|
|
||||||
GThread *thread);
|
|
||||||
void g_static_private_set_for_thread (GStaticPrivate *private_key,
|
|
||||||
GThread *thread,
|
|
||||||
gpointer data,
|
|
||||||
GDestroyNotify notify);
|
|
||||||
void g_static_private_free (GStaticPrivate *private_key);
|
void g_static_private_free (GStaticPrivate *private_key);
|
||||||
|
|
||||||
typedef struct _GStaticRecMutex GStaticRecMutex;
|
typedef struct _GStaticRecMutex GStaticRecMutex;
|
||||||
|
Loading…
Reference in New Issue
Block a user