summaryrefslogtreecommitdiff
path: root/src/upb_atomic.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/upb_atomic.h')
-rw-r--r--src/upb_atomic.h12
1 files changed, 7 insertions, 5 deletions
diff --git a/src/upb_atomic.h b/src/upb_atomic.h
index b3995e4..c1a60b9 100644
--- a/src/upb_atomic.h
+++ b/src/upb_atomic.h
@@ -79,12 +79,12 @@ INLINE void upb_atomic_refcount_init(upb_atomic_refcount_t *a, int val) {
__sync_synchronize(); /* Ensure the initialized value is visible. */
}
-INLINE void upb_atomic_ref(upb_atomic_refcount_t *a) {
- return __sync_fetch_and_add(&a->val) == 0;
+INLINE bool upb_atomic_ref(upb_atomic_refcount_t *a) {
+ return __sync_fetch_and_add(&a->val, 1) == 0;
}
INLINE bool upb_atomic_unref(upb_atomic_refcount_t *a) {
- return __sync_sub_and_fetch(&a->val) == 0;
+ return __sync_sub_and_fetch(&a->val, 1) == 0;
}
#elif defined(WIN32)
@@ -119,7 +119,9 @@ INLINE bool upb_atomic_unref(upb_atomic_refcount_t *a) {
/* Already defined. */
-#elif defined(_POSIX_THREADS)
+#elif defined(UPB_USE_PTHREADS)
+
+#include <pthread.h>
typedef struct {
pthread_rwlock_t lock;
@@ -127,7 +129,7 @@ typedef struct {
INLINE void upb_rwlock_init(upb_rwlock_t *l) {
/* TODO: check return value. */
- pthread_rwlock_init(&l->lock);
+ pthread_rwlock_init(&l->lock, NULL);
}
INLINE void upb_rwlock_destroy(upb_rwlock_t *l) {
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback