[TSan] Yet another idea about whitelisting data races (#5310)
[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 #endif /* _UNLOCKED_H_ */