Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/babylon/concurrent/counter.h
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ class ConcurrentSampler {

SampleBucket* prepare_sample_bucket(uint64_t value) noexcept;

EnumerableThreadLocal<Sample> _storage;
EnumerableThreadLocal<Sample, true> _storage;
uint8_t _bucket_capacity[32] = {30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30,
30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30,
30, 30, 30, 30, 30, 30, 30, 30, 30, 30};
Expand Down
5 changes: 3 additions & 2 deletions src/babylon/concurrent/id_allocator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,8 @@ struct IdAllocatorFotType {
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wpragmas"
#pragma GCC diagnostic ignored "-Wunknown-warning-option"
BABYLON_LEAK_CHECK_DISABLER;
static auto object = new IdAllocator<uint32_t>();
BABYLON_LEAK_CHECK_DISABLER();
static auto object = new IdAllocator<uint16_t>();
#pragma GCC diagnostic pop
return *object;
}
Expand Down Expand Up @@ -184,6 +184,7 @@ VersionedValue<uint16_t> ThreadIdImpl<Leaky>::current_thread_id() noexcept {
#pragma GCC diagnostic ignored "-Wpragmas"
#pragma GCC diagnostic ignored "-Wunknown-warning-option"
#pragma GCC diagnostic ignored "-Wexit-time-destructors"
BABYLON_LEAK_CHECK_DISABLER(Leaky);
thread_local ThreadIdImpl id(
concurrent_id_allocator::IdAllocatorFotType<T, Leaky>::instance());
#pragma GCC diagnostic pop
Expand Down
12 changes: 6 additions & 6 deletions src/babylon/concurrent/thread_local.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ BABYLON_NAMESPACE_BEGIN
template <typename T, bool Leaky = false>
class EnumerableThreadLocal {
using ThreadIdType =
typename std::conditional<Leaky, LeakyThreadId, ThreadId>::type;
typename ::std::conditional<Leaky, LeakyThreadId, ThreadId>::type;

public:
// 可默认构造,可以移动,不能拷贝
Expand Down Expand Up @@ -123,7 +123,7 @@ class CompactEnumerableThreadLocal {
// 获得线程局部存储
template <bool L = Leaky>
inline typename ::std::enable_if<L, T&>::type local() {
BABYLON_LEAK_CHECK_DISABLER;
BABYLON_LEAK_CHECK_DISABLER();
return _storage->local().value[_cacheline_offset];
}
template <bool L = Leaky>
Expand Down Expand Up @@ -181,12 +181,12 @@ class CompactEnumerableThreadLocal {
struct alignas(BABYLON_CACHELINE_SIZE) CacheLine {
T value[NUM_PER_CACHELINE];
};
using Storage = EnumerableThreadLocal<CacheLine>;
using Storage = EnumerableThreadLocal<CacheLine, Leaky>;
using StorageVector = ConcurrentVector<Storage, 128>;

template <bool L = Leaky>
static typename ::std::enable_if<L, uint32_t>::type allocate_id() noexcept {
BABYLON_LEAK_CHECK_DISABLER;
BABYLON_LEAK_CHECK_DISABLER();
return id_allocator().allocate().value;
}
template <bool L = Leaky>
Expand All @@ -200,7 +200,7 @@ class CompactEnumerableThreadLocal {
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wpragmas"
#pragma GCC diagnostic ignored "-Wunknown-warning-option"
BABYLON_LEAK_CHECK_DISABLER;
BABYLON_LEAK_CHECK_DISABLER();
static auto allocator = new IdAllocator<uint32_t>();
#pragma GCC diagnostic pop
return *allocator;
Expand All @@ -223,7 +223,7 @@ class CompactEnumerableThreadLocal {
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wpragmas"
#pragma GCC diagnostic ignored "-Wunknown-warning-option"
BABYLON_LEAK_CHECK_DISABLER;
BABYLON_LEAK_CHECK_DISABLER();
static auto storage_vector = new StorageVector();
#pragma GCC diagnostic pop
return storage_vector->ensure(slot_index);
Expand Down
20 changes: 15 additions & 5 deletions src/babylon/sanitizer_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,22 +92,32 @@ struct SanitizerHelper {
#ifdef BABYLON_HAVE_LEAK_SANITIZER
class LeakCheckDisabler {
public:
LeakCheckDisabler() {
LeakCheckDisabler() : _disable_leak_check(true) {
__lsan_disable();
}
LeakCheckDisabler(bool disable_leak_check)
: _disable_leak_check(disable_leak_check) {
if (_disable_leak_check) {
__lsan_disable();
}
}
LeakCheckDisabler(const LeakCheckDisabler&) = delete;
LeakCheckDisabler& operator=(const LeakCheckDisabler&) = delete;
~LeakCheckDisabler() {
__lsan_enable();
if (_disable_leak_check) {
__lsan_enable();
}
}
private:
bool _disable_leak_check;
};

#define BABYLON_LEAK_CHECK_DISABLER \
LeakCheckDisabler __disabler_##__LINE__; \
#define BABYLON_LEAK_CHECK_DISABLER(...) \
LeakCheckDisabler __disabler_##__LINE__{__VA_ARGS__}; \
((void)0)

#else
#define BABYLON_LEAK_CHECK_DISABLER ((void)0)
#define BABYLON_LEAK_CHECK_DISABLER(...) ((void)0)
#endif // BABYLON_HAVE_LEAK_SANITIZER

BABYLON_NAMESPACE_END