mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-03-15 04:05:11 +01:00
Combine g_sytem_thread_{new,create}()
This commit is contained in:
parent
a3f82c847f
commit
e14a3746db
@ -1069,29 +1069,23 @@ g_private_replace (GPrivate *key,
|
|||||||
|
|
||||||
#define posix_check_cmd(cmd) posix_check_err (cmd, #cmd)
|
#define posix_check_cmd(cmd) posix_check_err (cmd, #cmd)
|
||||||
|
|
||||||
GRealThread *
|
|
||||||
g_system_thread_new (void)
|
|
||||||
{
|
|
||||||
return g_slice_new0 (GRealThread);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void
|
||||||
g_system_thread_free (GRealThread *thread)
|
g_system_thread_free (GRealThread *thread)
|
||||||
{
|
{
|
||||||
g_slice_free (GRealThread, thread);
|
g_slice_free (GRealThread, thread);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
GRealThread *
|
||||||
g_system_thread_create (GThreadFunc thread_func,
|
g_system_thread_new (GThreadFunc thread_func,
|
||||||
gulong stack_size,
|
gulong stack_size,
|
||||||
gboolean joinable,
|
gboolean joinable,
|
||||||
GRealThread *thread,
|
GError **error)
|
||||||
GError **error)
|
|
||||||
{
|
{
|
||||||
|
GRealThread *thread;
|
||||||
pthread_attr_t attr;
|
pthread_attr_t attr;
|
||||||
gint ret;
|
gint ret;
|
||||||
|
|
||||||
g_return_if_fail (thread_func);
|
thread = g_slice_new0 (GRealThread);
|
||||||
|
|
||||||
posix_check_cmd (pthread_attr_init (&attr));
|
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,
|
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;
|
return thread;
|
||||||
}
|
}
|
||||||
|
|
||||||
posix_check_err (ret, "pthread_create");
|
posix_check_err (ret, "pthread_create");
|
||||||
|
|
||||||
|
return thread;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -463,12 +463,6 @@ struct _GThreadData
|
|||||||
gboolean joinable;
|
gboolean joinable;
|
||||||
};
|
};
|
||||||
|
|
||||||
GRealThread *
|
|
||||||
g_system_thread_new (void)
|
|
||||||
{
|
|
||||||
return g_slice_new0 (GRealThread);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void
|
||||||
g_system_thread_free (GRealThread *thread)
|
g_system_thread_free (GRealThread *thread)
|
||||||
{
|
{
|
||||||
@ -497,18 +491,17 @@ g_thread_proxy (gpointer data)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
GRealThread *
|
||||||
g_system_thread_create (GThreadFunc func,
|
g_system_thread_new (GThreadFunc func,
|
||||||
gulong stack_size,
|
gulong stack_size,
|
||||||
gboolean joinable,
|
gboolean joinable,
|
||||||
GRealThread *thread,
|
GError **error)
|
||||||
GError **error)
|
|
||||||
{
|
{
|
||||||
|
GRealThread *thread;
|
||||||
guint ignore;
|
guint ignore;
|
||||||
GThreadData *retval;
|
GThreadData *retval;
|
||||||
|
|
||||||
g_return_if_fail (func);
|
thread = g_slice_new0 (GRealThread);
|
||||||
|
|
||||||
retval = g_new(GThreadData, 1);
|
retval = g_new(GThreadData, 1);
|
||||||
retval->func = func;
|
retval->func = func;
|
||||||
retval->data = thread;
|
retval->data = thread;
|
||||||
@ -525,10 +518,12 @@ g_system_thread_create (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;
|
return thread;
|
||||||
}
|
}
|
||||||
|
|
||||||
*(GThreadData **) &(thread->system_thread) = retval;
|
*(GThreadData **) &(thread->system_thread) = retval;
|
||||||
|
|
||||||
|
return thread;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -694,8 +694,8 @@ g_thread_proxy (gpointer data)
|
|||||||
/* This has to happen before G_LOCK, as that might call g_thread_self */
|
/* This has to happen before G_LOCK, as that might call g_thread_self */
|
||||||
g_private_set (&g_thread_specific_private, data);
|
g_private_set (&g_thread_specific_private, data);
|
||||||
|
|
||||||
/* The lock makes sure that thread->system_thread is written,
|
/* The lock makes sure that g_thread_new_internal() has a chance to
|
||||||
* before thread->thread.func is called. See g_thread_new_internal().
|
* setup 'func' and 'data' before we make the call.
|
||||||
*/
|
*/
|
||||||
G_LOCK (g_thread_new);
|
G_LOCK (g_thread_new);
|
||||||
G_UNLOCK (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);
|
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.joinable = joinable;
|
||||||
result->thread.func = func;
|
result->thread.func = func;
|
||||||
result->thread.data = data;
|
result->thread.data = data;
|
||||||
result->name = name;
|
result->name = name;
|
||||||
G_LOCK (g_thread_new);
|
|
||||||
g_system_thread_create (proxy, stack_size, joinable,
|
|
||||||
result, &local_error);
|
|
||||||
G_UNLOCK (g_thread_new);
|
G_UNLOCK (g_thread_new);
|
||||||
|
|
||||||
if (local_error)
|
if (local_error)
|
||||||
|
@ -32,15 +32,13 @@ G_BEGIN_DECLS
|
|||||||
typedef struct _GRealThread GRealThread;
|
typedef struct _GRealThread GRealThread;
|
||||||
|
|
||||||
G_GNUC_INTERNAL
|
G_GNUC_INTERNAL
|
||||||
void g_system_thread_wait (GRealThread *thread);
|
void g_system_thread_wait (GRealThread *thread);
|
||||||
|
|
||||||
G_GNUC_INTERNAL
|
G_GNUC_INTERNAL
|
||||||
GRealThread * g_system_thread_new (void);
|
GRealThread * g_system_thread_new (GThreadFunc func,
|
||||||
G_GNUC_INTERNAL void g_system_thread_create (GThreadFunc func,
|
gulong stack_size,
|
||||||
gulong stack_size,
|
gboolean joinable,
|
||||||
gboolean joinable,
|
GError **error);
|
||||||
GRealThread *thread,
|
|
||||||
GError **error);
|
|
||||||
G_GNUC_INTERNAL
|
G_GNUC_INTERNAL
|
||||||
void g_system_thread_free (GRealThread *thread);
|
void g_system_thread_free (GRealThread *thread);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user