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