static GSList *g_thread_free_indices = NULL;
/* Protects g_thread_all_threads and g_thread_free_indices */
+G_LOCK_DEFINE_STATIC (g_static_mutex);
G_LOCK_DEFINE_STATIC (g_thread);
/* Misc. GThread functions {{{1 */
*
* This function creates a new thread.
*
- * If @joinable is %TRUE, you can wait for this threads termination
- * calling g_thread_join(). Otherwise the thread will just disappear
- * when it terminates.
- *
* The new thread executes the function @func with the argument @data.
* If the thread was created successfully, it is returned.
*
* @error can be %NULL to ignore errors, or non-%NULL to report errors.
* The error is set, if and only if the function returns %NULL.
*
+ * This function returns a reference to the created thread only if
+ * @joinable is %TRUE. In that case, you must free this reference by
+ * calling g_thread_unref() or g_thread_join(). If @joinable is %FALSE
+ * then you should probably not touch the return value.
+ *
* Returns: the new #GThread on success
*
* Deprecated:2.32: Use g_thread_new() instead
gboolean joinable,
GError **error)
{
- return g_thread_new_internal (NULL, g_deprecated_thread_proxy, func, data, joinable, 0, error);
+ return g_thread_create_full (func, data, 0, joinable, 0, 0, error);
}
/**
* This function creates a new thread.
*
* Deprecated:2.32: The @bound and @priority arguments are now ignored.
- * Use g_thread_new() or g_thread_new_full() instead.
+ * Use g_thread_new().
*/
GThread *
g_thread_create_full (GThreadFunc func,
GThreadPriority priority,
GError **error)
{
- return g_thread_new_internal (NULL, g_deprecated_thread_proxy, func, data, joinable, stack_size, error);
-}
+ GThread *thread;
+ thread = g_thread_new_internal (NULL, g_deprecated_thread_proxy,
+ func, data, stack_size, error);
+ if (!joinable)
+ {
+ thread->joinable = FALSE;
+ g_thread_unref (thread);
+ }
+
+ return thread;
+}
/* GOnce {{{1 ------------------------------------------------------------- */
gboolean
if (!result)
{
- g_mutex_lock (&g_once_mutex);
+ G_LOCK (g_static_mutex);
result = mutex->mutex;
if (!result)
g_atomic_pointer_set (&mutex->mutex, result);
}
- g_mutex_unlock (&g_once_mutex);
+ G_UNLOCK (g_static_mutex);
}
return result;
if (!result)
{
- g_mutex_lock (&g_once_mutex);
+ G_LOCK (g_static_mutex);
result = (GRecMutex *) mutex->mutex.mutex;
if (!result)
g_atomic_pointer_set (&mutex->mutex.mutex, result);
}
- g_mutex_unlock (&g_once_mutex);
+ G_UNLOCK (g_static_mutex);
}
return result;