mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-02-25 03:32:12 +01:00
thread creation: Simplify error handling
Instead of always returning non-NULL and finding out about errors via the GError*, return NULL from the backend in the event of an error.
This commit is contained in:
parent
e14a3746db
commit
2f5486f020
@ -1112,7 +1112,8 @@ g_system_thread_new (GThreadFunc thread_func,
|
||||
{
|
||||
g_set_error (error, G_THREAD_ERROR, G_THREAD_ERROR_AGAIN,
|
||||
"Error creating thread: %s", g_strerror (ret));
|
||||
return thread;
|
||||
g_slice_free (GRealThread, thread);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
posix_check_err (ret, "pthread_create");
|
||||
|
@ -518,7 +518,8 @@ g_system_thread_new (GThreadFunc func,
|
||||
"Error creating thread: %s", win_error);
|
||||
g_free (retval);
|
||||
g_free (win_error);
|
||||
return thread;
|
||||
g_slice_free (GRealThread, thread);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
*(GThreadData **) &(thread->system_thread) = retval;
|
||||
|
@ -799,27 +799,22 @@ g_thread_new_internal (const gchar *name,
|
||||
gsize stack_size,
|
||||
GError **error)
|
||||
{
|
||||
GRealThread *result;
|
||||
GError *local_error = NULL;
|
||||
GRealThread *thread;
|
||||
|
||||
g_return_val_if_fail (func != NULL, NULL);
|
||||
|
||||
G_LOCK (g_thread_new);
|
||||
result = g_system_thread_new (proxy, stack_size, joinable, &local_error);
|
||||
result->thread.joinable = joinable;
|
||||
result->thread.func = func;
|
||||
result->thread.data = data;
|
||||
result->name = name;
|
||||
thread = g_system_thread_new (proxy, stack_size, joinable, error);
|
||||
if (thread)
|
||||
{
|
||||
thread->thread.joinable = joinable;
|
||||
thread->thread.func = func;
|
||||
thread->thread.data = data;
|
||||
thread->name = name;
|
||||
}
|
||||
G_UNLOCK (g_thread_new);
|
||||
|
||||
if (local_error)
|
||||
{
|
||||
g_propagate_error (error, local_error);
|
||||
g_system_thread_free (result);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return (GThread*) result;
|
||||
return (GThread*) thread;
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user