1 /* LibMemcached 2 * Copyright (C) 2006-2009 Brian Aker 3 * All rights reserved. 4 * 5 * Use and distribution licensed under the BSD license. See 6 * the COPYING file in the parent directory for full text. 7 * 8 * Summary: 9 * 10 */ 11 12 #ifndef CLIENTS_MS_ATOMIC_H 13 #define CLIENTS_MS_ATOMIC_H 14 15 #if defined(__SUNPRO_C) 16 # define _KERNEL 17 # include <atomic.h> 18 # if SIZEOF_SIZE_T == 8 19 # define atomic_add_size(X, Y) atomic_add_64((X), (Y)) 20 # define atomic_add_size_nv(X, Y) atomic_add_64((X), (Y)) 21 # define atomic_dec_size(X, Y) atomic_add_64((X), (Y)) 22 # define atomic_dec_size_nv(X, Y) atomic_add_64((X), (Y)) 23 # else 24 # define atomic_add_size(X, Y) atomic_add_32((X), (Y)) 25 # define atomic_add_size_nv(X, Y) atomic_add_32((X), (Y)) 26 # define atomic_dec_size(X, Y) atomic_add_32((X), (Y)) 27 # define atomic_dec_size_nv(X, Y) atomic_add_32((X), (Y)) 28 # endif 29 # undef _KERNEL 30 #elif HAVE_GCC_ATOMIC_BUILTINS 31 # define atomic_add_8(X, Y) __sync_fetch_and_add((X), (Y)) 32 # define atomic_add_16(X, Y) __sync_fetch_and_add((X), (Y)) 33 # define atomic_add_32(X, Y) __sync_fetch_and_add((X), (Y)) 34 # define atomic_add_size(X, Y) __sync_fetch_and_add((X), (Y)) 35 # define atomic_dec_8(X) __sync_fetch_and_sub((X), 1) 36 # define atomic_dec_16(X) __sync_fetch_and_sub((X), 1) 37 # define atomic_dec_32(X) __sync_fetch_and_sub((X), 1) 38 # define atomic_dec_size(X) __sync_fetch_and_sub((X), 1) 39 /* The same as above, but these return the new value instead of void */ 40 # define atomic_add_8_nv(X, Y) __sync_fetch_and_add((X), (Y)) 41 # define atomic_add_16_nv(X, Y) __sync_fetch_and_add((X), (Y)) 42 # define atomic_add_32_nv(X, Y) __sync_fetch_and_add((X), (Y)) 43 # define atomic_add_size_nv(X, Y) __sync_fetch_and_add((X), (Y)) 44 # define atomic_dec_8_nv(X) __sync_fetch_and_sub((X), 1) 45 # define atomic_dec_16_nv(X) __sync_fetch_and_sub((X), 1) 46 # define atomic_dec_32_nv(X) __sync_fetch_and_sub((X), 1) 47 # define atomic_dec_size_nv(X) __sync_fetch_and_sub((X), 1) 48 #else 49 #warning "Atomic operators not found so memslap will not work correctly" 50 # define atomic_add_8(X, Y) 51 # define atomic_add_16(X, Y) 52 # define atomic_add_32(X, Y) 53 # define atomic_add_size(X, Y) 54 # define atomic_dec_8(X) 55 # define atomic_dec_16(X) 56 # define atomic_dec_32(X) 57 # define atomic_dec_size(X) 58 /* The same as above, but these return the new value instead of void */ 59 # define atomic_add_8_nv(X, Y) 60 # define atomic_add_16_nv(X, Y) 61 # define atomic_add_32_nv(X, Y) 62 # define atomic_add_size_nv(X, Y) 63 # define atomic_dec_8_nv(X) 64 # define atomic_dec_16_nv(X) 65 # define atomic_dec_32_nv(X) 66 # define atomic_dec_size_nv(X) 67 #endif /* defined(__SUNPRO_C) */ 68 69 #endif /* CLIENTS_MS_ATOMIC_H */ 70