Combine g_sytem_thread_{new,create}()

This commit is contained in:
Ryan Lortie 2011-10-12 22:29:13 -04:00
parent a3f82c847f
commit e14a3746db
4 changed files with 29 additions and 43 deletions

View File

@ -1069,29 +1069,23 @@ g_private_replace (GPrivate *key,
#define posix_check_cmd(cmd) posix_check_err (cmd, #cmd)
GRealThread *
g_system_thread_new (void)
{
return g_slice_new0 (GRealThread);
}
void
g_system_thread_free (GRealThread *thread)
{
g_slice_free (GRealThread, thread);
}
void
g_system_thread_create (GThreadFunc thread_func,
gulong stack_size,
gboolean joinable,
GRealThread *thread,
GError **error)
GRealThread *
g_system_thread_new (GThreadFunc thread_func,
gulong stack_size,
gboolean joinable,
GError **error)
{
GRealThread *thread;
pthread_attr_t attr;
gint ret;
g_return_if_fail (thread_func);
thread = g_slice_new0 (GRealThread);
posix_check_cmd (pthread_attr_init (&attr));
@ -1118,10 +1112,12 @@ g_system_thread_create (GThreadFunc thread_func,
{
g_set_error (error, G_THREAD_ERROR, G_THREAD_ERROR_AGAIN,
"Error creating thread: %s", g_strerror (ret));
return;
return thread;
}
posix_check_err (ret, "pthread_create");
return thread;
}
/**

View File

@ -463,12 +463,6 @@ struct _GThreadData
gboolean joinable;
};
GRealThread *
g_system_thread_new (void)
{
return g_slice_new0 (GRealThread);
}
void
g_system_thread_free (GRealThread *thread)
{
@ -497,18 +491,17 @@ g_thread_proxy (gpointer data)
return 0;
}
void
g_system_thread_create (GThreadFunc func,
gulong stack_size,
gboolean joinable,
GRealThread *thread,
GError **error)
GRealThread *
g_system_thread_new (GThreadFunc func,
gulong stack_size,
gboolean joinable,
GError **error)
{
GRealThread *thread;
guint ignore;
GThreadData *retval;
g_return_if_fail (func);
thread = g_slice_new0 (GRealThread);
retval = g_new(GThreadData, 1);
retval->func = func;
retval->data = thread;
@ -525,10 +518,12 @@ g_system_thread_create (GThreadFunc func,
"Error creating thread: %s", win_error);
g_free (retval);
g_free (win_error);
return;
return thread;
}
*(GThreadData **) &(thread->system_thread) = retval;
return thread;
}
void

View File

@ -694,8 +694,8 @@ g_thread_proxy (gpointer data)
/* This has to happen before G_LOCK, as that might call g_thread_self */
g_private_set (&g_thread_specific_private, data);
/* The lock makes sure that thread->system_thread is written,
* before thread->thread.func is called. See g_thread_new_internal().
/* The lock makes sure that g_thread_new_internal() has a chance to
* setup 'func' and 'data' before we make the call.
*/
G_LOCK (g_thread_new);
G_UNLOCK (g_thread_new);
@ -804,15 +804,12 @@ g_thread_new_internal (const gchar *name,
g_return_val_if_fail (func != NULL, NULL);
result = g_system_thread_new ();
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_LOCK (g_thread_new);
g_system_thread_create (proxy, stack_size, joinable,
result, &local_error);
G_UNLOCK (g_thread_new);
if (local_error)

View File

@ -32,15 +32,13 @@ G_BEGIN_DECLS
typedef struct _GRealThread GRealThread;
G_GNUC_INTERNAL
void g_system_thread_wait (GRealThread *thread);
void g_system_thread_wait (GRealThread *thread);
G_GNUC_INTERNAL
GRealThread * g_system_thread_new (void);
G_GNUC_INTERNAL void g_system_thread_create (GThreadFunc func,
gulong stack_size,
gboolean joinable,
GRealThread *thread,
GError **error);
GRealThread * g_system_thread_new (GThreadFunc func,
gulong stack_size,
gboolean joinable,
GError **error);
G_GNUC_INTERNAL
void g_system_thread_free (GRealThread *thread);