GRPC Core  6.0.0
atm_windows.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_WINDOWS_H
20 #define GRPC_IMPL_CODEGEN_ATM_WINDOWS_H
21 
24 
25 typedef intptr_t gpr_atm;
26 #define GPR_ATM_MAX INTPTR_MAX
27 #define GPR_ATM_MIN INTPTR_MIN
28 
29 #define gpr_atm_full_barrier MemoryBarrier
30 
31 static __inline gpr_atm gpr_atm_acq_load(const gpr_atm* p) {
32  gpr_atm result = *p;
34  return result;
35 }
36 
37 static __inline gpr_atm gpr_atm_no_barrier_load(const gpr_atm* p) {
38  /* TODO(dklempner): Can we implement something better here? */
39  return gpr_atm_acq_load(p);
40 }
41 
42 static __inline void gpr_atm_rel_store(gpr_atm* p, gpr_atm value) {
44  *p = value;
45 }
46 
47 static __inline void gpr_atm_no_barrier_store(gpr_atm* p, gpr_atm value) {
48  /* TODO(ctiller): Can we implement something better here? */
49  gpr_atm_rel_store(p, value);
50 }
51 
52 static __inline int gpr_atm_no_barrier_cas(gpr_atm* p, gpr_atm o, gpr_atm n) {
55 #ifdef GPR_ARCH_64
56  return o == (gpr_atm)InterlockedCompareExchangeAcquire64(
57  (volatile LONGLONG*)p, (LONGLONG)n, (LONGLONG)o);
58 #else
59  return o == (gpr_atm)InterlockedCompareExchangeAcquire((volatile LONG*)p,
60  (LONG)n, (LONG)o);
61 #endif
62 }
63 
64 static __inline int gpr_atm_acq_cas(gpr_atm* p, gpr_atm o, gpr_atm n) {
65 #ifdef GPR_ARCH_64
66  return o == (gpr_atm)InterlockedCompareExchangeAcquire64(
67  (volatile LONGLONG*)p, (LONGLONG)n, (LONGLONG)o);
68 #else
69  return o == (gpr_atm)InterlockedCompareExchangeAcquire((volatile LONG*)p,
70  (LONG)n, (LONG)o);
71 #endif
72 }
73 
74 static __inline int gpr_atm_rel_cas(gpr_atm* p, gpr_atm o, gpr_atm n) {
75 #ifdef GPR_ARCH_64
76  return o == (gpr_atm)InterlockedCompareExchangeRelease64(
77  (volatile LONGLONG*)p, (LONGLONG)n, (LONGLONG)o);
78 #else
79  return o == (gpr_atm)InterlockedCompareExchangeRelease((volatile LONG*)p,
80  (LONG)n, (LONG)o);
81 #endif
82 }
83 
84 static __inline int gpr_atm_full_cas(gpr_atm* p, gpr_atm o, gpr_atm n) {
85 #ifdef GPR_ARCH_64
86  return o == (gpr_atm)InterlockedCompareExchange64((volatile LONGLONG*)p,
87  (LONGLONG)n, (LONGLONG)o);
88 #else
89  return o == (gpr_atm)InterlockedCompareExchange((volatile LONG*)p, (LONG)n,
90  (LONG)o);
91 #endif
92 }
93 
95  gpr_atm delta) {
97  gpr_atm old;
98  do {
99  old = *p;
100  } while (!gpr_atm_no_barrier_cas(p, old, old + delta));
101  return old;
102 }
103 
104 static __inline gpr_atm gpr_atm_full_fetch_add(gpr_atm* p, gpr_atm delta) {
106  gpr_atm old;
107 #ifdef GPR_ARCH_64
108  do {
109  old = *p;
110  } while (old != (gpr_atm)InterlockedCompareExchange64((volatile LONGLONG*)p,
111  (LONGLONG)old + delta,
112  (LONGLONG)old));
113 #else
114  do {
115  old = *p;
116  } while (old != (gpr_atm)InterlockedCompareExchange(
117  (volatile LONG*)p, (LONG)old + delta, (LONG)old));
118 #endif
119  return old;
120 }
121 
122 static __inline gpr_atm gpr_atm_full_xchg(gpr_atm* p, gpr_atm n) {
123  return (gpr_atm)InterlockedExchangePointer((PVOID*)p, (PVOID)n);
124 }
125 
126 #endif /* GRPC_IMPL_CODEGEN_ATM_WINDOWS_H */
#define gpr_atm_no_barrier_load(p)
Definition: atm_gcc_atomic.h:51
#define gpr_atm_full_fetch_add(p, delta)
Definition: atm_gcc_atomic.h:60
#define gpr_atm_no_barrier_store(p, value)
Definition: atm_gcc_atomic.h:54
#define gpr_atm_acq_cas(p, o, n)
Definition: atm_gcc_sync.h:71
#define gpr_atm_full_xchg(p, n)
Definition: atm_gcc_atomic.h:84
#define gpr_atm_full_cas(p, o, n)
Definition: atm_gcc_sync.h:73
#define gpr_atm_rel_cas(p, o, n)
Definition: atm_gcc_sync.h:72
#define gpr_atm_acq_load(p)
Definition: atm_gcc_atomic.h:50
#define gpr_atm_rel_store(p, value)
Definition: atm_gcc_atomic.h:52
#define gpr_atm_no_barrier_fetch_add(p, delta)
Definition: atm_gcc_atomic.h:57
intptr_t gpr_atm
Definition: atm_gcc_atomic.h:30
#define gpr_atm_no_barrier_cas(p, o, n)
Definition: atm_gcc_sync.h:70
intptr_t gpr_atm
Win32 variant of atm_platform.h.
Definition: atm_windows.h:25
#define gpr_atm_full_barrier
Definition: atm_windows.h:29