[glib/wip/mutexes] Add GRWLock



commit 371f12d7231c9aec49fba18a886856f787723b64
Author: Ryan Lortie <desrt desrt ca>
Date:   Wed Sep 21 10:19:36 2011 -0400

    Add GRWLock

 glib/glib.symbols     |    8 +++++++
 glib/gthread-posix.c  |   50 ++++++++++++++++++++++++++++++++++++++++++++++++
 glib/gthread-win32.c  |   51 +++++++++++++++++++++++++++++++++++++++++++++++++
 glib/gthread.h        |   26 +++++++++++++++++++++++-
 glib/tests/strfuncs.c |    1 -
 5 files changed, 133 insertions(+), 3 deletions(-)
---
diff --git a/glib/glib.symbols b/glib/glib.symbols
index 32bf8c6..7f79813 100644
--- a/glib/glib.symbols
+++ b/glib/glib.symbols
@@ -1616,3 +1616,11 @@ g_mutex_unlock
 g_private_new
 g_private_get
 g_private_set
+g_rw_lock_clear
+g_rw_lock_init
+g_rw_lock_reader_lock
+g_rw_lock_reader_trylock
+g_rw_lock_reader_unlock
+g_rw_lock_writer_lock
+g_rw_lock_writer_trylock
+g_rw_lock_writer_unlock
diff --git a/glib/gthread-posix.c b/glib/gthread-posix.c
index 76697f2..c4fd6f2 100644
--- a/glib/gthread-posix.c
+++ b/glib/gthread-posix.c
@@ -197,6 +197,56 @@ g_mutex_trylock (GMutex *mutex)
   return FALSE;
 }
 
+/* {{{1 GRWLock */
+
+void
+g_rw_lock_init (GRWLock *lock)
+{
+  pthread_rwlock_init (&lock->impl, NULL);
+}
+
+void
+g_rw_lock_clear (GRWLock *lock)
+{
+  pthread_rwlock_destroy (&lock->impl);
+}
+
+void
+g_rw_lock_writer_lock (GRWLock *lock)
+{
+  pthread_rwlock_wrlock (&lock->impl);
+}
+
+gboolean
+g_rw_lock_writer_trylock (GRWLock *lock)
+{
+  return pthread_rwlock_trywrlock (&lock->impl);
+}
+
+void
+g_rw_lock_writer_unlock (GRWLock *lock)
+{
+  pthread_rwlock_unlock (&lock->impl);
+}
+
+void
+g_rw_lock_reader_lock (GRWLock *lock)
+{
+  pthread_rwlock_rdlock (&lock->impl);
+}
+
+gboolean
+g_rw_lock_reader_trylock (GRWLock *lock)
+{
+  return pthread_rwlock_tryrdlock (&lock->impl);
+}
+
+void
+g_rw_lock_reader_unlock (GRWLock *lock)
+{
+  pthread_rwlock_unlock (&lock->impl);
+}
+
 /* {{{1 GCond */
 
 /**
diff --git a/glib/gthread-win32.c b/glib/gthread-win32.c
index cadd0c7..1213143 100644
--- a/glib/gthread-win32.c
+++ b/glib/gthread-win32.c
@@ -154,6 +154,57 @@ g_mutex_unlock (GMutex *mutex)
   g_thread_impl_vtable.ReleaseSRWLockExclusive (mutex);
 }
 
+/* {{{1 GRWLock */
+
+void
+g_rw_lock_init (GRWLock *lock)
+{
+  g_thread_impl_vtable.InitializeSRWLock (lock);
+}
+
+void
+g_rw_lock_clear (GRWLock *lock)
+{
+  if (g_thread_impl_vtable.DeleteSRWLock != NULL)
+    g_thread_impl_vtable.DeleteSRWLock (lock);
+}
+
+void
+g_rw_lock_writer_lock (GRWLock *lock)
+{
+  g_thread_impl_vtable.AcquireSRWLockExclusive (lock);
+}
+
+gboolean
+g_rw_lock_writer_trylock (GRWLock *lock)
+{
+  return g_thread_impl_vtable.TryAcquireSRWLockExclusive (lock);
+}
+
+void
+g_rw_lock_writer_unlock (GRWLock *lock)
+{
+  g_thread_impl_vtable.ReleaseSRWLockExclusive (lock);
+}
+
+void
+g_rw_lock_reader_lock (GRWLock *lock)
+{
+  g_thread_impl_vtable.AcquireSRWLockShared (lock);
+}
+
+gboolean
+g_rw_lock_reader_trylock (GRWLock *lock)
+{
+  return g_thread_impl_vtable.TryAcquireSRWLockShared (lock);
+}
+
+void
+g_rw_lock_reader_unlock (GRWLock *lock)
+{
+  g_thread_impl_vtable.ReleaseSRWLockShared (lock);
+}
+
 /* {{{1 GCond */
 void
 g_cond_init (GCond *cond)
