mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-01-11 23:16:14 +01:00
Add new thread creation API
Deprecate both g_thread_create functions and add g_thread_new() and g_thread_new_full(). The new functions expect a name for the thread. Change GThreadPool, GMainContext and GDBus to create named threads. https://bugzilla.gnome.org/show_bug.cgi?id=660635
This commit is contained in:
parent
bc67c23bf9
commit
0d1a92ca3d
@ -302,10 +302,11 @@ _g_dbus_shared_thread_ref (void)
|
||||
|
||||
data->context = g_main_context_new ();
|
||||
data->loop = g_main_loop_new (data->context, FALSE);
|
||||
data->thread = g_thread_create (gdbus_shared_thread_func,
|
||||
data,
|
||||
TRUE,
|
||||
&error);
|
||||
data->thread = g_thread_new ("gdbus",
|
||||
gdbus_shared_thread_func,
|
||||
data,
|
||||
TRUE,
|
||||
&error);
|
||||
g_assert_no_error (error);
|
||||
/* We can cast between gsize and gpointer safely */
|
||||
g_once_init_leave (&shared_thread_data, (gsize) data);
|
||||
|
@ -126,6 +126,38 @@ g_thread_set_priority (GThread *thread,
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* g_thread_create:
|
||||
* @func: a function to execute in the new thread
|
||||
* @data: an argument to supply to the new thread
|
||||
* @joinable: should this thread be joinable?
|
||||
* @error: return location for error, or %NULL
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* Returns: the new #GThread on success
|
||||
*
|
||||
* Deprecated:2.32: Use g_thread_new() instead
|
||||
*/
|
||||
GThread *
|
||||
g_thread_create (GThreadFunc func,
|
||||
gpointer data,
|
||||
gboolean joinable,
|
||||
GError **error)
|
||||
{
|
||||
return g_thread_new_full (NULL, func, data, joinable, 0, error);
|
||||
}
|
||||
|
||||
/**
|
||||
* g_thread_create_full:
|
||||
* @func: a function to execute in the new thread.
|
||||
@ -140,7 +172,7 @@ g_thread_set_priority (GThread *thread,
|
||||
* This function creates a new thread.
|
||||
*
|
||||
* Deprecated:2.32: The @bound and @priority arguments are now ignored.
|
||||
* Use g_thread_create() or g_thread_create_with_stack_size() instead.
|
||||
* Use g_thread_new() or g_thread_new_full() instead.
|
||||
*/
|
||||
GThread *
|
||||
g_thread_create_full (GThreadFunc func,
|
||||
@ -151,7 +183,7 @@ g_thread_create_full (GThreadFunc func,
|
||||
GThreadPriority priority,
|
||||
GError **error)
|
||||
{
|
||||
return g_thread_create_with_stack_size (func, data, joinable, stack_size, error);
|
||||
return g_thread_new_full (NULL, func, data, joinable, stack_size, error);
|
||||
}
|
||||
|
||||
/* GStaticMutex {{{1 ------------------------------------------------------ */
|
||||
|
@ -99,6 +99,10 @@ GLIB_VAR guint64 (*g_thread_gettime) (void);
|
||||
/* internal function for fallback static mutex implementation */
|
||||
GMutex* g_static_mutex_get_mutex_impl (GMutex **mutex);
|
||||
|
||||
GThread* g_thread_create (GThreadFunc func,
|
||||
gpointer data,
|
||||
gboolean joinable,
|
||||
GError **error);
|
||||
GThread* g_thread_create_full (GThreadFunc func,
|
||||
gpointer data,
|
||||
gulong stack_size,
|
||||
|
@ -1087,20 +1087,21 @@ g_pointer_bit_unlock
|
||||
g_once_impl
|
||||
g_once_init_enter_impl
|
||||
g_once_init_leave
|
||||
g_thread_init_glib
|
||||
g_once_init_enter
|
||||
g_thread_functions_for_glib_use
|
||||
g_threads_got_initialized
|
||||
g_thread_use_default_impl
|
||||
g_thread_gettime
|
||||
g_thread_create
|
||||
g_thread_create_with_stack_size
|
||||
g_thread_create_full
|
||||
g_thread_error_quark
|
||||
g_thread_exit
|
||||
g_thread_functions_for_glib_use
|
||||
g_thread_init_glib
|
||||
g_thread_join
|
||||
g_thread_new
|
||||
g_thread_new_full
|
||||
g_thread_self
|
||||
g_thread_set_priority
|
||||
g_thread_use_default_impl
|
||||
g_thread_yield
|
||||
g_static_mutex_free
|
||||
g_static_mutex_get_mutex_impl
|
||||
|
@ -4757,7 +4757,7 @@ g_get_worker_context (void)
|
||||
GError *error = NULL;
|
||||
|
||||
glib_worker_context = g_main_context_new ();
|
||||
if (g_thread_create (glib_worker_main, NULL, FALSE, &error) == NULL)
|
||||
if (g_thread_new ("gmain", glib_worker_main, NULL, FALSE, &error) == NULL)
|
||||
g_error ("Creating GLib worker thread failed: %s\n", error->message);
|
||||
|
||||
g_once_init_leave (&initialised, TRUE);
|
||||
|
@ -584,6 +584,7 @@ struct _GRealThread
|
||||
GThread thread;
|
||||
GArray *private_data;
|
||||
GRealThread *next;
|
||||
const gchar *name;
|
||||
gpointer retval;
|
||||
GSystemThread system_thread;
|
||||
};
|
||||
@ -1116,7 +1117,6 @@ g_thread_cleanup (gpointer data)
|
||||
}
|
||||
}
|
||||
G_UNLOCK (g_thread);
|
||||
|
||||
/* Just to make sure, this isn't used any more */
|
||||
g_system_thread_assign (thread->system_thread, zero_thread);
|
||||
g_free (thread);
|
||||
@ -1146,14 +1146,19 @@ g_thread_create_proxy (gpointer data)
|
||||
}
|
||||
|
||||
/**
|
||||
* g_thread_create:
|
||||
* g_thread_new:
|
||||
* @name: a name for the new thread
|
||||
* @func: a function to execute in the new thread
|
||||
* @data: an argument to supply to the new thread
|
||||
* @joinable: should this thread be joinable?
|
||||
* @error: return location for error, or %NULL
|
||||
* @error: return location for error
|
||||
*
|
||||
* This function creates a new thread.
|
||||
*
|
||||
* The @name can be useful for discriminating threads in
|
||||
* a debugger. Some systems restrict the length of @name to
|
||||
* 16 bytes.
|
||||
*
|
||||
* If @joinable is %TRUE, you can wait for this threads termination
|
||||
* calling g_thread_join(). Otherwise the thread will just disappear
|
||||
* when it terminates.
|
||||
@ -1165,28 +1170,37 @@ g_thread_create_proxy (gpointer data)
|
||||
* The error is set, if and only if the function returns %NULL.
|
||||
*
|
||||
* Returns: the new #GThread on success
|
||||
*
|
||||
* Since: 2.32
|
||||
*/
|
||||
GThread *
|
||||
g_thread_create (GThreadFunc func,
|
||||
gpointer data,
|
||||
gboolean joinable,
|
||||
GError **error)
|
||||
g_thread_new (const gchar *name,
|
||||
GThreadFunc func,
|
||||
gpointer data,
|
||||
gboolean joinable,
|
||||
GError **error)
|
||||
{
|
||||
return g_thread_create_with_stack_size (func, data, joinable, 0, error);
|
||||
return g_thread_new_full (name, func, data, joinable, 0, error);
|
||||
}
|
||||
|
||||
/**
|
||||
* g_thread_create_with_stack_size:
|
||||
* g_thread_new_full:
|
||||
* @name: a name for the new thread
|
||||
* @func: a function to execute in the new thread
|
||||
* @data: an argument to supply to the new thread
|
||||
* @joinable: should this thread be joinable?
|
||||
* @stack_size: a stack size for the new thread
|
||||
* @error: return location for error
|
||||
*
|
||||
* This function creates a new thread. If the underlying thread
|
||||
* implementation supports it, the thread gets a stack size of
|
||||
* @stack_size or the default value for the current platform, if
|
||||
* @stack_size is 0.
|
||||
* This function creates a new thread.
|
||||
*
|
||||
* The @name can be useful for discriminating threads in
|
||||
* a debugger. Some systems restrict the length of @name to
|
||||
* 16 bytes.
|
||||
*
|
||||
* If the underlying thread implementation supports it, the thread
|
||||
* gets a stack size of @stack_size or the default value for the
|
||||
* current platform, if @stack_size is 0.
|
||||
*
|
||||
* If @joinable is %TRUE, you can wait for this threads termination
|
||||
* calling g_thread_join(). Otherwise the thread will just disappear
|
||||
@ -1198,8 +1212,8 @@ g_thread_create (GThreadFunc func,
|
||||
* @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.
|
||||
*
|
||||
* <note><para>Only use g_thread_create_with_stack_size() if you
|
||||
* really can't use g_thread_create() instead. g_thread_create()
|
||||
* <note><para>Only use a non-zero @stack_size if you
|
||||
* really can't use the default instead. g_thread_new()
|
||||
* does not take @stack_size, as it should only be used in cases
|
||||
* in which it is unavoidable.</para></note>
|
||||
*
|
||||
@ -1207,12 +1221,13 @@ g_thread_create (GThreadFunc func,
|
||||
*
|
||||
* Since: 2.32
|
||||
*/
|
||||
GThread*
|
||||
g_thread_create_with_stack_size (GThreadFunc func,
|
||||
gpointer data,
|
||||
gboolean joinable,
|
||||
gsize stack_size,
|
||||
GError **error)
|
||||
GThread *
|
||||
g_thread_new_full (const gchar *name,
|
||||
GThreadFunc func,
|
||||
gpointer data,
|
||||
gboolean joinable,
|
||||
gsize stack_size,
|
||||
GError **error)
|
||||
{
|
||||
GRealThread* result;
|
||||
GError *local_error = NULL;
|
||||
@ -1224,6 +1239,7 @@ g_thread_create_with_stack_size (GThreadFunc func,
|
||||
result->thread.func = func;
|
||||
result->thread.data = data;
|
||||
result->private_data = NULL;
|
||||
result->name = name;
|
||||
G_LOCK (g_thread);
|
||||
g_system_thread_create (g_thread_create_proxy, result,
|
||||
stack_size, joinable,
|
||||
@ -1316,7 +1332,6 @@ g_thread_join (GThread* thread)
|
||||
}
|
||||
}
|
||||
G_UNLOCK (g_thread);
|
||||
|
||||
/* Just to make sure, this isn't used any more */
|
||||
thread->joinable = 0;
|
||||
g_system_thread_assign (real->system_thread, zero_thread);
|
||||
|
@ -134,12 +134,14 @@ GLIB_VAR gboolean g_threads_got_initialized;
|
||||
|
||||
GMutex* g_static_mutex_get_mutex_impl (GMutex **mutex);
|
||||
|
||||
GThread *g_thread_create (GThreadFunc func,
|
||||
GThread *g_thread_new (const gchar *name,
|
||||
GThreadFunc func,
|
||||
gpointer data,
|
||||
gboolean joinable,
|
||||
GError **error);
|
||||
|
||||
GThread *g_thread_create_with_stack_size (GThreadFunc func,
|
||||
GThread *g_thread_new_full (const gchar *name,
|
||||
GThreadFunc func,
|
||||
gpointer data,
|
||||
gboolean joinable,
|
||||
gsize stack_size,
|
||||
|
@ -414,7 +414,7 @@ g_thread_pool_start_thread (GRealThreadPool *pool,
|
||||
GError *local_error = NULL;
|
||||
|
||||
/* No thread was found, we have to start a new one */
|
||||
if (!g_thread_create (g_thread_pool_thread_proxy, pool, FALSE, &local_error))
|
||||
if (!g_thread_new ("pool", g_thread_pool_thread_proxy, pool, FALSE, &local_error))
|
||||
{
|
||||
g_propagate_error (error, local_error);
|
||||
return FALSE;
|
||||
|
Loading…
Reference in New Issue
Block a user