impl/codegen/atm_gcc_atomic.h
Go to the documentation of this file.
1 /*
2  *
3  * Copyright 2015 gRPC authors.
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 
19 #ifndef GRPC_IMPL_CODEGEN_ATM_GCC_ATOMIC_H
20 #define GRPC_IMPL_CODEGEN_ATM_GCC_ATOMIC_H
21 
22 // IWYU pragma: private, include <grpc/support/atm.h>
23 
24 /* atm_platform.h for gcc and gcc-like compilers with the
25  __atomic_* interface. */
27 
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31 
32 typedef intptr_t gpr_atm;
33 #define GPR_ATM_MAX INTPTR_MAX
34 #define GPR_ATM_MIN INTPTR_MIN
35 
36 #ifdef GPR_LOW_LEVEL_COUNTERS
37 extern gpr_atm gpr_counter_atm_cas;
38 extern gpr_atm gpr_counter_atm_add;
39 #define GPR_ATM_INC_COUNTER(counter) \
40  __atomic_fetch_add(&counter, 1, __ATOMIC_RELAXED)
41 #define GPR_ATM_INC_CAS_THEN(blah) \
42  (GPR_ATM_INC_COUNTER(gpr_counter_atm_cas), blah)
43 #define GPR_ATM_INC_ADD_THEN(blah) \
44  (GPR_ATM_INC_COUNTER(gpr_counter_atm_add), blah)
45 #else
46 #define GPR_ATM_INC_CAS_THEN(blah) blah
47 #define GPR_ATM_INC_ADD_THEN(blah) blah
48 #endif
49 
50 #define gpr_atm_full_barrier() (__atomic_thread_fence(__ATOMIC_SEQ_CST))
51 
52 #define gpr_atm_acq_load(p) (__atomic_load_n((p), __ATOMIC_ACQUIRE))
53 #define gpr_atm_no_barrier_load(p) (__atomic_load_n((p), __ATOMIC_RELAXED))
54 #define gpr_atm_rel_store(p, value) \
55  (__atomic_store_n((p), (intptr_t)(value), __ATOMIC_RELEASE))
56 #define gpr_atm_no_barrier_store(p, value) \
57  (__atomic_store_n((p), (intptr_t)(value), __ATOMIC_RELAXED))
58 
59 #define gpr_atm_no_barrier_fetch_add(p, delta) \
60  GPR_ATM_INC_ADD_THEN( \
61  __atomic_fetch_add((p), (intptr_t)(delta), __ATOMIC_RELAXED))
62 #define gpr_atm_full_fetch_add(p, delta) \
63  GPR_ATM_INC_ADD_THEN( \
64  __atomic_fetch_add((p), (intptr_t)(delta), __ATOMIC_ACQ_REL))
65 
66 static __inline int gpr_atm_no_barrier_cas(gpr_atm* p, gpr_atm o, gpr_atm n) {
67  return GPR_ATM_INC_CAS_THEN(__atomic_compare_exchange_n(
68  p, &o, n, 0, __ATOMIC_RELAXED, __ATOMIC_RELAXED));
69 }
70 
71 static __inline int gpr_atm_acq_cas(gpr_atm* p, gpr_atm o, gpr_atm n) {
72  return GPR_ATM_INC_CAS_THEN(__atomic_compare_exchange_n(
73  p, &o, n, 0, __ATOMIC_ACQUIRE, __ATOMIC_RELAXED));
74 }
75 
76 static __inline int gpr_atm_rel_cas(gpr_atm* p, gpr_atm o, gpr_atm n) {
77  return GPR_ATM_INC_CAS_THEN(__atomic_compare_exchange_n(
78  p, &o, n, 0, __ATOMIC_RELEASE, __ATOMIC_RELAXED));
79 }
80 
81 static __inline int gpr_atm_full_cas(gpr_atm* p, gpr_atm o, gpr_atm n) {
82  return GPR_ATM_INC_CAS_THEN(__atomic_compare_exchange_n(
83  p, &o, n, 0, __ATOMIC_ACQ_REL, __ATOMIC_RELAXED));
84 }
85 
86 #define gpr_atm_full_xchg(p, n) \
87  GPR_ATM_INC_CAS_THEN(__atomic_exchange_n((p), (n), __ATOMIC_ACQ_REL))
88 
89 #ifdef __cplusplus
90 }
91 #endif
92 
93 #endif /* GRPC_IMPL_CODEGEN_ATM_GCC_ATOMIC_H */
xds_manager.p
p
Definition: xds_manager.py:60
gpr_atm_acq_cas
static __inline int gpr_atm_acq_cas(gpr_atm *p, gpr_atm o, gpr_atm n)
Definition: impl/codegen/atm_gcc_atomic.h:71
o
UnboundConversion o
Definition: third_party/abseil-cpp/absl/strings/internal/str_format/parser_test.cc:97
gpr_atm_no_barrier_cas
static __inline int gpr_atm_no_barrier_cas(gpr_atm *p, gpr_atm o, gpr_atm n)
Definition: impl/codegen/atm_gcc_atomic.h:66
gpr_atm_full_cas
static __inline int gpr_atm_full_cas(gpr_atm *p, gpr_atm o, gpr_atm n)
Definition: impl/codegen/atm_gcc_atomic.h:81
intptr_t
_W64 signed int intptr_t
Definition: stdint-msvc2008.h:118
n
int n
Definition: abseil-cpp/absl/container/btree_test.cc:1080
gpr_atm
intptr_t gpr_atm
Definition: impl/codegen/atm_gcc_atomic.h:32
GPR_ATM_INC_CAS_THEN
#define GPR_ATM_INC_CAS_THEN(blah)
Definition: impl/codegen/atm_gcc_atomic.h:46
gpr_atm_rel_cas
static __inline int gpr_atm_rel_cas(gpr_atm *p, gpr_atm o, gpr_atm n)
Definition: impl/codegen/atm_gcc_atomic.h:76
port_platform.h


grpc
Author(s):
autogenerated on Thu Mar 13 2025 02:58:35