[glib/wip/mutexes: 4/6] Port g_mutex_new to use GSlice



commit 85658ad29661b3c395af9aa2555df7e5c3e01543
Author: Ryan Lortie <desrt desrt ca>
Date:   Sat Sep 17 17:59:03 2011 -0400

    Port g_mutex_new to use GSlice
    
    Now that nothing inside of GLib is using g_mutex_new, we can implement
    it using GSlice.  Since the implementations for POSIX and Windows are
    now the same, move it to gthread.c.

 glib/gthread-posix.c |   21 ---------------------
 glib/gthread-win32.c |   21 ---------------------
 glib/gthread.c       |   18 ++++++++++++++++++
 3 files changed, 18 insertions(+), 42 deletions(-)
---
diff --git a/glib/gthread-posix.c b/glib/gthread-posix.c
index 1fcc3dd..53ee362 100644
--- a/glib/gthread-posix.c
+++ b/glib/gthread-posix.c
@@ -225,27 +225,6 @@ g_cond_timedwait (GCond  *cond,
 
 /* {{{1 new/free API */
 
-GMutex *
-g_mutex_new (void)
-{
-  GMutex *mutex;
-
-  /* malloc() is temporary until all libglib users are ported away */
-  mutex = malloc (sizeof (GMutex));
-  if G_UNLIKELY (mutex == NULL)
-    g_thread_abort (errno, "malloc");
-  g_mutex_init (mutex);
-
-  return mutex;
-}
-
-void
-g_mutex_free (GMutex *mutex)
-{
-  g_mutex_clear (mutex);
-  free (mutex);
-}
-
 GCond *
 g_cond_new (void)
 {
diff --git a/glib/gthread-win32.c b/glib/gthread-win32.c
index a880e10..91510c5 100644
--- a/glib/gthread-win32.c
+++ b/glib/gthread-win32.c
@@ -253,27 +253,6 @@ g_cond_timed_wait (GCond    *cond,
 }
 
 /* {{{1 new/free API */
-GMutex *
-g_mutex_new (void)
-{
-  GMutex *mutex;
-
-  /* malloc() is temporary until all libglib users are ported away */
-  mutex = malloc (sizeof (GMutex));
-  if G_UNLIKELY (mutex == NULL)
-    g_thread_abort (errno, "malloc");
-  g_mutex_init (mutex);
-
-  return mutex;
-}
-
-void
-g_mutex_free (GMutex *mutex)
-{
-  g_mutex_clear (mutex);
-  free (mutex);
-}
-
 GCond *
 g_cond_new (void)
 {
diff --git a/glib/gthread.c b/glib/gthread.c
index 2328ae0..e5caf9d 100644
--- a/glib/gthread.c
+++ b/glib/gthread.c
@@ -2575,3 +2575,21 @@ g_thread_get_initialized ()
 {
   return g_thread_supported ();
 }
+
+GMutex *
+g_mutex_new (void)
+{
+  GMutex *mutex;
+
+  mutex = g_slice_new (GMutex);
+  g_mutex_init (mutex);
+
+  return mutex;
+}
+
+void
+g_mutex_free (GMutex *mutex)
+{
+  g_mutex_clear (mutex);
+  g_slice_free (GMutex, mutex);
+}



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]