Home | History | Annotate | Line # | Download | only in libzpool
atomic.c revision 1.2
      1 
      2 #include <inttypes.h>
      3 #include <sys/types.h>
      4 #include <sys/atomic.h>
      5 
      6 #ifndef __HAVE_ATOMIC64_OPS
      7 
      8 /* XXX: Not so atomic, could use mutexes but not worth it */
      9 uint64_t
     10 atomic_cas_64(volatile uint64_t *ptr, uint64_t old, uint64_t new) {
     11 	uint64_t prev = *ptr;
     12 	if (prev == old)
     13 		*ptr = new;
     14 	return prev;
     15 }
     16 
     17 void
     18 atomic_add_64(volatile uint64_t *ptr, int64_t delta) {
     19 	*ptr += delta;
     20 }
     21 
     22 void
     23 atomic_inc_64(volatile uint64_t *ptr) {
     24 	++(*ptr);
     25 }
     26 
     27 void
     28 atomic_dec_64(volatile uint64_t *ptr) {
     29 	--(*ptr);
     30 }
     31 
     32 uint64_t
     33 atomic_add_64_nv(volatile uint64_t *ptr, int64_t delta) {
     34 	return *ptr += delta;
     35 }
     36 
     37 #endif
     38