[utils] Fix inet_pton fallback.
[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 #else
24 #define MONO_UNLOCKED_ATTRS MONO_ALWAYS_INLINE static inline
25 #endif
26
27 MONO_UNLOCKED_ATTRS
28 gint32
29 UnlockedIncrement (gint32 *val)
30 {
31         return ++*val;
32 }
33
34 MONO_UNLOCKED_ATTRS
35 gint32
36 UnlockedAdd (gint32 *dest, gint32 add)
37 {
38         return *dest += add;
39 }
40
41 MONO_UNLOCKED_ATTRS
42 gint64
43 UnlockedAdd64 (gint64 *dest, gint64 add)
44 {
45         return *dest += add;
46 }
47
48 MONO_UNLOCKED_ATTRS
49 gint64
50 UnlockedSubtract64 (gint64 *dest, gint64 sub)
51 {
52         return *dest -= sub;
53 }
54
55 MONO_UNLOCKED_ATTRS
56 void
57 UnlockedWrite (gint32 *dest, gint32 val)
58 {
59         *dest = val;
60 }
61
62 MONO_UNLOCKED_ATTRS
63 gint32
64 UnlockedRead (gint32 *src)
65 {
66         return *src;
67 }
68
69 MONO_UNLOCKED_ATTRS
70 gint64
71 UnlockedRead64 (gint64 *src)
72 {
73         return *src;
74 }
75
76 #endif /* _UNLOCKED_H_ */