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:
Ryan Lortie 2011-10-12 22:35:35 -04:00
parent e14a3746db
commit 2f5486f020
3 changed files with 15 additions and 18 deletions

View File

@ -1112,7 +1112,8 @@ g_system_thread_new (GThreadFunc thread_func,
{ {
g_set_error (error, G_THREAD_ERROR, G_THREAD_ERROR_AGAIN, g_set_error (error, G_THREAD_ERROR, G_THREAD_ERROR_AGAIN,
"Error creating thread: %s", g_strerror (ret)); "Error creating thread: %s", g_strerror (ret));
return thread; g_slice_free (GRealThread, thread);
return NULL;
} }
posix_check_err (ret, "pthread_create"); posix_check_err (ret, "pthread_create");

View File

@ -518,7 +518,8 @@ g_system_thread_new (GThreadFunc func,
"Error creating thread: %s", win_error); "Error creating thread: %s", win_error);
g_free (retval); g_free (retval);
g_free (win_error); g_free (win_error);
return thread; g_slice_free (GRealThread, thread);
return NULL;
} }
*(GThreadData **) &(thread->system_thread) = retval; *(GThreadData **) &(thread->system_thread) = retval;

View File

@ -799,27 +799,22 @@ g_thread_new_internal (const gchar *name,
gsize stack_size, gsize stack_size,
GError **error) GError **error)
{ {
GRealThread *result; GRealThread *thread;
GError *local_error = NULL;
g_return_val_if_fail (func != NULL, NULL); g_return_val_if_fail (func != NULL, NULL);
G_LOCK (g_thread_new); G_LOCK (g_thread_new);
result = g_system_thread_new (proxy, stack_size, joinable, &local_error); thread = g_system_thread_new (proxy, stack_size, joinable, error);
result->thread.joinable = joinable; if (thread)
result->thread.func = func; {
result->thread.data = data; thread->thread.joinable = joinable;
result->name = name; thread->thread.func = func;
thread->thread.data = data;
thread->name = name;
}
G_UNLOCK (g_thread_new); G_UNLOCK (g_thread_new);
if (local_error) return (GThread*) thread;
{
g_propagate_error (error, local_error);
g_system_thread_free (result);
return NULL;
}
return (GThread*) result;
} }
/** /**