1 // Copyright (c) 2011-present, Facebook, Inc. All rights reserved. 2 // This source code is licensed under both the GPLv2 (found in the 3 // COPYING file in the root directory) and Apache 2.0 License 4 // (found in the LICENSE.Apache file in the root directory). 5 6 #include <atomic> 7 8 #include "monitoring/thread_status_updater.h" 9 #include "monitoring/thread_status_util.h" 10 #include "rocksdb/env.h" 11 12 namespace ROCKSDB_NAMESPACE { 13 14 #ifndef NDEBUG 15 // the delay for debugging purpose. 16 static std::atomic<int> states_delay[ThreadStatus::NUM_STATE_TYPES]; 17 TEST_SetStateDelay(const ThreadStatus::StateType state,int micro)18void ThreadStatusUtil::TEST_SetStateDelay( 19 const ThreadStatus::StateType state, int micro) { 20 states_delay[state].store(micro, std::memory_order_relaxed); 21 } 22 TEST_StateDelay(const ThreadStatus::StateType state)23void ThreadStatusUtil::TEST_StateDelay(const ThreadStatus::StateType state) { 24 auto delay = states_delay[state].load(std::memory_order_relaxed); 25 if (delay > 0) { 26 Env::Default()->SleepForMicroseconds(delay); 27 } 28 } 29 30 #endif // !NDEBUG 31 32 } // namespace ROCKSDB_NAMESPACE 33