mirror of
https://github.com/facebook/rocksdb.git
synced 2024-11-25 22:44:05 +00:00
12f1137355
Summary: Introduces and uses a SystemClock class to RocksDB. This class contains the time-related functions of an Env and these functions can be redirected from the Env to the SystemClock. Many of the places that used an Env (Timer, PerfStepTimer, RepeatableThread, RateLimiter, WriteController) for time-related functions have been changed to use SystemClock instead. There are likely more places that can be changed, but this is a start to show what can/should be done. Over time it would be nice to migrate most (if not all) of the uses of the time functions from the Env to the SystemClock. There are several Env classes that implement these functions. Most of these have not been converted yet to SystemClock implementations; that will come in a subsequent PR. It would be good to unify many of the Mock Timer implementations, so that they behave similarly and be tested similarly (some override Sleep, some use a MockSleep, etc). Additionally, this change will allow new methods to be introduced to the SystemClock (like https://github.com/facebook/rocksdb/issues/7101 WaitFor) in a consistent manner across a smaller number of classes. Pull Request resolved: https://github.com/facebook/rocksdb/pull/7858 Reviewed By: pdillinger Differential Revision: D26006406 Pulled By: mrambacher fbshipit-source-id: ed10a8abbdab7ff2e23d69d85bd25b3e7e899e90
39 lines
1.5 KiB
C++
39 lines
1.5 KiB
C++
// Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
|
|
// 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).
|
|
|
|
#include "test_util/mock_time_env.h"
|
|
|
|
#include "test_util/sync_point.h"
|
|
|
|
namespace ROCKSDB_NAMESPACE {
|
|
|
|
// TODO: this is a workaround for the different behavior on different platform
|
|
// for timedwait timeout. Ideally timedwait API should be moved to env.
|
|
// details: PR #7101.
|
|
void MockSystemClock::InstallTimedWaitFixCallback() {
|
|
#ifndef NDEBUG
|
|
SyncPoint::GetInstance()->DisableProcessing();
|
|
SyncPoint::GetInstance()->ClearAllCallBacks();
|
|
#ifdef OS_MACOSX
|
|
// This is an alternate way (vs. SpecialEnv) of dealing with the fact
|
|
// that on some platforms, pthread_cond_timedwait does not appear to
|
|
// release the lock for other threads to operate if the deadline time
|
|
// is already passed. (TimedWait calls are currently a bad abstraction
|
|
// because the deadline parameter is usually computed from Env time,
|
|
// but is interpreted in real clock time.)
|
|
SyncPoint::GetInstance()->SetCallBack(
|
|
"InstrumentedCondVar::TimedWaitInternal", [&](void* arg) {
|
|
uint64_t time_us = *reinterpret_cast<uint64_t*>(arg);
|
|
if (time_us < this->RealNowMicros()) {
|
|
*reinterpret_cast<uint64_t*>(arg) = this->RealNowMicros() + 1000;
|
|
}
|
|
});
|
|
#endif // OS_MACOSX
|
|
SyncPoint::GetInstance()->EnableProcessing();
|
|
#endif // !NDEBUG
|
|
}
|
|
|
|
} // namespace ROCKSDB_NAMESPACE
|