[netcore] Reorder test targets
[mono-project.git] / mono / utils / unlocked.h
blobf55e08c959a508a4a5881b03fbc148739177538e
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.
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 * gpointer ("Pointer")
13 * Licensed under the MIT license. See LICENSE file in the project root for full license information.
16 #ifndef _UNLOCKED_H_
17 #define _UNLOCKED_H_
19 #include <glib.h>
20 #include <mono/utils/mono-compiler.h>
22 #if MONO_HAS_CLANG_THREAD_SANITIZER
23 #define MONO_UNLOCKED_ATTRS MONO_NO_SANITIZE_THREAD MONO_NEVER_INLINE static
24 #elif defined(_MSC_VER)
25 #define MONO_UNLOCKED_ATTRS MONO_ALWAYS_INLINE static
26 #else
27 #define MONO_UNLOCKED_ATTRS MONO_ALWAYS_INLINE static inline
28 #endif
30 MONO_UNLOCKED_ATTRS
31 gint32
32 UnlockedIncrement (volatile gint32 *val)
34 return ++*val;
37 MONO_UNLOCKED_ATTRS
38 gint64
39 UnlockedIncrement64 (volatile gint64 *val)
41 return ++*val;
44 MONO_UNLOCKED_ATTRS
45 gint64
46 UnlockedDecrement64 (volatile gint64 *val)
48 return --*val;
51 MONO_UNLOCKED_ATTRS
52 gint32
53 UnlockedDecrement (volatile gint32 *val)
55 return --*val;
58 MONO_UNLOCKED_ATTRS
59 gint32
60 UnlockedAdd (volatile gint32 *dest, gint32 add)
62 return *dest += add;
65 MONO_UNLOCKED_ATTRS
66 gint64
67 UnlockedAdd64 (volatile gint64 *dest, gint64 add)
69 return *dest += add;
72 MONO_UNLOCKED_ATTRS
73 gdouble
74 UnlockedAddDouble (volatile gdouble *dest, gdouble add)
76 return *dest += add;
79 MONO_UNLOCKED_ATTRS
80 gint64
81 UnlockedSubtract64 (volatile gint64 *dest, gint64 sub)
83 return *dest -= sub;
86 MONO_UNLOCKED_ATTRS
87 void
88 UnlockedWrite (volatile gint32 *dest, gint32 val)
90 *dest = val;
93 MONO_UNLOCKED_ATTRS
94 void
95 UnlockedWrite64 (volatile gint64 *dest, gint64 val)
97 *dest = val;
100 MONO_UNLOCKED_ATTRS
101 void
102 UnlockedWriteBool (volatile gboolean *dest, gboolean val)
104 *dest = val;
107 MONO_UNLOCKED_ATTRS
108 void
109 UnlockedWritePointer (volatile gpointer *dest, gpointer val)
111 *dest = val;
114 MONO_UNLOCKED_ATTRS
115 gint32
116 UnlockedRead (volatile gint32 *src)
118 return *src;
121 MONO_UNLOCKED_ATTRS
122 gint64
123 UnlockedRead64 (volatile gint64 *src)
125 return *src;
128 MONO_UNLOCKED_ATTRS
129 gboolean
130 UnlockedReadBool (volatile gboolean *src)
132 return *src;
135 MONO_UNLOCKED_ATTRS
136 gpointer
137 UnlockedReadPointer (volatile gpointer *src)
139 return *src;
142 #endif /* _UNLOCKED_H_ */