diff --git a/src/babylon/concurrent/counter.h b/src/babylon/concurrent/counter.h index 272ff54..19bb85d 100644 --- a/src/babylon/concurrent/counter.h +++ b/src/babylon/concurrent/counter.h @@ -308,7 +308,7 @@ class ConcurrentSampler { SampleBucket* prepare_sample_bucket(uint64_t value) noexcept; - EnumerableThreadLocal _storage; + EnumerableThreadLocal _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}; diff --git a/src/babylon/concurrent/id_allocator.hpp b/src/babylon/concurrent/id_allocator.hpp index 751b172..2c682c8 100644 --- a/src/babylon/concurrent/id_allocator.hpp +++ b/src/babylon/concurrent/id_allocator.hpp @@ -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(); + BABYLON_LEAK_CHECK_DISABLER(); + static auto object = new IdAllocator(); #pragma GCC diagnostic pop return *object; } @@ -184,6 +184,7 @@ VersionedValue ThreadIdImpl::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::instance()); #pragma GCC diagnostic pop diff --git a/src/babylon/concurrent/thread_local.h b/src/babylon/concurrent/thread_local.h index 3d16a89..c9b3b23 100644 --- a/src/babylon/concurrent/thread_local.h +++ b/src/babylon/concurrent/thread_local.h @@ -13,7 +13,7 @@ BABYLON_NAMESPACE_BEGIN template class EnumerableThreadLocal { using ThreadIdType = - typename std::conditional::type; + typename ::std::conditional::type; public: // 可默认构造,可以移动,不能拷贝 @@ -123,7 +123,7 @@ class CompactEnumerableThreadLocal { // 获得线程局部存储 template inline typename ::std::enable_if::type local() { - BABYLON_LEAK_CHECK_DISABLER; + BABYLON_LEAK_CHECK_DISABLER(); return _storage->local().value[_cacheline_offset]; } template @@ -181,12 +181,12 @@ class CompactEnumerableThreadLocal { struct alignas(BABYLON_CACHELINE_SIZE) CacheLine { T value[NUM_PER_CACHELINE]; }; - using Storage = EnumerableThreadLocal; + using Storage = EnumerableThreadLocal; using StorageVector = ConcurrentVector; template static typename ::std::enable_if::type allocate_id() noexcept { - BABYLON_LEAK_CHECK_DISABLER; + BABYLON_LEAK_CHECK_DISABLER(); return id_allocator().allocate().value; } template @@ -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(); #pragma GCC diagnostic pop return *allocator; @@ -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); diff --git a/src/babylon/sanitizer_helper.h b/src/babylon/sanitizer_helper.h index b421740..2dd53e7 100644 --- a/src/babylon/sanitizer_helper.h +++ b/src/babylon/sanitizer_helper.h @@ -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