[glib] thread: delegate allocation of GThread to backends
- From: Ryan Lortie <ryanl src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib] thread: delegate allocation of GThread to backends
- Date: Thu, 13 Oct 2011 02:04:47 +0000 (UTC)
commit e064c9bfeca33b59627e7e1ee43d805713fde280
Author: Ryan Lortie <desrt desrt ca>
Date: Wed Oct 12 22:03:14 2011 -0400
thread: delegate allocation of GThread to backends
Add g_system_thread_new() and g_system_thread_free(), implemented with
GSlice. Use those instead of g_new() and g_free().
Presently, the backends are both doing the same thing. This will change
soon.
glib/gthread-posix.c | 12 ++++++++++++
glib/gthread-win32.c | 12 ++++++++++++
glib/gthread.c | 8 ++++----
glib/gthreadprivate.h | 5 +++++
4 files changed, 33 insertions(+), 4 deletions(-)
---
diff --git a/glib/gthread-posix.c b/glib/gthread-posix.c
index 4e103e8..ebeb966 100644
--- a/glib/gthread-posix.c
+++ b/glib/gthread-posix.c
@@ -1069,6 +1069,18 @@ 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,
gpointer arg,
diff --git a/glib/gthread-win32.c b/glib/gthread-win32.c
index fb6ad7c..8d19739 100644
--- a/glib/gthread-win32.c
+++ b/glib/gthread-win32.c
@@ -463,6 +463,18 @@ struct _GThreadData
gboolean joinable;
};
+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_exit (void)
{
diff --git a/glib/gthread.c b/glib/gthread.c
index 18db89f..a9fe4b6 100644
--- a/glib/gthread.c
+++ b/glib/gthread.c
@@ -677,7 +677,7 @@ g_thread_cleanup (gpointer data)
* If it is, the structure is freed in g_thread_join()
*/
if (!thread->thread.joinable)
- g_free (thread);
+ g_system_thread_free (thread);
}
}
@@ -804,7 +804,7 @@ g_thread_new_internal (const gchar *name,
g_return_val_if_fail (func != NULL, NULL);
- result = g_new0 (GRealThread, 1);
+ result = g_system_thread_new ();
result->thread.joinable = joinable;
result->thread.func = func;
@@ -818,7 +818,7 @@ g_thread_new_internal (const gchar *name,
if (local_error)
{
g_propagate_error (error, local_error);
- g_free (result);
+ g_system_thread_free (result);
return NULL;
}
@@ -894,7 +894,7 @@ g_thread_join (GThread *thread)
* thread end. We free the memory here. This will leave a loose end,
* if a joinable thread is not joined.
*/
- g_free (thread);
+ g_system_thread_free (real);
return retval;
}
diff --git a/glib/gthreadprivate.h b/glib/gthreadprivate.h
index 5ade4a3..6109060 100644
--- a/glib/gthreadprivate.h
+++ b/glib/gthreadprivate.h
@@ -32,12 +32,17 @@ G_BEGIN_DECLS
typedef struct _GRealThread GRealThread;
G_GNUC_INTERNAL void g_system_thread_join (gpointer thread);
+
+G_GNUC_INTERNAL
+GRealThread * g_system_thread_new (void);
G_GNUC_INTERNAL void g_system_thread_create (GThreadFunc func,
gpointer data,
gulong stack_size,
gboolean joinable,
gpointer thread,
GError **error);
+G_GNUC_INTERNAL
+void g_system_thread_free (GRealThread *thread);
G_GNUC_INTERNAL void g_system_thread_exit (void);
G_GNUC_INTERNAL void g_system_thread_set_name (const gchar *name);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]