]>
git.proxmox.com Git - ceph.git/blob - ceph/src/rocksdb/test_util/mock_time_env.cc
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).
6 #include "test_util/mock_time_env.h"
8 #include "test_util/sync_point.h"
10 namespace ROCKSDB_NAMESPACE
{
12 // TODO: this is a workaround for the different behavior on different platform
13 // for timedwait timeout. Ideally timedwait API should be moved to env.
15 void MockTimeEnv::InstallTimedWaitFixCallback() {
17 SyncPoint::GetInstance()->DisableProcessing();
18 SyncPoint::GetInstance()->ClearAllCallBacks();
20 // This is an alternate way (vs. SpecialEnv) of dealing with the fact
21 // that on some platforms, pthread_cond_timedwait does not appear to
22 // release the lock for other threads to operate if the deadline time
23 // is already passed. (TimedWait calls are currently a bad abstraction
24 // because the deadline parameter is usually computed from Env time,
25 // but is interpreted in real clock time.)
26 SyncPoint::GetInstance()->SetCallBack(
27 "InstrumentedCondVar::TimedWaitInternal", [&](void* arg
) {
28 uint64_t time_us
= *reinterpret_cast<uint64_t*>(arg
);
29 if (time_us
< this->RealNowMicros()) {
30 *reinterpret_cast<uint64_t*>(arg
) = this->RealNowMicros() + 1000;
34 SyncPoint::GetInstance()->EnableProcessing();
38 } // namespace ROCKSDB_NAMESPACE