From cfd67dda4967d2246ab1a9d852ad466a9b2a1a18 Mon Sep 17 00:00:00 2001 From: Joshua Haberman Date: Sun, 16 Aug 2009 00:21:17 -0700 Subject: Various fixes. --- src/upb_atomic.h | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'src/upb_atomic.h') 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 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) { -- cgit v1.2.3