EpcTools
An event based multi-threaded C++ development framework.
eatomic.h
Go to the documentation of this file.
1 /*
2 * Copyright (c) 2009-2019 Brian Waters
3 * Copyright (c) 2019 Sprint
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17 
18 #ifndef __eatomic_h_included
19 #define __eatomic_h_included
20 
23 
25 #define atomic_dec(a) __sync_sub_and_fetch(&a, 1)
26 #define atomic_inc(a) __sync_add_and_fetch(&a, 1)
28 #define atomic_dec_fetch(a) __sync_sub_and_fetch(&a, 1)
30 #define atomic_inc_fetch(a) __sync_add_and_fetch(&a, 1)
32 #define atomic_fetch_dec(a) __sync_fetch_and_sub(&a, 1)
34 #define atomic_fetch_inc(a) __sync_fetch_and_add(&a, 1)
36 #define atomic_cas(a, b, c) __sync_val_compare_and_swap(&a, b, c)
38 #define atomic_swap(a, b) __sync_lock_test_and_set(&a, b)
40 #define atomic_and(a, b) __sync_fetch_and_and(&a, b)
42 #define atomic_or(a, b) __sync_fetch_and_or(&a, b)
44 #define atomic_set(a, b) __sync_lock_test_and_set(&a, b)
46 
47 #endif // #define __eatomic_h_included