]>
git.saurik.com Git - apple/libc.git/blob - arm/sys/gcc_atomic.c
2 * Copyright (c) 2008 Apple Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
21 * @APPLE_LICENSE_HEADER_END@
24 #include <libkern/OSAtomic.h>
29 * Implement gcc atomic "builtins" in terms of OSAtomic routines,
30 * since the ARM GCC target does not currently support them
33 int32_t __sync_fetch_and_add_4 (int32_t *ptr
, int32_t value
)
35 return OSAtomicAdd32(value
, ptr
) - value
;
38 int32_t __sync_fetch_and_sub_4 (int32_t *ptr
, int32_t value
)
40 return OSAtomicAdd32(-value
, ptr
) + value
;
43 uint32_t __sync_fetch_and_or_4(uint32_t *ptr
, uint32_t value
)
45 return OSAtomicOr32Orig(value
, ptr
);
48 uint32_t __sync_fetch_and_and_4(uint32_t *ptr
, uint32_t value
)
50 return OSAtomicAnd32Orig(value
, ptr
);
53 uint32_t __sync_fetch_and_xor_4(uint32_t *ptr
, uint32_t value
)
55 OSAtomicXor32Orig(value
, ptr
);
58 int32_t __sync_add_and_fetch_4 (int32_t *ptr
, int32_t value
)
60 return OSAtomicAdd32(value
, ptr
);
63 int32_t __sync_sub_and_fetch_4 (int32_t *ptr
, int32_t value
)
65 return OSAtomicAdd32(-value
, ptr
);
68 uint32_t __sync_or_and_fetch_4 (uint32_t *ptr
, int32_t value
)
70 return OSAtomicOr32(value
, ptr
);
73 uint32_t __sync_and_and_fetch_4 (uint32_t *ptr
, int32_t value
)
75 return OSAtomicAnd32(value
, ptr
);
78 uint32_t __sync_xor_and_fetch_4 (uint32_t *ptr
, int32_t value
)
80 return OSAtomicXor32(value
, ptr
);
83 bool __sync_bool_compare_and_swap_4(int32_t *ptr
, int32_t oldval
, int32_t newval
)
85 return OSAtomicCompareAndSwap32(oldval
, newval
, ptr
);
88 int32_t __sync_val_compare_and_swap_4(int32_t *ptr
, int32_t oldval
, int32_t newval
)
91 OSAtomicCompareAndSwap32(oldval
, newval
, ptr
);
95 int32_t __sync_lock_test_and_set_4(int32_t *ptr
, int32_t value
)
101 } while (!OSAtomicCompareAndSwap32(old
, value
, ptr
));
106 void __sync_lock_release_4(int32_t *ptr
)