]>
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@
27 #include <libkern/OSAtomic.h>
32 * Implement gcc atomic "builtins" in terms of OSAtomic routines,
33 * since the ARM GCC target does not currently support them
36 int32_t __sync_fetch_and_add_4 (int32_t *ptr
, int32_t value
)
38 return OSAtomicAdd32Barrier(value
, ptr
) - value
;
41 int32_t __sync_fetch_and_sub_4 (int32_t *ptr
, int32_t value
)
43 return OSAtomicAdd32Barrier(-value
, ptr
) + value
;
46 uint32_t __sync_fetch_and_or_4(uint32_t *ptr
, uint32_t value
)
48 return OSAtomicOr32OrigBarrier(value
, ptr
);
51 uint32_t __sync_fetch_and_and_4(uint32_t *ptr
, uint32_t value
)
53 return OSAtomicAnd32OrigBarrier(value
, ptr
);
56 uint32_t __sync_fetch_and_xor_4(uint32_t *ptr
, uint32_t value
)
58 return OSAtomicXor32OrigBarrier(value
, ptr
);
61 int32_t __sync_add_and_fetch_4 (int32_t *ptr
, int32_t value
)
63 return OSAtomicAdd32Barrier(value
, ptr
);
66 int32_t __sync_sub_and_fetch_4 (int32_t *ptr
, int32_t value
)
68 return OSAtomicAdd32Barrier(-value
, ptr
);
71 uint32_t __sync_or_and_fetch_4 (uint32_t *ptr
, int32_t value
)
73 return OSAtomicOr32Barrier(value
, ptr
);
76 uint32_t __sync_and_and_fetch_4 (uint32_t *ptr
, int32_t value
)
78 return OSAtomicAnd32Barrier(value
, ptr
);
81 uint32_t __sync_xor_and_fetch_4 (uint32_t *ptr
, int32_t value
)
83 return OSAtomicXor32Barrier(value
, ptr
);
86 bool __sync_bool_compare_and_swap_4(int32_t *ptr
, int32_t oldval
, int32_t newval
)
88 return OSAtomicCompareAndSwap32Barrier(oldval
, newval
, ptr
);
91 int32_t __sync_val_compare_and_swap_4(int32_t *ptr
, int32_t oldval
, int32_t newval
)
94 OSAtomicCompareAndSwap32Barrier(oldval
, newval
, ptr
);
98 int32_t __sync_lock_test_and_set_4(int32_t *ptr
, int32_t value
)
104 } while (!OSAtomicCompareAndSwap32Barrier(old
, value
, ptr
));
109 void __sync_lock_release_4(int32_t *ptr
)