summaryrefslogtreecommitdiff
path: root/src/upb_atomic.h
diff options
context:
space:
mode:
authorJoshua Haberman <joshua@reverberate.org>2009-12-05 18:06:50 -0800
committerJoshua Haberman <joshua@reverberate.org>2009-12-05 18:06:50 -0800
commit651c92ab33187b34d7878ac57427bbbc062662fa (patch)
tree1049aebdaf255ddd344237fb972ac8d39fa7d353 /src/upb_atomic.h
parent18291eedc3cb6bf4386698620ad9d02ad367126a (diff)
Scheme for collecting circular refs.
"make descriptorgen" is now valgrind-clean again.
Diffstat (limited to 'src/upb_atomic.h')
-rw-r--r--src/upb_atomic.h20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/upb_atomic.h b/src/upb_atomic.h
index 85ec582..22aa306 100644
--- a/src/upb_atomic.h
+++ b/src/upb_atomic.h
@@ -50,6 +50,14 @@ INLINE bool upb_atomic_unref(upb_atomic_refcount_t *a) {
return --a->val == 0;
}
+INLINE int upb_atomic_read(upb_atomic_refcount_t *a) {
+ return a->val;
+}
+
+INLINE bool upb_atomic_add(upb_atomic_refcount_t *a, int val) {
+ return a->val += val;
+}
+
typedef struct {
} upb_rwlock_t;
@@ -84,10 +92,22 @@ INLINE bool upb_atomic_ref(upb_atomic_refcount_t *a) {
return __sync_fetch_and_add(&a->val, 1) == 0;
}
+INLINE bool upb_atomic_add(upb_atomic_refcount_t *a, int n) {
+ return __sync_fetch_and_add(&a->val, n) == 0;
+}
+
INLINE bool upb_atomic_unref(upb_atomic_refcount_t *a) {
return __sync_sub_and_fetch(&a->val, 1) == 0;
}
+INLINE bool upb_atomic_read(upb_atomic_refcount_t *a) {
+ return __sync_fetch_and_add(&a->val, 0);
+}
+
+INLINE bool upb_atomic_write(upb_atomic_refcount_t *a, int val) {
+ a->val = val;
+}
+
#elif defined(WIN32)
/* Windows defines atomic increment/decrement. */
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback