mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-03-30 20:33:08 +02:00
posix threads: joinable tweaks
Make the POSIX backend a little bit more like the win32 one in terms of how we deal with joinability. Calling g_system_thread_join() is now optional, and g_system_thread_wait() can be safely called by multiple threads. There is no longer any internal concept of joinability.
This commit is contained in:
parent
f970dfc734
commit
dbf20d585f
@ -1074,6 +1074,8 @@ typedef struct
|
|||||||
GRealThread thread;
|
GRealThread thread;
|
||||||
|
|
||||||
pthread_t system_thread;
|
pthread_t system_thread;
|
||||||
|
gboolean joined;
|
||||||
|
GMutex lock;
|
||||||
} GThreadPosix;
|
} GThreadPosix;
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -1081,6 +1083,11 @@ g_system_thread_free (GRealThread *thread)
|
|||||||
{
|
{
|
||||||
GThreadPosix *pt = (GThreadPosix *) thread;
|
GThreadPosix *pt = (GThreadPosix *) thread;
|
||||||
|
|
||||||
|
if (!pt->joined)
|
||||||
|
pthread_detach (pt->system_thread);
|
||||||
|
|
||||||
|
g_mutex_clear (&pt->lock);
|
||||||
|
|
||||||
g_slice_free (GThreadPosix, pt);
|
g_slice_free (GThreadPosix, pt);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1110,9 +1117,6 @@ g_system_thread_new (GThreadFunc thread_func,
|
|||||||
}
|
}
|
||||||
#endif /* HAVE_PTHREAD_ATTR_SETSTACKSIZE */
|
#endif /* HAVE_PTHREAD_ATTR_SETSTACKSIZE */
|
||||||
|
|
||||||
posix_check_cmd (pthread_attr_setdetachstate (&attr,
|
|
||||||
joinable ? PTHREAD_CREATE_JOINABLE : PTHREAD_CREATE_DETACHED));
|
|
||||||
|
|
||||||
ret = pthread_create (&thread->system_thread, &attr, (void* (*)(void*))thread_func, thread);
|
ret = pthread_create (&thread->system_thread, &attr, (void* (*)(void*))thread_func, thread);
|
||||||
|
|
||||||
posix_check_cmd (pthread_attr_destroy (&attr));
|
posix_check_cmd (pthread_attr_destroy (&attr));
|
||||||
@ -1127,6 +1131,8 @@ g_system_thread_new (GThreadFunc thread_func,
|
|||||||
|
|
||||||
posix_check_err (ret, "pthread_create");
|
posix_check_err (ret, "pthread_create");
|
||||||
|
|
||||||
|
g_mutex_init (&thread->lock);
|
||||||
|
|
||||||
return (GRealThread *) thread;
|
return (GRealThread *) thread;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1148,8 +1154,16 @@ void
|
|||||||
g_system_thread_wait (GRealThread *thread)
|
g_system_thread_wait (GRealThread *thread)
|
||||||
{
|
{
|
||||||
GThreadPosix *pt = (GThreadPosix *) thread;
|
GThreadPosix *pt = (GThreadPosix *) thread;
|
||||||
gpointer ignore;
|
|
||||||
posix_check_cmd (pthread_join (pt->system_thread, &ignore));
|
g_mutex_lock (&pt->lock);
|
||||||
|
|
||||||
|
if (!pt->joined)
|
||||||
|
{
|
||||||
|
posix_check_cmd (pthread_join (pt->system_thread, NULL));
|
||||||
|
pt->joined = TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
g_mutex_unlock (&pt->lock);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
Loading…
x
Reference in New Issue
Block a user