locks: change the ABI just a bit
authorRyan Lortie <desrt@desrt.ca>
Mon, 3 Oct 2011 00:59:15 +0000 (20:59 -0400)
committerRyan Lortie <desrt@desrt.ca>
Mon, 3 Oct 2011 02:33:11 +0000 (22:33 -0400)
Add a little bit more room in the ABI for our synchronisation primatives
since we're going to need it when we add native implementations on
Linux.

Also: rename the pointer field and add /*< private >*/ annotations.

glib/deprecated/gthread.h
glib/gthread-posix.c
glib/gthread-win32.c
glib/gthread.h

index 8e013a8..00e92df 100644 (file)
@@ -123,7 +123,7 @@ typedef GMutex * GStaticMutex;
 #define g_static_mutex_get_mutex g_static_mutex_get_mutex_impl
 #else /* G_OS_WIN32 */
 typedef struct {
-  struct _GMutex *unused;
+  GMutex *unused;
   GMutex mutex;
 } GStaticMutex;
 #define G_STATIC_MUTEX_INIT { NULL, { NULL } }
index dfb2b91..c47fc0d 100644 (file)
@@ -116,14 +116,14 @@ g_mutex_impl_free (pthread_mutex_t *mutex)
 static pthread_mutex_t *
 g_mutex_get_impl (GMutex *mutex)
 {
-  pthread_mutex_t *impl = mutex->impl;
+  pthread_mutex_t *impl = mutex->p;
 
   if G_UNLIKELY (impl == NULL)
     {
       impl = g_mutex_impl_new ();
-      if (!g_atomic_pointer_compare_and_exchange (&mutex->impl, NULL, impl))
+      if (!g_atomic_pointer_compare_and_exchange (&mutex->p, NULL, impl))
         g_mutex_impl_free (impl);
-      impl = mutex->impl;
+      impl = mutex->p;
     }
 
   return impl;
@@ -164,7 +164,7 @@ g_mutex_get_impl (GMutex *mutex)
 void
 g_mutex_init (GMutex *mutex)
 {
-  mutex->impl = g_mutex_impl_new ();
+  mutex->p = g_mutex_impl_new ();
 }
 
 /**
@@ -184,7 +184,7 @@ g_mutex_init (GMutex *mutex)
 void
 g_mutex_clear (GMutex *mutex)
 {
-  g_mutex_impl_free (mutex->impl);
+  g_mutex_impl_free (mutex->p);
 }
 
 /**
@@ -293,14 +293,14 @@ g_rec_mutex_impl_free (pthread_mutex_t *mutex)
 static pthread_mutex_t *
 g_rec_mutex_get_impl (GRecMutex *rec_mutex)
 {
-  pthread_mutex_t *impl = rec_mutex->impl;
+  pthread_mutex_t *impl = rec_mutex->p;
 
   if G_UNLIKELY (impl == NULL)
     {
       impl = g_rec_mutex_impl_new ();
-      if (!g_atomic_pointer_compare_and_exchange (&rec_mutex->impl, NULL, impl))
+      if (!g_atomic_pointer_compare_and_exchange (&rec_mutex->p, NULL, impl))
         g_rec_mutex_impl_free (impl);
-      impl = rec_mutex->impl;
+      impl = rec_mutex->p;
     }
 
   return impl;
@@ -342,7 +342,7 @@ g_rec_mutex_get_impl (GRecMutex *rec_mutex)
 void
 g_rec_mutex_init (GRecMutex *rec_mutex)
 {
-  rec_mutex->impl = g_rec_mutex_impl_new ();
+  rec_mutex->p = g_rec_mutex_impl_new ();
 }
 
 /**
@@ -363,7 +363,7 @@ g_rec_mutex_init (GRecMutex *rec_mutex)
 void
 g_rec_mutex_clear (GRecMutex *rec_mutex)
 {
-  g_rec_mutex_impl_free (rec_mutex->impl);
+  g_rec_mutex_impl_free (rec_mutex->p);
 }
 
 /**
@@ -401,7 +401,7 @@ g_rec_mutex_lock (GRecMutex *mutex)
 void
 g_rec_mutex_unlock (GRecMutex *rec_mutex)
 {
-  pthread_mutex_unlock (rec_mutex->impl);
+  pthread_mutex_unlock (rec_mutex->p);
 }
 
 /**
@@ -453,14 +453,14 @@ g_rw_lock_impl_free (pthread_rwlock_t *rwlock)
 static pthread_rwlock_t *
 g_rw_lock_get_impl (GRWLock *lock)
 {
-  pthread_rwlock_t *impl = lock->impl;
+  pthread_rwlock_t *impl = lock->p;
 
   if G_UNLIKELY (impl == NULL)
     {
       impl = g_rw_lock_impl_new ();
-      if (!g_atomic_pointer_compare_and_exchange (&lock->impl, NULL, impl))
+      if (!g_atomic_pointer_compare_and_exchange (&lock->p, NULL, impl))
         g_rw_lock_impl_free (impl);
-      impl = lock->impl;
+      impl = lock->p;
     }
 
   return impl;
@@ -500,7 +500,7 @@ g_rw_lock_get_impl (GRWLock *lock)
 void
 g_rw_lock_init (GRWLock *rw_lock)
 {
-  rw_lock->impl = g_rw_lock_impl_new ();
+  rw_lock->p = g_rw_lock_impl_new ();
 }
 
 /**
@@ -517,7 +517,7 @@ g_rw_lock_init (GRWLock *rw_lock)
 void
 g_rw_lock_clear (GRWLock *rw_lock)
 {
-  g_rw_lock_impl_free (rw_lock->impl);
+  g_rw_lock_impl_free (rw_lock->p);
 }
 
 /**
@@ -659,14 +659,14 @@ g_cond_impl_free (pthread_cond_t *cond)
 static pthread_cond_t *
 g_cond_get_impl (GCond *cond)
 {
-  pthread_cond_t *impl = cond->impl;
+  pthread_cond_t *impl = cond->p;
 
   if G_UNLIKELY (impl == NULL)
     {
       impl = g_cond_impl_new ();
-      if (!g_atomic_pointer_compare_and_exchange (&cond->impl, NULL, impl))
+      if (!g_atomic_pointer_compare_and_exchange (&cond->p, NULL, impl))
         g_cond_impl_free (impl);
-      impl = cond->impl;
+      impl = cond->p;
     }
 
   return impl;
@@ -694,7 +694,7 @@ g_cond_get_impl (GCond *cond)
 void
 g_cond_init (GCond *cond)
 {
-  cond->impl = g_cond_impl_new ();
+  cond->p = g_cond_impl_new ();
 }
 
 /**
@@ -714,7 +714,7 @@ g_cond_init (GCond *cond)
 void
 g_cond_clear (GCond *cond)
 {
-  g_cond_impl_free (cond->impl);
+  g_cond_impl_free (cond->p);
 }
 
 /**
index 5d6d867..efd0a70 100644 (file)
@@ -173,14 +173,14 @@ g_rec_mutex_impl_free (CRITICAL_SECTION *cs)
 static CRITICAL_SECTION *
 g_rec_mutex_get_impl (GRecMutex *mutex)
 {
-  CRITICAL_SECTION *impl = mutex->impl;
+  CRITICAL_SECTION *impl = mutex->p;
 
-  if G_UNLIKELY (mutex->impl == NULL)
+  if G_UNLIKELY (mutex->p == NULL)
     {
       impl = g_rec_mutex_impl_new ();
-      if (InterlockedCompareExchangePointer (&mutex->impl, impl, NULL) != NULL)
+      if (InterlockedCompareExchangePointer (&mutex->p, impl, NULL) != NULL)
         g_rec_mutex_impl_free (impl);
-      impl = mutex->impl;
+      impl = mutex->p;
     }
 
   return impl;
@@ -189,14 +189,13 @@ g_rec_mutex_get_impl (GRecMutex *mutex)
 void
 g_rec_mutex_init (GRecMutex *mutex)
 {
-  mutex->impl = g_rec_mutex_impl_new ();
+  mutex->p = g_rec_mutex_impl_new ();
 }
 
 void
 g_rec_mutex_clear (GRecMutex *mutex)
 {
-  if (mutex->impl)
-    g_rec_mutex_impl_free (mutex->impl);
+  g_rec_mutex_impl_free (mutex->p);
 }
 
 void
@@ -208,7 +207,7 @@ g_rec_mutex_lock (GRecMutex *mutex)
 void
 g_rec_mutex_unlock (GRecMutex *mutex)
 {
-  LeaveCriticalSection (mutex->impl);
+  LeaveCriticalSection (mutex->p);
 }
 
 gboolean
index 495eaa0..8844cdb 100644 (file)
@@ -52,31 +52,39 @@ typedef gpointer (*GThreadFunc) (gpointer data);
 
 typedef struct _GThread         GThread;
 
-typedef struct _GMutex          GMutex;
+typedef union  _GMutex          GMutex;
 typedef struct _GRecMutex       GRecMutex;
 typedef struct _GRWLock         GRWLock;
 typedef struct _GCond           GCond;
 typedef struct _GPrivate        GPrivate;
 typedef struct _GStaticPrivate  GStaticPrivate;
 
-struct _GMutex
+union _GMutex
 {
-  gpointer impl;
+  /*< private >*/
+  gpointer p;
+  guint i[2];
 };
 
 struct _GRWLock
 {
-  gpointer impl;
+  /*< private >*/
+  gpointer p;
+  guint i[2];
 };
 
 struct _GCond
 {
-  gpointer impl;
+  /*< private >*/
+  gpointer p;
+  guint i[2];
 };
 
 struct _GRecMutex
 {
-  gpointer impl;
+  /*< private >*/
+  gpointer p;
+  guint i[2];
 };
 
 #define G_PRIVATE_INIT(notify) { NULL, (notify), { NULL, NULL } }