[glib] thread creation: Simplify error handling
- From: Ryan Lortie <ryanl src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib] thread creation: Simplify error handling
- Date: Thu, 13 Oct 2011 02:43:56 +0000 (UTC)
commit 2f5486f02040b0d5cfc67eb97bd037a0ffd86635
Author: Ryan Lortie <desrt desrt ca>
Date: Wed Oct 12 22:35:35 2011 -0400
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.
glib/gthread-posix.c | 5 +++--
glib/gthread-win32.c | 3 ++-
glib/gthread.c | 23 +++++++++--------------
3 files changed, 14 insertions(+), 17 deletions(-)
---
diff --git a/glib/gthread-posix.c b/glib/gthread-posix.c
index f640c00..4d971e8 100644
--- a/glib/gthread-posix.c
+++ b/glib/gthread-posix.c
@@ -1111,8 +1111,9 @@ g_system_thread_new (GThreadFunc thread_func,
if (ret == EAGAIN)
{
g_set_error (error, G_THREAD_ERROR, G_THREAD_ERROR_AGAIN,
- "Error creating thread: %s", g_strerror (ret));
- return thread;
+ "Error creating thread: %s", g_strerror (ret));
+ g_slice_free (GRealThread, thread);
+ return NULL;
}
posix_check_err (ret, "pthread_create");
diff --git a/glib/gthread-win32.c b/glib/gthread-win32.c
index e380b84..2babc92 100644
--- a/glib/gthread-win32.c
+++ b/glib/gthread-win32.c
@@ -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;
diff --git a/glib/gthread.c b/glib/gthread.c
index e259bad..7896df8 100644
--- a/glib/gthread.c
+++ b/glib/gthread.c
@@ -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;
- G_UNLOCK (g_thread_new);
-
- if (local_error)
+ thread = g_system_thread_new (proxy, stack_size, joinable, error);
+ if (thread)
{
- g_propagate_error (error, local_error);
- g_system_thread_free (result);
- return NULL;
+ thread->thread.joinable = joinable;
+ thread->thread.func = func;
+ thread->thread.data = data;
+ thread->name = name;
}
+ G_UNLOCK (g_thread_new);
- return (GThread*) result;
+ return (GThread*) thread;
}
/**
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]