GRPC Core 0.10.0.0

- Main Page
- Data Structures
- Files

- File List
- Globals

All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
atm_win32.h
Go to the documentation of this file.
1 /*
2 *
3 * Copyright 2015, Google Inc.
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are
8 * met:
9 *
10 * * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * * Redistributions in binary form must reproduce the above
13 * copyright notice, this list of conditions and the following disclaimer
14 * in the documentation and/or other materials provided with the
15 * distribution.
16 * * Neither the name of Google Inc. nor the names of its
17 * contributors may be used to endorse or promote products derived from
18 * this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 *
32 */
33
34 #ifndef GRPC_SUPPORT_ATM_WIN32_H
35 #define GRPC_SUPPORT_ATM_WIN32_H
36
37 /* Win32 variant of atm_platform.h */
38 #include <grpc/support/port_platform.h>
39
40 typedef gpr_intptr gpr_atm;
41
42 #define gpr_atm_full_barrier MemoryBarrier
43
44 static __inline gpr_atm gpr_atm_acq_load(const gpr_atm *p) {
45 gpr_atm result = *p;
46 gpr_atm_full_barrier();
47 return result;
48 }
49
50 static __inline gpr_atm gpr_atm_no_barrier_load(const gpr_atm *p) {
51 /* TODO(dklempner): Can we implement something better here? */
52 return gpr_atm_acq_load(p);
53 }
54
55 static __inline void gpr_atm_rel_store(gpr_atm *p, gpr_atm value) {
56 gpr_atm_full_barrier();
57 *p = value;
58 }
59
60 static __inline void gpr_atm_no_barrier_store(gpr_atm *p, gpr_atm value) {
61 /* TODO(ctiller): Can we implement something better here? */
62 gpr_atm_rel_store(p, value);
63 }
64
65 static __inline int gpr_atm_no_barrier_cas(gpr_atm *p, gpr_atm o, gpr_atm n) {
66 /* InterlockedCompareExchangePointerNoFence() not available on vista or
67 windows7 */
68 #ifdef GPR_ARCH_64
69 return o == (gpr_atm)InterlockedCompareExchangeAcquire64((volatile LONGLONG *) p,
70 (LONGLONG) n, (LONGLONG) o);
71 #else
72 return o == (gpr_atm)InterlockedCompareExchangeAcquire((volatile LONG *) p,
73 (LONG) n, (LONG) o);
74 #endif
75 }
76
77 static __inline int gpr_atm_acq_cas(gpr_atm *p, gpr_atm o, gpr_atm n) {
78 #ifdef GPR_ARCH_64
79 return o == (gpr_atm)InterlockedCompareExchangeAcquire64((volatile LONGLONG *) p,
80 (LONGLONG) n, (LONGLONG) o);
81 #else
82 return o == (gpr_atm)InterlockedCompareExchangeAcquire((volatile LONG *) p,
83 (LONG) n, (LONG) o);
84 #endif
85 }
86
87 static __inline int gpr_atm_rel_cas(gpr_atm *p, gpr_atm o, gpr_atm n) {
88 #ifdef GPR_ARCH_64
89 return o == (gpr_atm)InterlockedCompareExchangeRelease64((volatile LONGLONG *) p,
90 (LONGLONG) n, (LONGLONG) o);
91 #else
92 return o == (gpr_atm)InterlockedCompareExchangeRelease((volatile LONG *) p,
93 (LONG) n, (LONG) o);
94 #endif
95 }
96
97 static __inline gpr_atm gpr_atm_no_barrier_fetch_add(gpr_atm *p,
98 gpr_atm delta) {
99 /* Use the CAS operation to get pointer-sized fetch and add */
100 gpr_atm old;
101 do {
102 old = *p;
103 } while (!gpr_atm_no_barrier_cas(p, old, old + delta));
104 return old;
105 }
106
107 static __inline gpr_atm gpr_atm_full_fetch_add(gpr_atm *p, gpr_atm delta) {
108 /* Use a CAS operation to get pointer-sized fetch and add */
109 gpr_atm old;
110 #ifdef GPR_ARCH_64
111 do {
112 old = *p;
113 } while (old != (gpr_atm)InterlockedCompareExchange64((volatile LONGLONG *) p,
114 (LONGLONG) old + delta,
115 (LONGLONG) old));
116 #else
117 do {
118 old = *p;
119 } while (old != (gpr_atm)InterlockedCompareExchange((volatile LONG *) p,
120 (LONG) old + delta,
121 (LONG) old));
122 #endif
123 return old;
124 }
125
126 #endif /* GRPC_SUPPORT_ATM_WIN32_H */
value
const char * value
Definition: hpack_table.c:44
port_platform.h
gpr_intptr
intptr_t gpr_intptr
Definition: port_platform.h:312
gpr_atm_no_barrier_fetch_add
#define gpr_atm_no_barrier_fetch_add(p, delta)
Definition: atm_gcc_atomic.h:52
gpr_atm_acq_load
#define gpr_atm_acq_load(p)
Definition: atm_gcc_atomic.h:45
gpr_atm_no_barrier_load
#define gpr_atm_no_barrier_load(p)
Definition: atm_gcc_atomic.h:46
gpr_atm_acq_cas
#define gpr_atm_acq_cas(p, o, n)
Definition: atm_gcc_sync.h:84
gpr_atm_full_fetch_add
#define gpr_atm_full_fetch_add(p, delta)
Definition: atm_gcc_atomic.h:54
gpr_atm_no_barrier_store
#define gpr_atm_no_barrier_store(p, value)
Definition: atm_gcc_atomic.h:49
gpr_atm_rel_store
#define gpr_atm_rel_store(p, value)
Definition: atm_gcc_atomic.h:47
gpr_atm_no_barrier_cas
#define gpr_atm_no_barrier_cas(p, o, n)
Definition: atm_gcc_sync.h:83
gpr_atm_rel_cas
#define gpr_atm_rel_cas(p, o, n)
Definition: atm_gcc_sync.h:85
gpr_atm
gpr_intptr gpr_atm
Definition: atm_win32.h:40
gpr_atm
gpr_intptr gpr_atm
Definition: atm_gcc_atomic.h:41
gpr_atm_full_barrier
#define gpr_atm_full_barrier
Definition: atm_win32.h:42