Support Android API level earlier than 9.
authorMarcus Brinkmann <marcus.brinkmann@ruhr-uni-bochum.de>
Fri, 9 Mar 2012 18:00:21 +0000 (19:00 +0100)
committerMarcus Brinkmann <marcus.brinkmann@ruhr-uni-bochum.de>
Fri, 9 Mar 2012 18:06:24 +0000 (19:06 +0100)
* src/npth.h [__ANDROID__]: Include <android/api-level.h>
(_NPTH_NO_RWLOCK) [__ANDROID__ && __ANDROID_API__ < 9]: Define.
(npth_rwlockattr_t, npth_rwlockattr_init, npth_rwlockattr_destroy,
npth_rwlockattr_gettype_np, npth_rwlockattr_settype_np,
NPTH_RWLOCK_PREFER_READER_NP, NPTH_RWLOCK_PREFER_WRITER_NP,
NPTH_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP, NPTH_RWLOCK_DEFAULT_NP,
NPTH_RWLOCK_INITIALIZER, NPTH_RWLOCK_WRITER_NONRECURSIVE_INITIALIZER_NP,
NPTH_MUTEX_INITIALIZER, npth_rwlock_t, npth_rwlock_init,
npth_rwlock_destroy, npth_rwlock_tryrdlock, npth_rwlock_rdlock,
npth_rwlock_trywrlock, npth_rwlock_timedrdlock, npth_rwlock_wrlock,
npth_rwlock_rdlock, npth_rwlock_timedwrlock, npth_rwlock_unlock
(_NPTH_NO_RWLOCK): Alternative implementation based on mutex.

src/npth.c
src/npth.h.in

index fb63f13..18221d5 100644 (file)
@@ -308,6 +308,7 @@ npth_mutex_timedlock (npth_mutex_t *mutex, const struct timespec *abstime)
 }
 
 
+#ifndef _NPTH_NO_RWLOCK
 int
 npth_rwlock_rdlock (npth_rwlock_t *rwlock)
 {
@@ -396,6 +397,7 @@ npth_rwlock_timedwrlock (npth_rwlock_t *rwlock, const struct timespec *abstime)
   LEAVE();
   return err;
 }
+#endif
 
 
 int
index ac9890a..2110e35 100644 (file)
 
 #include <pthread.h>
 
+#ifdef __ANDROID__
+#include <android/api-level.h>
+#if __ANDROID_API__ < 9
+/* Android 8 and earlier are missing rwlocks.  We punt to mutexes in
+   that case.  */
+#define _NPTH_NO_RWLOCK 1
+#endif
+#endif
+
 #ifdef __cplusplus
 extern "C" {
 #if 0 /* (Keep Emacsens' auto-indent happy.) */
@@ -211,6 +220,33 @@ int npth_mutex_timedlock(npth_mutex_t *mutex, const struct timespec *abstime);
 
 #define npth_mutex_unlock pthread_mutex_unlock
 
+#ifdef _NPTH_NO_RWLOCK
+
+typedef int npth_rwlockattr_t;
+#define npth_rwlockattr_init(attr)
+#define npth_rwlockattr_destroy(attr)
+#define npth_rwlockattr_gettype_np(attr,kind)
+#define npth_rwlockattr_settype_np(attr,kind)
+#define NPTH_RWLOCK_PREFER_READER_NP 0
+#define NPTH_RWLOCK_PREFER_WRITER_NP 0
+#define NPTH_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP 0
+#define NPTH_RWLOCK_DEFAULT_NP 0
+#define NPTH_RWLOCK_INITIALIZER NPTH_MUTEX_INITIALIZER
+#define NPTH_RWLOCK_WRITER_NONRECURSIVE_INITIALIZER_NP NPTH_MUTEX_INITIALIZER
+typedef npth_mutex_t npth_rwlock_t;
+#define npth_rwlock_init(rwlock,attr) npth_mutex_init(rwlock,0)
+#define npth_rwlock_destroy npth_mutex_destroy
+#define npth_rwlock_tryrdlock npth_mutex_trylock
+#define npth_rwlock_rdlock npth_mutex_lock
+#define npth_rwlock_trywrlock npth_mutex_trylock
+#define npth_rwlock_timedrdlock npth_mutex_timedlock
+#define npth_rwlock_wrlock npth_mutex_lock
+#define npth_rwlock_rdlock npth_mutex_lock
+#define npth_rwlock_timedwrlock npth_mutex_timedlock
+#define npth_rwlock_unlock npth_mutex_unlock
+
+#else /* _NPTH_NO_RWLOCK */
+
 #define npth_rwlockattr_t pthread_rwlockattr_t
 #define npth_rwlockattr_init pthread_rwlockattr_init
 #define npth_rwlockattr_destroy pthread_rwlockattr_destroy
@@ -252,6 +288,9 @@ int npth_rwlock_timedwrlock (npth_rwlock_t *rwlock,
                             const struct timespec *abstime);
 #define npth_rwlock_unlock  pthread_rwlock_unlock
 
+#endif /* !_NPTH_NO_RWLOCK */
+
+
 typedef pthread_cond_t npth_cond_t;
 #define NPTH_COND_INITIALIZER PTHREAD_COND_INITIALIZER
 /* For now, we don't support any cond attributes.  */