Use the `Unlocked* ()` functions to blacklist specific load / store operations (...
[mono.git] / mono / utils / unlocked.h
1 /**
2  * \file
3  * Contains inline functions to explicitly mark data races that should not be changed.
4  * This way, instruments like Clang's ThreadSanitizer can be told to ignore very specific instructions.
5  *
6  * Licensed under the MIT license. See LICENSE file in the project root for full license information.
7  */
8
9 #ifndef _UNLOCKED_H_
10 #define _UNLOCKED_H_
11
12 #include <glib.h>
13 #include <mono/utils/mono-compiler.h>
14
15 #if MONO_HAS_CLANG_THREAD_SANITIZER
16 #define MONO_UNLOCKED_ATTRS MONO_NO_SANITIZE_THREAD MONO_NEVER_INLINE static
17 #else
18 #define MONO_UNLOCKED_ATTRS MONO_ALWAYS_INLINE static inline
19 #endif
20
21 MONO_UNLOCKED_ATTRS
22 gint32
23 UnlockedIncrement (gint32 *val)
24 {
25         return ++*val;
26 }
27
28 MONO_UNLOCKED_ATTRS
29 gint64
30 UnlockedIncrement64 (gint64 *val)
31 {
32         return ++*val;
33 }
34
35 MONO_UNLOCKED_ATTRS
36 gsize
37 UnlockedIncrementSize (gsize *val)
38 {
39         return ++*val;
40 }
41
42 MONO_UNLOCKED_ATTRS
43 gint64
44 UnlockedAdd64 (gint64 *dest, gint64 add)
45 {
46         return *dest += add;
47 }
48
49 MONO_UNLOCKED_ATTRS
50 gint64
51 UnlockedSubtract64 (gint64 *dest, gint64 sub)
52 {
53         return *dest -= sub;
54 }
55
56 MONO_UNLOCKED_ATTRS
57 gint64
58 UnlockedRead64 (gint64 *src)
59 {
60         return *src;
61 }
62
63 #endif /* _UNLOCKED_H_ */