impl/codegen/atm_gcc_sync.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_SYNC_H
20 #define GRPC_IMPL_CODEGEN_ATM_GCC_SYNC_H
21 
22 // IWYU pragma: private, include <grpc/support/atm.h>
23 
24 /* variant of atm_platform.h for gcc and gcc-like compiers with __sync_*
25  interface */
27 
28 typedef intptr_t gpr_atm;
29 #define GPR_ATM_MAX INTPTR_MAX
30 #define GPR_ATM_MIN INTPTR_MIN
31 #define GPR_ATM_INC_CAS_THEN(blah) blah
32 #define GPR_ATM_INC_ADD_THEN(blah) blah
33 
34 #define GPR_ATM_COMPILE_BARRIER_() __asm__ __volatile__("" : : : "memory")
35 
36 #if defined(__i386) || defined(__x86_64__)
37 /* All loads are acquire loads and all stores are release stores. */
38 #define GPR_ATM_LS_BARRIER_() GPR_ATM_COMPILE_BARRIER_()
39 #else
40 #define GPR_ATM_LS_BARRIER_() gpr_atm_full_barrier()
41 #endif
42 
43 #define gpr_atm_full_barrier() (__sync_synchronize())
44 
45 static __inline gpr_atm gpr_atm_acq_load(const gpr_atm* p) {
46  gpr_atm value = *p;
48  return value;
49 }
50 
51 static __inline gpr_atm gpr_atm_no_barrier_load(const gpr_atm* p) {
52  gpr_atm value = *p;
54  return value;
55 }
56 
57 static __inline void gpr_atm_rel_store(gpr_atm* p, gpr_atm value) {
59  *p = value;
60 }
61 
62 static __inline void gpr_atm_no_barrier_store(gpr_atm* p, gpr_atm value) {
64  *p = value;
65 }
66 
67 #undef GPR_ATM_LS_BARRIER_
68 #undef GPR_ATM_COMPILE_BARRIER_
69 
70 #define gpr_atm_no_barrier_fetch_add(p, delta) \
71  gpr_atm_full_fetch_add((p), (delta))
72 #define gpr_atm_full_fetch_add(p, delta) (__sync_fetch_and_add((p), (delta)))
73 
74 #define gpr_atm_no_barrier_cas(p, o, n) gpr_atm_acq_cas((p), (o), (n))
75 #define gpr_atm_acq_cas(p, o, n) (__sync_bool_compare_and_swap((p), (o), (n)))
76 #define gpr_atm_rel_cas(p, o, n) gpr_atm_acq_cas((p), (o), (n))
77 #define gpr_atm_full_cas(p, o, n) gpr_atm_acq_cas((p), (o), (n))
78 
80  gpr_atm cur;
81  do {
83  } while (!gpr_atm_rel_cas(p, cur, n));
84  return cur;
85 }
86 
87 #endif /* GRPC_IMPL_CODEGEN_ATM_GCC_SYNC_H */
gpr_atm_full_xchg
static __inline gpr_atm gpr_atm_full_xchg(gpr_atm *p, gpr_atm n)
Definition: impl/codegen/atm_gcc_sync.h:79
gpr_atm_no_barrier_store
static __inline void gpr_atm_no_barrier_store(gpr_atm *p, gpr_atm value)
Definition: impl/codegen/atm_gcc_sync.h:62
GPR_ATM_COMPILE_BARRIER_
#define GPR_ATM_COMPILE_BARRIER_()
Definition: impl/codegen/atm_gcc_sync.h:34
gpr_atm_no_barrier_load
static __inline gpr_atm gpr_atm_no_barrier_load(const gpr_atm *p)
Definition: impl/codegen/atm_gcc_sync.h:51
GPR_ATM_LS_BARRIER_
#define GPR_ATM_LS_BARRIER_()
Definition: impl/codegen/atm_gcc_sync.h:40
gpr_atm_acq_load
static __inline gpr_atm gpr_atm_acq_load(const gpr_atm *p)
Definition: impl/codegen/atm_gcc_sync.h:45
gpr_atm_rel_cas
#define gpr_atm_rel_cas(p, o, n)
Definition: impl/codegen/atm_gcc_sync.h:76
xds_manager.p
p
Definition: xds_manager.py:60
gpr_atm_rel_store
static __inline void gpr_atm_rel_store(gpr_atm *p, gpr_atm value)
Definition: impl/codegen/atm_gcc_sync.h:57
gpr_atm
intptr_t gpr_atm
Definition: impl/codegen/atm_gcc_sync.h:28
intptr_t
_W64 signed int intptr_t
Definition: stdint-msvc2008.h:118
n
int n
Definition: abseil-cpp/absl/container/btree_test.cc:1080
value
const char * value
Definition: hpack_parser_table.cc:165
gpr_atm
intptr_t gpr_atm
Definition: impl/codegen/atm_gcc_atomic.h:32
memory_diff.cur
def cur
Definition: memory_diff.py:83
port_platform.h


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