Have attributes for mutex, rwlock and cond like in pthread.
authorMarcus Brinkmann <marcus.brinkmann@ruhr-uni-bochum.de>
Fri, 7 Oct 2011 19:58:02 +0000 (21:58 +0200)
committerMarcus Brinkmann <marcus.brinkmann@ruhr-uni-bochum.de>
Fri, 7 Oct 2011 19:58:02 +0000 (21:58 +0200)
ChangeLog
src/libnpth.vers
src/npth.c
src/npth.def
src/npth.h
tests/t-mutex.c

index dba8c60..74db096 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2011-10-07  Marcus Brinkmann  <marcus@g10code.com>
+
+       * src/npth.h (npth_mutexattr_t, npth_mutexattr_init)
+       (npth_mutexattr_destroy, npth_mutexattr_settype)
+       (npth_mutexattr_gettype, NPTH_MUTEX_NORMAL, NPTH_MUTEX_RECURSIVE)
+       (NPTH_MUTEX_ERRORCHECK, NPTH_MUTEX_DEFAULT): New.
+       * src/npth.c (npth_mutex_init): Removed.
+       * src/libnpth.vers: Remove npth_mutex_init.
+       * src/npth.def: Likewise.  Add missing numbers.
+       * tests/t-mutex.c: Adjust to new interface.
+
 2011-10-06  Marcus Brinkmann  <marcus@g10code.com>
 
        * Initial version.
