Skip to content

Commit 3e6ce01

Browse files
committed
Add helgrind and drd annotations to critnib data strcture
1 parent a339b1f commit 3e6ce01

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

src/utils/utils_concurrency.h

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
#include <stdatomic.h>
1919
#endif
2020

21+
#include "utils_sanitizers.h"
22+
2123
#ifdef __cplusplus
2224
extern "C" {
2325
#endif
@@ -72,9 +74,17 @@ static __inline unsigned char util_mssb_index(long long value) {
7274
#define util_lssb_index(x) ((unsigned char)__builtin_ctzll(x))
7375
#define util_mssb_index(x) ((unsigned char)(63 - __builtin_clzll(x)))
7476
#define util_atomic_load_acquire(object, dest) \
75-
__atomic_load(object, dest, memory_order_acquire)
77+
do { \
78+
utils_annotate_acquire((void *)object); \
79+
__atomic_load(object, dest, memory_order_acquire); \
80+
} while (0)
81+
7682
#define util_atomic_store_release(object, desired) \
77-
__atomic_store_n(object, desired, memory_order_release)
83+
do { \
84+
__atomic_store_n(object, desired, memory_order_release); \
85+
utils_annotate_release((void *)dst); \
86+
} while (0)
87+
7888
#define util_atomic_increment(object) \
7989
__atomic_add_fetch(object, 1, __ATOMIC_ACQ_REL)
8090
#endif

src/utils/utils_sanitizers.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
*
88
*/
99

10+
#ifndef UMF_UTILS_SANITIZERS_H
11+
#define UMF_UTILS_SANITIZERS_H 1
12+
1013
#if defined(__has_feature)
1114
#if __has_feature(thread_sanitizer)
1215
#ifndef __SANITIZE_THREAD__
@@ -113,6 +116,8 @@ extern "C" {
113116
static inline void utils_annotate_acquire(void *ptr) {
114117
#if __SANITIZE_THREAD__
115118
__tsan_acquire(ptr);
119+
#elif UMF_VG_HELGRIND_ENABLED || UMF_VG_DRD_ENABLED
120+
ANNOTATE_HAPPENS_AFTER(ptr);
116121
#else
117122
(void)ptr;
118123
#endif
@@ -121,6 +126,8 @@ static inline void utils_annotate_acquire(void *ptr) {
121126
static inline void utils_annotate_release(void *ptr) {
122127
#if __SANITIZE_THREAD__
123128
__tsan_release(ptr);
129+
#elif UMF_VG_HELGRIND_ENABLED || UMF_VG_DRD_ENABLED
130+
ANNOTATE_HAPPENS_BEFORE(ptr);
124131
#else
125132
(void)ptr;
126133
#endif
@@ -164,3 +171,5 @@ static inline void utils_annotate_memory_inaccessible(void *ptr, size_t size) {
164171
#ifdef __cplusplus
165172
}
166173
#endif
174+
175+
#endif /* UMF_UTILS_SANITIZERS_H */

0 commit comments

Comments
 (0)