diff --git a/util/sync_point_impl.cc b/util/sync_point_impl.cc index ab4cc5ae5..248c381a3 100644 --- a/util/sync_point_impl.cc +++ b/util/sync_point_impl.cc @@ -89,11 +89,11 @@ void SyncPoint::Data::ClearAllCallBacks() { } void SyncPoint::Data::Process(const std::string& point, void* cb_arg) { - std::unique_lock lock(mutex_); if (!enabled_) { return; } + std::unique_lock lock(mutex_); auto thread_id = std::this_thread::get_id(); auto marker_iter = markers_.find(point); diff --git a/util/sync_point_impl.h b/util/sync_point_impl.h index 8c7bd7a2d..3c7e70491 100644 --- a/util/sync_point_impl.h +++ b/util/sync_point_impl.h @@ -6,6 +6,7 @@ #include "util/sync_point.h" #include +#include #include #include #include @@ -22,6 +23,7 @@ #ifndef NDEBUG namespace rocksdb { struct SyncPoint::Data { + Data() : enabled_(false) {} // Enable proper deletion by subclasses virtual ~Data() {} // successor/predecessor map loaded from LoadDependency @@ -35,7 +37,7 @@ struct SyncPoint::Data { std::condition_variable cv_; // sync points that have been passed through std::unordered_set cleared_points_; - bool enabled_ = false; + std::atomic enabled_; int num_callbacks_running_ = 0; void LoadDependency(const std::vector& dependencies); @@ -51,11 +53,9 @@ struct SyncPoint::Data { void ClearCallBack(const std::string& point); void ClearAllCallBacks(); void EnableProcessing() { - std::lock_guard lock(mutex_); enabled_ = true; } void DisableProcessing() { - std::lock_guard lock(mutex_); enabled_ = false; } void ClearTrace() {