]> git.proxmox.com Git - ceph.git/blob - ceph/src/rocksdb/test_util/mock_time_env.cc
import quincy beta 17.1.0
[ceph.git] / 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).
5
6 #include "test_util/mock_time_env.h"
7
8 #include "test_util/sync_point.h"
9
10 namespace ROCKSDB_NAMESPACE {
11
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.
14 // details: PR #7101.
15 void MockTimeEnv::InstallTimedWaitFixCallback() {
16 #ifndef NDEBUG
17 SyncPoint::GetInstance()->DisableProcessing();
18 SyncPoint::GetInstance()->ClearAllCallBacks();
19 #ifdef OS_MACOSX
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;
31 }
32 });
33 #endif // OS_MACOSX
34 SyncPoint::GetInstance()->EnableProcessing();
35 #endif // !NDEBUG
36 }
37
38 } // namespace ROCKSDB_NAMESPACE