locks: change the ABI just a bit

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.
This commit is contained in:
Ryan Lortie 2011-10-02 20:59:15 -04:00
parent 2a677d1370
commit c5634df6d3
4 changed files with 43 additions and 36 deletions

View File

@ -123,7 +123,7 @@ typedef GMutex * GStaticMutex;
#define g_static_mutex_get_mutex g_static_mutex_get_mutex_impl #define g_static_mutex_get_mutex g_static_mutex_get_mutex_impl
#else /* G_OS_WIN32 */ #else /* G_OS_WIN32 */
typedef struct { typedef struct {
struct _GMutex *unused; GMutex *unused;
GMutex mutex; GMutex mutex;
} GStaticMutex; } GStaticMutex;
#define G_STATIC_MUTEX_INIT { NULL, { NULL } } #define G_STATIC_MUTEX_INIT { NULL, { NULL } }

View File

@ -116,14 +116,14 @@ g_mutex_impl_free (pthread_mutex_t *mutex)
static pthread_mutex_t * static pthread_mutex_t *
g_mutex_get_impl (GMutex *mutex) g_mutex_get_impl (GMutex *mutex)
{ {
pthread_mutex_t *impl = mutex->impl; pthread_mutex_t *impl = mutex->p;
if G_UNLIKELY (impl == NULL) if G_UNLIKELY (impl == NULL)
{ {
impl = g_mutex_impl_new (); 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); g_mutex_impl_free (impl);
impl = mutex->impl; impl = mutex->p;
} }
return impl; return impl;
@ -164,7 +164,7 @@ g_mutex_get_impl (GMutex *mutex)
void void
g_mutex_init (GMutex *mutex) 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 void
g_mutex_clear (GMutex *mutex) 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 * static pthread_mutex_t *
g_rec_mutex_get_impl (GRecMutex *rec_mutex) 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) if G_UNLIKELY (impl == NULL)
{ {
impl = g_rec_mutex_impl_new (); 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); g_rec_mutex_impl_free (impl);
impl = rec_mutex->impl; impl = rec_mutex->p;
} }
return impl; return impl;
@ -342,7 +342,7 @@ g_rec_mutex_get_impl (GRecMutex *rec_mutex)
void void
g_rec_mutex_init (GRecMutex *rec_mutex) 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 void
g_rec_mutex_clear (GRecMutex *rec_mutex) 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 void
g_rec_mutex_unlock (GRecMutex *rec_mutex) 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 * static pthread_rwlock_t *
g_rw_lock_get_impl (GRWLock *lock) g_rw_lock_get_impl (GRWLock *lock)
{ {
pthread_rwlock_t *impl = lock->impl; pthread_rwlock_t *impl = lock->p;
if G_UNLIKELY (impl == NULL) if G_UNLIKELY (impl == NULL)
{ {
impl = g_rw_lock_impl_new (); 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); g_rw_lock_impl_free (impl);
impl = lock->impl; impl = lock->p;
} }
return impl; return impl;
@ -500,7 +500,7 @@ g_rw_lock_get_impl (GRWLock *lock)
void void
g_rw_lock_init (GRWLock *rw_lock) 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 void
g_rw_lock_clear (GRWLock *rw_lock) 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 * static pthread_cond_t *
g_cond_get_impl (GCond *cond) g_cond_get_impl (GCond *cond)
{ {
pthread_cond_t *impl = cond->impl; pthread_cond_t *impl = cond->p;
if G_UNLIKELY (impl == NULL) if G_UNLIKELY (impl == NULL)
{ {
impl = g_cond_impl_new (); 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); g_cond_impl_free (impl);
impl = cond->impl; impl = cond->p;
} }
return impl; return impl;
@ -694,7 +694,7 @@ g_cond_get_impl (GCond *cond)
void void
g_cond_init (GCond *cond) 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 void
g_cond_clear (GCond *cond) g_cond_clear (GCond *cond)
{ {
g_cond_impl_free (cond->impl); g_cond_impl_free (cond->p);
} }
/** /**

View File

@ -173,14 +173,14 @@ g_rec_mutex_impl_free (CRITICAL_SECTION *cs)
static CRITICAL_SECTION * static CRITICAL_SECTION *
g_rec_mutex_get_impl (GRecMutex *mutex) 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 (); 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); g_rec_mutex_impl_free (impl);
impl = mutex->impl; impl = mutex->p;
} }
return impl; return impl;
@ -189,14 +189,13 @@ g_rec_mutex_get_impl (GRecMutex *mutex)
void void
g_rec_mutex_init (GRecMutex *mutex) g_rec_mutex_init (GRecMutex *mutex)
{ {
mutex->impl = g_rec_mutex_impl_new (); mutex->p = g_rec_mutex_impl_new ();
} }
void void
g_rec_mutex_clear (GRecMutex *mutex) g_rec_mutex_clear (GRecMutex *mutex)
{ {
if (mutex->impl) g_rec_mutex_impl_free (mutex->p);
g_rec_mutex_impl_free (mutex->impl);
} }
void void
@ -208,7 +207,7 @@ g_rec_mutex_lock (GRecMutex *mutex)
void void
g_rec_mutex_unlock (GRecMutex *mutex) g_rec_mutex_unlock (GRecMutex *mutex)
{ {
LeaveCriticalSection (mutex->impl); LeaveCriticalSection (mutex->p);
} }
gboolean gboolean

View File

@ -52,31 +52,39 @@ typedef gpointer (*GThreadFunc) (gpointer data);
typedef struct _GThread GThread; typedef struct _GThread GThread;
typedef struct _GMutex GMutex; typedef union _GMutex GMutex;
typedef struct _GRecMutex GRecMutex; typedef struct _GRecMutex GRecMutex;
typedef struct _GRWLock GRWLock; typedef struct _GRWLock GRWLock;
typedef struct _GCond GCond; typedef struct _GCond GCond;
typedef struct _GPrivate GPrivate; typedef struct _GPrivate GPrivate;
typedef struct _GStaticPrivate GStaticPrivate; typedef struct _GStaticPrivate GStaticPrivate;
struct _GMutex union _GMutex
{ {
gpointer impl; /*< private >*/
gpointer p;
guint i[2];
}; };
struct _GRWLock struct _GRWLock
{ {
gpointer impl; /*< private >*/
gpointer p;
guint i[2];
}; };
struct _GCond struct _GCond
{ {
gpointer impl; /*< private >*/
gpointer p;
guint i[2];
}; };
struct _GRecMutex struct _GRecMutex
{ {
gpointer impl; /*< private >*/
gpointer p;
guint i[2];
}; };
#define G_PRIVATE_INIT(notify) { NULL, (notify), { NULL, NULL } } #define G_PRIVATE_INIT(notify) { NULL, (notify), { NULL, NULL } }