2016-02-10 00:12:00 +01:00
|
|
|
// Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
|
2017-07-16 01:03:42 +02:00
|
|
|
// This source code is licensed under both the GPLv2 (found in the
|
|
|
|
// COPYING file in the root directory) and Apache 2.0 License
|
|
|
|
// (found in the LICENSE.Apache file in the root directory).
|
2015-02-17 20:29:36 +01:00
|
|
|
|
|
|
|
#include <atomic>
|
|
|
|
|
2017-04-06 04:02:00 +02:00
|
|
|
#include "monitoring/thread_status_updater.h"
|
|
|
|
#include "monitoring/thread_status_util.h"
|
2021-01-26 07:07:26 +01:00
|
|
|
#include "rocksdb/system_clock.h"
|
2015-02-17 20:29:36 +01:00
|
|
|
|
2020-02-20 21:07:53 +01:00
|
|
|
namespace ROCKSDB_NAMESPACE {
|
2015-02-17 20:29:36 +01:00
|
|
|
|
|
|
|
#ifndef NDEBUG
|
|
|
|
// the delay for debugging purpose.
|
|
|
|
static std::atomic<int> states_delay[ThreadStatus::NUM_STATE_TYPES];
|
|
|
|
|
|
|
|
void ThreadStatusUtil::TEST_SetStateDelay(
|
|
|
|
const ThreadStatus::StateType state, int micro) {
|
|
|
|
states_delay[state].store(micro, std::memory_order_relaxed);
|
|
|
|
}
|
|
|
|
|
2015-04-14 00:58:45 +02:00
|
|
|
void ThreadStatusUtil::TEST_StateDelay(const ThreadStatus::StateType state) {
|
|
|
|
auto delay = states_delay[state].load(std::memory_order_relaxed);
|
|
|
|
if (delay > 0) {
|
2021-01-26 07:07:26 +01:00
|
|
|
SystemClock::Default()->SleepForMicroseconds(delay);
|
2015-04-14 00:58:45 +02:00
|
|
|
}
|
2015-02-17 20:29:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif // !NDEBUG
|
|
|
|
|
2020-02-20 21:07:53 +01:00
|
|
|
} // namespace ROCKSDB_NAMESPACE
|