blob: 5376026dde2ef6a49e135d7988b9ba2febd76b9a [file] [log] [blame]
David Garcia Quintas2425bbb2016-01-25 17:32:48 -08001/*
2 *
Craig Tiller6169d5f2016-03-31 07:46:18 -07003 * Copyright 2015, Google Inc.
David Garcia Quintas2425bbb2016-01-25 17:32:48 -08004 * 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_IMPL_CODEGEN_ATM_H
35#define GRPC_IMPL_CODEGEN_ATM_H
36
37/* This interface provides atomic operations and barriers.
38 It is internal to gpr support code and should not be used outside it.
39
40 If an operation with acquire semantics precedes another memory access by the
41 same thread, the operation will precede that other access as seen by other
42 threads.
43
44 If an operation with release semantics follows another memory access by the
45 same thread, the operation will follow that other access as seen by other
46 threads.
47
48 Routines with "acq" or "full" in the name have acquire semantics. Routines
49 with "rel" or "full" in the name have release semantics. Routines with
50 "no_barrier" in the name have neither acquire not release semantics.
51
52 The routines may be implemented as macros.
53
54 // Atomic operations act on an intergral_type gpr_atm that is guaranteed to
55 // be the same size as a pointer.
56 typedef intptr_t gpr_atm;
57
58 // A memory barrier, providing both acquire and release semantics, but not
59 // otherwise acting on memory.
60 void gpr_atm_full_barrier(void);
61
62 // Atomically return *p, with acquire semantics.
63 gpr_atm gpr_atm_acq_load(gpr_atm *p);
64
65 // Atomically set *p = value, with release semantics.
66 void gpr_atm_rel_store(gpr_atm *p, gpr_atm value);
67
68 // Atomically add delta to *p, and return the old value of *p, with
69 // the barriers specified.
70 gpr_atm gpr_atm_no_barrier_fetch_add(gpr_atm *p, gpr_atm delta);
71 gpr_atm gpr_atm_full_fetch_add(gpr_atm *p, gpr_atm delta);
72
73 // Atomically, if *p==o, set *p=n and return non-zero otherwise return 0,
74 // with the barriers specified if the operation succeeds.
75 int gpr_atm_no_barrier_cas(gpr_atm *p, gpr_atm o, gpr_atm n);
76 int gpr_atm_acq_cas(gpr_atm *p, gpr_atm o, gpr_atm n);
77 int gpr_atm_rel_cas(gpr_atm *p, gpr_atm o, gpr_atm n);
78*/
79
80#include <grpc/impl/codegen/port_platform.h>
81
82#if defined(GPR_GCC_ATOMIC)
83#include <grpc/impl/codegen/atm_gcc_atomic.h>
84#elif defined(GPR_GCC_SYNC)
85#include <grpc/impl/codegen/atm_gcc_sync.h>
86#elif defined(GPR_WIN32_ATOMIC)
87#include <grpc/impl/codegen/atm_win32.h>
88#else
89#error could not determine platform for atm
90#endif
91
92#endif /* GRPC_IMPL_CODEGEN_ATM_H */