mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-02-09 12:25:48 +01:00
Only g_system_thread_free() our own threads
Keep track of if we created a thread for ourselves or if the GThread* was allocated in response to g_thread_self() on a previously-unknown thread. Only call g_system_thread_free() in the first case.
This commit is contained in:
parent
a5800ef336
commit
dfd466979b
@ -677,7 +677,12 @@ g_thread_cleanup (gpointer data)
|
|||||||
* If it is, the structure is freed in g_thread_join()
|
* If it is, the structure is freed in g_thread_join()
|
||||||
*/
|
*/
|
||||||
if (!thread->thread.joinable)
|
if (!thread->thread.joinable)
|
||||||
g_system_thread_free (thread);
|
{
|
||||||
|
if (thread->ours)
|
||||||
|
g_system_thread_free (thread);
|
||||||
|
else
|
||||||
|
g_slice_free (GRealThread, thread);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -807,6 +812,7 @@ g_thread_new_internal (const gchar *name,
|
|||||||
thread = g_system_thread_new (proxy, stack_size, joinable, error);
|
thread = g_system_thread_new (proxy, stack_size, joinable, error);
|
||||||
if (thread)
|
if (thread)
|
||||||
{
|
{
|
||||||
|
thread->ours = TRUE;
|
||||||
thread->thread.joinable = joinable;
|
thread->thread.joinable = joinable;
|
||||||
thread->thread.func = func;
|
thread->thread.func = func;
|
||||||
thread->thread.data = data;
|
thread->thread.data = data;
|
||||||
@ -886,7 +892,10 @@ g_thread_join (GThread *thread)
|
|||||||
* thread end. We free the memory here. This will leave a loose end,
|
* thread end. We free the memory here. This will leave a loose end,
|
||||||
* if a joinable thread is not joined.
|
* if a joinable thread is not joined.
|
||||||
*/
|
*/
|
||||||
g_system_thread_free (real);
|
if (real->ours)
|
||||||
|
g_system_thread_free (real);
|
||||||
|
else
|
||||||
|
g_slice_free (GRealThread, real);
|
||||||
|
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
@ -910,15 +919,11 @@ g_thread_self (void)
|
|||||||
* This can happen for the main thread and for threads
|
* This can happen for the main thread and for threads
|
||||||
* that are not created by GLib.
|
* that are not created by GLib.
|
||||||
*/
|
*/
|
||||||
thread = g_new0 (GRealThread, 1);
|
thread = g_slice_new0 (GRealThread);
|
||||||
thread->thread.joinable = FALSE; /* This is a safe guess */
|
|
||||||
thread->thread.func = NULL;
|
|
||||||
thread->thread.data = NULL;
|
|
||||||
|
|
||||||
g_private_set (&g_thread_specific_private, thread);
|
g_private_set (&g_thread_specific_private, thread);
|
||||||
}
|
}
|
||||||
|
|
||||||
return (GThread*)thread;
|
return (GThread*) thread;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Epilogue {{{1 */
|
/* Epilogue {{{1 */
|
||||||
|
@ -59,6 +59,8 @@ gpointer g_thread_proxy (gpointer thread);
|
|||||||
struct _GRealThread
|
struct _GRealThread
|
||||||
{
|
{
|
||||||
GThread thread;
|
GThread thread;
|
||||||
|
|
||||||
|
gboolean ours;
|
||||||
const gchar *name;
|
const gchar *name;
|
||||||
gpointer retval;
|
gpointer retval;
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user