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