index ae2c70f..d5ec292 100644 (file)
@@ -23,7 +23,6 @@
 NPTH_1.0 {
   global:
     npth_init;
-    npth_mutex_init;
     _npth_mutex_lock;
     _npth_mutex_timedlock;
     _npth_rwlock_rdlock;
index fdd9927..34d936f 100644 (file)
@@ -108,22 +108,6 @@ npth_init (void)
 
 \f
 int
-npth_mutex_init (npth_mutex_t *mutex)
-{
-  int err;
-  pthread_mutexattr_t attr;
-
-  err = pthread_mutexattr_init(&attr);
-  assert (!err);
-  err = pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
-  assert (!err);
-  pthread_mutex_init(mutex, &attr);
-  pthread_mutexattr_destroy(&attr);
-  return 0;
-}
-
-
-int
 _npth_mutex_lock (npth_mutex_t *mutex)
 {
   int err;
index 710898b..301d4b5 100644 (file)
 
 EXPORTS
     npth_init                          @1
-    npth_mutex_init                    @
-    _npth_mutex_lock                   @
-    _npth_mutex_timedlock              @
-    _npth_rwlock_rdlock                        @
-    _npth_rwlock_timedrdlock           @
-    _npth_rwlock_wrlock                        @
-    _npth_rwlock_timedwrlock           @
-    npth_cond_wait                     @
-    npth_cond_timedwait                        @
-    npth_usleep                                @
-    npth_sleep                         @
-    npth_waitpid                       @
-    npth_system                                @
-    npth_sigmask                       @
-    npth_sigwait                       @
-    npth_connect                       @
-    npth_accept                                @
-    npth_select                                @
-    npth_pselect                       @
-    npth_read                          @
-    npth_write                         @
-    npth_recvmsg                       @
-    npth_sendmsg                       @
+    _npth_mutex_lock                   @2
+    _npth_mutex_timedlock              @3
+    _npth_rwlock_rdlock                        @4
+    _npth_rwlock_timedrdlock           @5
+    _npth_rwlock_wrlock                        @6
+    _npth_rwlock_timedwrlock           @7
+    npth_cond_wait                     @8
+    npth_cond_timedwait                        @9
+    npth_usleep                                @10
+    npth_sleep                         @11
+    npth_waitpid                       @12
+    npth_system                                @13
+    npth_sigmask                       @14
+    npth_sigwait                       @15
+    npth_connect                       @16
+    npth_accept                                @17
+    npth_select                                @18
+    npth_pselect                       @19
+    npth_read                          @20
+    npth_write                         @21
+    npth_recvmsg                       @22
+    npth_sendmsg                       @23
 
-    npth_sigev_init                    @
-    npth_sigev_add                     @
-    npth_sigev_fini                    @
-    npth_sigev_sigmask                 @
-    npth_sigev_get_pending             @
+    npth_sigev_init                    @24
+    npth_sigev_add                     @25
+    npth_sigev_fini                    @26
+    npth_sigev_sigmask                 @27
+    npth_sigev_get_pending             @28
 
 ; END
 
index 77a3885..b918a56 100644 (file)
@@ -184,11 +184,21 @@ int npth_init(void);
 \f
 /* Synchronization */
 
-typedef pthread_mutex_t npth_mutex_t;
-#define NPTH_MUTEX_INITIALIZER PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP
-#define NPTH_RECURSIVE_MUTEX_INITIALIZER PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP
+#define npth_mutexattr_t pthread_mutexattr_t
+#define npth_mutexattr_init pthread_mutexattr_init
+#define npth_mutexattr_destroy pthread_mutexattr_destroy
+#define npth_mutexattr_settype pthread_mutexattr_settype
+#define npth_mutexattr_gettype pthread_mutexattr_gettype
+#define NPTH_MUTEX_NORMAL PTHREAD_MUTEX_NORMAL
+#define NPTH_MUTEX_RECURSIVE PTHREAD_MUTEX_RECURSIVE
+#define NPTH_MUTEX_ERRORCHECK PTHREAD_MUTEX_ERRORCHECK
+#define NPTH_MUTEX_DEFAULT PTHREAD_MUTEX_DEFAULT
+
+#define npth_mutex_t pthread_mutex_t
+#define NPTH_MUTEX_INITIALIZER PTHREAD_MUTEX_INITIALIZER
+#define NPTH_RECURSIVE_MUTEX_INITIALIZER_NP PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP
 /* FIXME: Go away from recursive lock default.  */
-int npth_mutex_init(npth_mutex_t *mutex);
+#define npth_mutex_init pthread_mutex_init
 #define npth_mutex_trylock pthread_mutex_trylock
 
 int _npth_mutex_lock(npth_mutex_t *mutex);
@@ -219,7 +229,8 @@ npth_mutex_timedlock(npth_mutex_t *mutex, const struct timespec *abstime)
 
 typedef pthread_rwlock_t npth_rwlock_t;
 #define NPTH_RWLOCK_INIT PTHREAD_RWLOCK_INITIALIZER
-#define npth_rwlock_init(rwlock) pthread_rwlock_init(rwlock, NULL)
+/* For now, we don't support any rwlock attributes.  */
+#define npth_rwlock_init pthread_rwlock_init
 #define npth_rwlock_tryrdlock pthread_rwlock_tryrdlock
 
 int _npth_rwlock_rdlock (npth_rwlock_t *rwlock);
@@ -277,7 +288,8 @@ npth_rwlock_timedwrlock (npth_rwlock_t *rwlock, const struct timespec *abstime)
 
 typedef pthread_cond_t npth_cond_t;
 #define NPTH_COND_INITIALIZER PTHREAD_COND_INITIALIZER
-#define npth_cond_init(cond) pthread_cond_init(cond, NULL)
+/* For now, we don't support any cond attributes.  */
+#define npth_cond_init pthread_cond_init
 #define npth_cond_broadcast pthread_cond_broadcast
 #define npth_cond_signal pthread_cond_signal
 #define npth_cond_destroy pthread_cond_destroy
index 445b20f..a95411a 100644 (file)
@@ -6,7 +6,7 @@ main (int argc, char *argv[])
   npth_mutex_t mutex;
   npth_init ();
   
-  npth_mutex_init (&mutex);
+  npth_mutex_init (&mutex, NULL);
   npth_mutex_lock (&mutex);
   npth_mutex_unlock (&mutex);
 }