Merge pull request #5714 from alexischr/update_bockbuild
[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  * Please keep this file and its methods organised:
7  *  * Increment, Decrement, Add, Subtract, Write, Read
8  *  * gint32 (""), guint32 ("Unsigned"),
9  *      gint64 ("64"), guint64 ("Unsigned64"),
10  *      gsize ("Size"), gboolean ("Bool")
11  *
12  * Licensed under the MIT license. See LICENSE file in the project root for full license information.
13  */
14
15 #ifndef _UNLOCKED_H_
16 #define _UNLOCKED_H_
17
18 #include <glib.h>
19 #include <mono/utils/mono-compiler.h>
20
21 #if MONO_HAS_CLANG_THREAD_SANITIZER
22 #define MONO_UNLOCKED_ATTRS MONO_NO_SANITIZE_THREAD MONO_NEVER_INLINE static
23 #elif defined(_MSC_VER)
24 #define MONO_UNLOCKED_ATTRS MONO_ALWAYS_INLINE static
25 #else
26 #define MONO_UNLOCKED_ATTRS MONO_ALWAYS_INLINE static inline
27 #endif
28
29 MONO_UNLOCKED_ATTRS
30 gint32
31 UnlockedIncrement (gint32 *val)
32 {
33         return ++*val;
34 }
35
36 MONO_UNLOCKED_ATTRS
37 gint64
38 UnlockedIncrement64 (gint64 *val)
39 {
40         return ++*val;
41 }
42
43 MONO_UNLOCKED_ATTRS
44 gint64
45 UnlockedDecrement64 (gint64 *val)
46 {
47         return --*val;
48 }
49
50 MONO_UNLOCKED_ATTRS
51 gint32
52 UnlockedDecrement (gint32 *val)
53 {
54         return --*val;
55 }
56
57 MONO_UNLOCKED_ATTRS
58 gint32
59 UnlockedAdd (gint32 *dest, gint32 add)
60 {
61         return *dest += add;
62 }
63
64 MONO_UNLOCKED_ATTRS
65 gint64
66 UnlockedAdd64 (gint64 *dest, gint64 add)
67 {
68         return *dest += add;
69 }
70
71 MONO_UNLOCKED_ATTRS
72 gdouble
73 UnlockedAddDouble (gdouble *dest, gdouble add)
74 {
75         return *dest += add;
76 }
77
78 MONO_UNLOCKED_ATTRS
79 gint64
80 UnlockedSubtract64 (gint64 *dest, gint64 sub)
81 {
82         return *dest -= sub;
83 }
84
85 MONO_UNLOCKED_ATTRS
86 void
87 UnlockedWrite (gint32 *dest, gint32 val)
88 {
89         *dest = val;
90 }
91
92 MONO_UNLOCKED_ATTRS
93 void
94 UnlockedWrite64 (gint64 *dest, gint64 val)
95 {
96         *dest = val;
97 }
98
99 MONO_UNLOCKED_ATTRS
100 void
101 UnlockedWriteBool (gboolean *dest, gboolean val)
102 {
103         *dest = val;
104 }
105
106 MONO_UNLOCKED_ATTRS
107 gint32
108 UnlockedRead (gint32 *src)
109 {
110         return *src;
111 }
112
113 MONO_UNLOCKED_ATTRS
114 gint64
115 UnlockedRead64 (gint64 *src)
116 {
117         return *src;
118 }
119
120 MONO_UNLOCKED_ATTRS
121 gboolean
122 UnlockedReadBool (gboolean *src)
123 {
124         return *src;
125 }
126
127 MONO_UNLOCKED_ATTRS
128 gpointer
129 UnlockedReadPointer (volatile gpointer *src)
130 {
131         return *src;
132 }
133
134 #endif /* _UNLOCKED_H_ */