1
1
/*
2
2
*
3
- * Copyright (C) 2023 Intel Corporation
3
+ * Copyright (C) 2023-2024 Intel Corporation
4
4
*
5
5
* Under the Apache License v2.0 with LLVM Exceptions. See LICENSE.TXT.
6
6
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
24
24
#include <tbb/scalable_allocator.h>
25
25
26
26
#include "utils_common.h"
27
+ #include "utils_sanitizers.h"
27
28
28
29
typedef void * (* raw_alloc_tbb_type )(intptr_t , size_t * );
29
30
typedef void (* raw_free_tbb_type )(intptr_t , void * , size_t );
@@ -179,6 +180,7 @@ static void *tbb_malloc(void *pool, size_t size) {
179
180
}
180
181
return NULL ;
181
182
}
183
+ utils_annotate_acquire (pool );
182
184
return ptr ;
183
185
}
184
186
@@ -205,6 +207,7 @@ static void *tbb_realloc(void *pool, void *ptr, size_t size) {
205
207
}
206
208
return NULL ;
207
209
}
210
+ utils_annotate_acquire (pool );
208
211
return new_ptr ;
209
212
}
210
213
@@ -219,6 +222,7 @@ static void *tbb_aligned_malloc(void *pool, size_t size, size_t alignment) {
219
222
}
220
223
return NULL ;
221
224
}
225
+ utils_annotate_acquire (pool );
222
226
return ptr ;
223
227
}
224
228
@@ -229,6 +233,12 @@ static umf_result_t tbb_free(void *pool, void *ptr) {
229
233
230
234
TLS_last_free_error = UMF_RESULT_SUCCESS ;
231
235
236
+ // Establishes happens-before order with tbb_*alloc functions.
237
+ // Makes sure that writes to the memory pointed to by 'ptr'
238
+ // are not reported as data races whenever 'ptr' reused by
239
+ // other threads.
240
+ utils_annotate_release (pool );
241
+
232
242
struct tbb_memory_pool * pool_data = (struct tbb_memory_pool * )pool ;
233
243
if (g_tbb_ops .pool_free (pool_data -> tbb_pool , ptr )) {
234
244
return UMF_RESULT_SUCCESS ;
0 commit comments