Skip to content

Commit 9ff7ee2

Browse files
asaezpercodebot
authored andcommitted
memory_pool: TSAN explicitly synchronization
1 parent f8faa95 commit 9ff7ee2

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ endif (ENABLE_ASAN)
152152

153153
if (ENABLE_TSAN)
154154
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=thread")
155+
add_definitions(-DENABLE_TSAN)
155156
endif (ENABLE_TSAN)
156157

157158
if (ENABLE_GCOV)

include/srsran/support/memory_pool/fixed_size_memory_block_pool.h

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010

1111
#pragma once
1212

13+
#ifdef ENABLE_TSAN
14+
#include "sanitizer/tsan_interface.h"
15+
#endif
16+
1317
#include "cameron314/concurrentqueue.h"
1418
#include "memory_block_list.h"
1519
#include "srsran/adt/static_vector.h"
@@ -155,6 +159,9 @@ class fixed_size_memory_block_pool
155159
free_memory_block_list batch;
156160
if (central_mem_cache.try_dequeue(w_ctx->consumer_token, batch)) {
157161
w_ctx->local_cache.push_back(batch);
162+
#ifdef ENABLE_TSAN
163+
__tsan_acquire((void*)w_ctx->local_cache.back().head);
164+
#endif
158165
node = w_ctx->local_cache.back().try_pop();
159166
validate_node_address(node);
160167
}
@@ -177,6 +184,9 @@ class fixed_size_memory_block_pool
177184

178185
// Push block to local cache.
179186
w_ctx->local_cache.back().push(p);
187+
#ifdef ENABLE_TSAN
188+
__tsan_release(p);
189+
#endif
180190

181191
if (w_ctx->local_cache.size() >= max_local_batches and w_ctx->local_cache.back().size() >= block_batch_size) {
182192
// Local cache is full. Rebalance by sending batches of blocks to central cache.
@@ -198,7 +208,10 @@ class fixed_size_memory_block_pool
198208
}
199209

200210
/// Get central cache current size in number of memory blocks.
201-
size_t get_central_cache_approx_size() const { return central_mem_cache.size_approx() * block_batch_size; }
211+
size_t get_central_cache_approx_size() const
212+
{
213+
return central_mem_cache.size_approx() * block_batch_size;
214+
}
202215
/// Get thread local cache current size in number of memory blocks.
203216
size_t get_local_cache_size()
204217
{
@@ -266,7 +279,10 @@ class fixed_size_memory_block_pool
266279
}
267280

268281
/// Number of batches of memory blocks stored in the pool.
269-
size_t nof_total_batches() const { return (nof_blocks + block_batch_size - 1) / block_batch_size; }
282+
size_t nof_total_batches() const
283+
{
284+
return (nof_blocks + block_batch_size - 1) / block_batch_size;
285+
}
270286

271287
void validate_node_address(void* node)
272288
{

0 commit comments

Comments
 (0)