2 * Copyright (C) 2005, 2007, 2009, 2011, 2012 Internet Systems Consortium, Inc. ("ISC")
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
8 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
9 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
10 * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
11 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
12 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
13 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
14 * PERFORMANCE OF THIS SOFTWARE.
20 #define ISC_ATOMIC_H 1
22 #include <isc/platform.h>
23 #include <isc/types.h>
26 * static inline isc_int32_t
27 * isc_atomic_xadd(isc_int32_t *p, isc_int32_t val);
29 * This routine atomically increments the value stored in 'p' by 'val', and
30 * returns the previous value.
33 * isc_atomic_store(void *p, isc_int32_t val);
35 * This routine atomically stores the value 'val' in 'p'.
37 * static inline isc_int32_t
38 * isc_atomic_cmpxchg(isc_int32_t *p, isc_int32_t cmpval, isc_int32_t val);
40 * This routine atomically replaces the value in 'p' with 'val', if the
41 * original value is equal to 'cmpval'. The original value is returned in any
47 #include <sys/atomic_op.h>
49 #define isc_atomic_store(p, v) _clear_lock(p, v)
52 static inline isc_int32_t
56 isc_atomic_xadd(isc_int32_t *p, isc_int32_t val) {
65 ret = fetch_and_add((atomic_p)p, (int)val);
81 isc_atomic_cmpxchg(atomic_p p, int old, int new) {
89 if (compare_and_swap(p, &orig, new))
101 #elif defined(ISC_PLATFORM_USEGCCASM) || defined(ISC_PLATFORM_USEMACASM)
102 static inline isc_int32_t
103 isc_atomic_xadd(isc_int32_t *p, isc_int32_t val) {
107 #ifdef ISC_PLATFORM_USEMACASM
133 isc_atomic_store(void *p, isc_int32_t val) {
135 #ifdef ISC_PLATFORM_USEMACASM
156 static inline isc_int32_t
157 isc_atomic_cmpxchg(isc_int32_t *p, isc_int32_t cmpval, isc_int32_t val) {
161 #ifdef ISC_PLATFORM_USEMACASM
185 : "r"(p), "r"(cmpval), "r"(val)
194 #error "unsupported compiler. disable atomic ops by --disable-atomic"
197 #endif /* ISC_ATOMIC_H */