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 );
@@ -180,6 +181,7 @@ static void *tbb_malloc(void *pool, size_t size) {
180
181
}
181
182
return NULL ;
182
183
}
184
+ utils_annotate_acquire (pool );
183
185
return ptr ;
184
186
}
185
187
@@ -206,6 +208,7 @@ static void *tbb_realloc(void *pool, void *ptr, size_t size) {
206
208
}
207
209
return NULL ;
208
210
}
211
+ utils_annotate_acquire (pool );
209
212
return new_ptr ;
210
213
}
211
214
@@ -220,6 +223,7 @@ static void *tbb_aligned_malloc(void *pool, size_t size, size_t alignment) {
220
223
}
221
224
return NULL ;
222
225
}
226
+ utils_annotate_acquire (pool );
223
227
return ptr ;
224
228
}
225
229
@@ -230,6 +234,12 @@ static umf_result_t tbb_free(void *pool, void *ptr) {
230
234
231
235
TLS_last_free_error = UMF_RESULT_SUCCESS ;
232
236
237
+ // Establishes happens-before order with tbb_*alloc functions.
238
+ // Makes sure that writes to the memory pointed to by 'ptr'
239
+ // are not reported as data races whenever 'ptr' reused by
240
+ // other threads.
241
+ utils_annotate_release (pool );
242
+
233
243
struct tbb_memory_pool * pool_data = (struct tbb_memory_pool * )pool ;
234
244
if (g_tbb_ops .pool_free (pool_data -> tbb_pool , ptr )) {
235
245
return UMF_RESULT_SUCCESS ;
0 commit comments