1b32f58018498ea2225959b0ba11c18f0c433deefEvgeniy Stepanov/* ThreadSanitizer
2b32f58018498ea2225959b0ba11c18f0c433deefEvgeniy Stepanov * Copyright (c) 2011, Google Inc. All rights reserved.
3b32f58018498ea2225959b0ba11c18f0c433deefEvgeniy Stepanov *
4b32f58018498ea2225959b0ba11c18f0c433deefEvgeniy Stepanov * Redistribution and use in source and binary forms, with or without
5b32f58018498ea2225959b0ba11c18f0c433deefEvgeniy Stepanov * modification, are permitted provided that the following conditions are met:
6b32f58018498ea2225959b0ba11c18f0c433deefEvgeniy Stepanov *
7b32f58018498ea2225959b0ba11c18f0c433deefEvgeniy Stepanov *     * Redistributions of source code must retain the above copyright
8b32f58018498ea2225959b0ba11c18f0c433deefEvgeniy Stepanov * notice, this list of conditions and the following disclaimer.
9b32f58018498ea2225959b0ba11c18f0c433deefEvgeniy Stepanov *     * Neither the name of Google Inc. nor the names of its
10b32f58018498ea2225959b0ba11c18f0c433deefEvgeniy Stepanov * contributors may be used to endorse or promote products derived from
11b32f58018498ea2225959b0ba11c18f0c433deefEvgeniy Stepanov * this software without specific prior written permission.
12b32f58018498ea2225959b0ba11c18f0c433deefEvgeniy Stepanov *
13b32f58018498ea2225959b0ba11c18f0c433deefEvgeniy Stepanov * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
14b32f58018498ea2225959b0ba11c18f0c433deefEvgeniy Stepanov * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
15b32f58018498ea2225959b0ba11c18f0c433deefEvgeniy Stepanov * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
16b32f58018498ea2225959b0ba11c18f0c433deefEvgeniy Stepanov * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
17b32f58018498ea2225959b0ba11c18f0c433deefEvgeniy Stepanov * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
18b32f58018498ea2225959b0ba11c18f0c433deefEvgeniy Stepanov * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
19b32f58018498ea2225959b0ba11c18f0c433deefEvgeniy Stepanov * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
20b32f58018498ea2225959b0ba11c18f0c433deefEvgeniy Stepanov * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
21b32f58018498ea2225959b0ba11c18f0c433deefEvgeniy Stepanov * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22b32f58018498ea2225959b0ba11c18f0c433deefEvgeniy Stepanov * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23b32f58018498ea2225959b0ba11c18f0c433deefEvgeniy Stepanov * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24b32f58018498ea2225959b0ba11c18f0c433deefEvgeniy Stepanov */
25b32f58018498ea2225959b0ba11c18f0c433deefEvgeniy Stepanov
26b32f58018498ea2225959b0ba11c18f0c433deefEvgeniy Stepanov#ifndef TS_ATOMIC_H_INCLUDED
27b32f58018498ea2225959b0ba11c18f0c433deefEvgeniy Stepanov#define TS_ATOMIC_H_INCLUDED
28b32f58018498ea2225959b0ba11c18f0c433deefEvgeniy Stepanov
29b32f58018498ea2225959b0ba11c18f0c433deefEvgeniy Stepanov#ifdef __cplusplus
30b32f58018498ea2225959b0ba11c18f0c433deefEvgeniy Stepanovextern "C" {
31b32f58018498ea2225959b0ba11c18f0c433deefEvgeniy Stepanov#endif
32b32f58018498ea2225959b0ba11c18f0c433deefEvgeniy Stepanov
33b32f58018498ea2225959b0ba11c18f0c433deefEvgeniy Stepanov
34b32f58018498ea2225959b0ba11c18f0c433deefEvgeniy Stepanov// These constants mostly mimic ones from C++0x standard draft.
35b32f58018498ea2225959b0ba11c18f0c433deefEvgeniy Stepanov// The most recent version of the draft (as of now) can be found here:
36b32f58018498ea2225959b0ba11c18f0c433deefEvgeniy Stepanov// http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2011/n3242.pdf
37b32f58018498ea2225959b0ba11c18f0c433deefEvgeniy Stepanov// Check out fresh versions here:
38b32f58018498ea2225959b0ba11c18f0c433deefEvgeniy Stepanov// http://www.open-std.org/jtc1/sc22/wg21/docs/papers/
39b32f58018498ea2225959b0ba11c18f0c433deefEvgeniy Stepanov// Refer to sections 1.10 and 29.
40b32f58018498ea2225959b0ba11c18f0c433deefEvgeniy Stepanov//
41b32f58018498ea2225959b0ba11c18f0c433deefEvgeniy Stepanov// tsan_memory_order_invalid has no meaning other than invalid enum value.
42b32f58018498ea2225959b0ba11c18f0c433deefEvgeniy Stepanov// tsan_memory_order_natomic stands for "non atomic" and expresses
43b32f58018498ea2225959b0ba11c18f0c433deefEvgeniy Stepanov// as if plain memory access that is not intended to race
44b32f58018498ea2225959b0ba11c18f0c433deefEvgeniy Stepanov// with other accesses.
45b32f58018498ea2225959b0ba11c18f0c433deefEvgeniy Stepanovtypedef enum tsan_memory_order {
46b32f58018498ea2225959b0ba11c18f0c433deefEvgeniy Stepanov  tsan_memory_order_invalid = 0,
47b32f58018498ea2225959b0ba11c18f0c433deefEvgeniy Stepanov  tsan_memory_order_natomic = 1 << 0,
48b32f58018498ea2225959b0ba11c18f0c433deefEvgeniy Stepanov  tsan_memory_order_relaxed = 1 << 1,
49b32f58018498ea2225959b0ba11c18f0c433deefEvgeniy Stepanov  tsan_memory_order_consume = 1 << 2,
50b32f58018498ea2225959b0ba11c18f0c433deefEvgeniy Stepanov  tsan_memory_order_acquire = 1 << 3,
51b32f58018498ea2225959b0ba11c18f0c433deefEvgeniy Stepanov  tsan_memory_order_release = 1 << 4,
52b32f58018498ea2225959b0ba11c18f0c433deefEvgeniy Stepanov  tsan_memory_order_acq_rel = 1 << 5,
53b32f58018498ea2225959b0ba11c18f0c433deefEvgeniy Stepanov  tsan_memory_order_seq_cst = 1 << 6
54b32f58018498ea2225959b0ba11c18f0c433deefEvgeniy Stepanov} tsan_memory_order;
55b32f58018498ea2225959b0ba11c18f0c433deefEvgeniy Stepanov
56b32f58018498ea2225959b0ba11c18f0c433deefEvgeniy Stepanov
57b32f58018498ea2225959b0ba11c18f0c433deefEvgeniy Stepanov// These constants express types of atomic memory operations
58b32f58018498ea2225959b0ba11c18f0c433deefEvgeniy Stepanov// as defined by C++0x standard draft (section 29).
59b32f58018498ea2225959b0ba11c18f0c433deefEvgeniy Stepanov//
60b32f58018498ea2225959b0ba11c18f0c433deefEvgeniy Stepanov// tsan_atomic_op_invalid has no meaning other than invalid enum value.
61b32f58018498ea2225959b0ba11c18f0c433deefEvgeniy Stepanov// compare_exchange_weak differs from compare_exchange_strong in that
62b32f58018498ea2225959b0ba11c18f0c433deefEvgeniy Stepanov// it can fail spuriously.
63b32f58018498ea2225959b0ba11c18f0c433deefEvgeniy Stepanovtypedef enum tsan_atomic_op {
64b32f58018498ea2225959b0ba11c18f0c433deefEvgeniy Stepanov  tsan_atomic_op_invalid = 0,
65b32f58018498ea2225959b0ba11c18f0c433deefEvgeniy Stepanov  tsan_atomic_op_fence = 1 << 0,
66b32f58018498ea2225959b0ba11c18f0c433deefEvgeniy Stepanov  tsan_atomic_op_load = 1 << 1,
67b32f58018498ea2225959b0ba11c18f0c433deefEvgeniy Stepanov  tsan_atomic_op_store = 1 << 2,
68b32f58018498ea2225959b0ba11c18f0c433deefEvgeniy Stepanov  tsan_atomic_op_exchange = 1 << 3,
69b32f58018498ea2225959b0ba11c18f0c433deefEvgeniy Stepanov  tsan_atomic_op_fetch_add = 1 << 4,
70b32f58018498ea2225959b0ba11c18f0c433deefEvgeniy Stepanov  tsan_atomic_op_fetch_sub = 1 << 5,
71b32f58018498ea2225959b0ba11c18f0c433deefEvgeniy Stepanov  tsan_atomic_op_fetch_and  = 1 << 6,
72b32f58018498ea2225959b0ba11c18f0c433deefEvgeniy Stepanov  tsan_atomic_op_fetch_xor = 1 << 7,
73b32f58018498ea2225959b0ba11c18f0c433deefEvgeniy Stepanov  tsan_atomic_op_fetch_or = 1 << 8,
74b32f58018498ea2225959b0ba11c18f0c433deefEvgeniy Stepanov  tsan_atomic_op_compare_exchange_weak = 1 << 9,
75b32f58018498ea2225959b0ba11c18f0c433deefEvgeniy Stepanov  tsan_atomic_op_compare_exchange_strong = 1 << 10
76b32f58018498ea2225959b0ba11c18f0c433deefEvgeniy Stepanov} tsan_atomic_op;
77b32f58018498ea2225959b0ba11c18f0c433deefEvgeniy Stepanov
78b32f58018498ea2225959b0ba11c18f0c433deefEvgeniy Stepanov
79b32f58018498ea2225959b0ba11c18f0c433deefEvgeniy Stepanov#ifdef __cplusplus
80b32f58018498ea2225959b0ba11c18f0c433deefEvgeniy Stepanov}
81b32f58018498ea2225959b0ba11c18f0c433deefEvgeniy Stepanov#endif
82b32f58018498ea2225959b0ba11c18f0c433deefEvgeniy Stepanov
83b32f58018498ea2225959b0ba11c18f0c433deefEvgeniy Stepanov#endif // #ifndef TS_ATOMIC_H_INCLUDED
84b32f58018498ea2225959b0ba11c18f0c433deefEvgeniy Stepanov
85b32f58018498ea2225959b0ba11c18f0c433deefEvgeniy Stepanov
86