diff --git a/glib/gthread.h b/glib/gthread.h
index b2db18a..161de59 100644
--- a/glib/gthread.h
+++ b/glib/gthread.h
@@ -53,6 +53,7 @@ typedef gpointer (*GThreadFunc) (gpointer data);
 typedef struct _GThread         GThread;
 
 typedef struct _GMutex          GMutex;
+typedef struct _GRWLock         GRWLock;
 typedef struct _GCond           GCond;
 typedef struct _GPrivate        GPrivate;
 typedef struct _GStaticPrivate  GStaticPrivate;
@@ -62,13 +63,19 @@ typedef struct _GStaticPrivate  GStaticPrivate;
 #define G_MUTEX_INIT { NULL }
 struct _GMutex
 {
-    gpointer impl;
+  gpointer impl;
+};
+
+#define G_RWLOCK_INIT { NULL }
+struct _GRWLock
+{
+  gpointer impl;
 };
 
 #define G_COND_INIT { NULL }
 struct _GCond
 {
-    gpointer impl;
+  gpointer impl;
 };
 #else
 
@@ -80,6 +87,12 @@ struct _GMutex
   pthread_mutex_t impl;
 };
 
+#define G_RW_LOCK_INIT { PTHREAD_RWLOCK_INITIALIZER }
+struct _GRWLock
+{
+  pthread_rwlock_t impl;
+};
+
 #define G_COND_INIT { PTHREAD_COND_INITIALIZER }
 struct _GCond
 {
@@ -292,6 +305,15 @@ void                    g_mutex_lock                                    (GMutex
 void                    g_mutex_unlock                                  (GMutex         *mutex);
 gboolean                g_mutex_trylock                                 (GMutex         *mutex);
 
+void                    g_rw_lock_init                                  (GRWLock        *lock);
+void                    g_rw_lock_clear                                 (GRWLock        *lock);
+void                    g_rw_lock_writer_lock                           (GRWLock        *lock);
+gboolean                g_rw_lock_writer_trylock                        (GRWLock        *lock);
+void                    g_rw_lock_writer_unlock                         (GRWLock        *lock);
+void                    g_rw_lock_reader_lock                           (GRWLock        *lock);
+gboolean                g_rw_lock_reader_trylock                        (GRWLock        *lock);
+void                    g_rw_lock_reader_unlock                         (GRWLock        *lock);
+
 GCond *                 g_cond_new                                      (void);
 void                    g_cond_free                                     (GCond          *cond);
 void                    g_cond_init                                     (GCond          *cond);
diff --git a/glib/tests/strfuncs.c b/glib/tests/strfuncs.c
index df8b67d..ff632c7 100644
--- a/glib/tests/strfuncs.c
+++ b/glib/tests/strfuncs.c
@@ -19,7 +19,6 @@
  * if advised of the possibility of such damage.
  */
 
-#define _XOPEN_SOURCE
 #include <ctype.h>
 #include <errno.h>
 #include <locale.h>



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