]>
Commit | Line | Data |
---|---|---|
7c673cae | 1 | // Copyright (c) 2011-present, Facebook, Inc. All rights reserved. |
11fdf7f2 TL |
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). | |
7c673cae FG |
5 | |
6 | #include "monitoring/instrumented_mutex.h" | |
7 | #include "monitoring/perf_context_imp.h" | |
8 | #include "monitoring/thread_status_util.h" | |
f67539c2 | 9 | #include "test_util/sync_point.h" |
7c673cae | 10 | |
f67539c2 | 11 | namespace ROCKSDB_NAMESPACE { |
7c673cae | 12 | namespace { |
20effc67 | 13 | #ifndef NPERF_CONTEXT |
11fdf7f2 TL |
14 | Statistics* stats_for_report(Env* env, Statistics* stats) { |
15 | if (env != nullptr && stats != nullptr && | |
494da23a | 16 | stats->get_stats_level() > kExceptTimeForMutex) { |
11fdf7f2 TL |
17 | return stats; |
18 | } else { | |
19 | return nullptr; | |
20 | } | |
7c673cae | 21 | } |
20effc67 | 22 | #endif // NPERF_CONTEXT |
7c673cae FG |
23 | } // namespace |
24 | ||
25 | void InstrumentedMutex::Lock() { | |
11fdf7f2 TL |
26 | PERF_CONDITIONAL_TIMER_FOR_MUTEX_GUARD( |
27 | db_mutex_lock_nanos, stats_code_ == DB_MUTEX_WAIT_MICROS, | |
28 | stats_for_report(env_, stats_), stats_code_); | |
29 | LockInternal(); | |
7c673cae FG |
30 | } |
31 | ||
32 | void InstrumentedMutex::LockInternal() { | |
33 | #ifndef NDEBUG | |
34 | ThreadStatusUtil::TEST_StateDelay(ThreadStatus::STATE_MUTEX_WAIT); | |
35 | #endif | |
36 | mutex_.Lock(); | |
37 | } | |
38 | ||
39 | void InstrumentedCondVar::Wait() { | |
11fdf7f2 TL |
40 | PERF_CONDITIONAL_TIMER_FOR_MUTEX_GUARD( |
41 | db_condition_wait_nanos, stats_code_ == DB_MUTEX_WAIT_MICROS, | |
42 | stats_for_report(env_, stats_), stats_code_); | |
43 | WaitInternal(); | |
7c673cae FG |
44 | } |
45 | ||
46 | void InstrumentedCondVar::WaitInternal() { | |
47 | #ifndef NDEBUG | |
48 | ThreadStatusUtil::TEST_StateDelay(ThreadStatus::STATE_MUTEX_WAIT); | |
49 | #endif | |
50 | cond_.Wait(); | |
51 | } | |
52 | ||
53 | bool InstrumentedCondVar::TimedWait(uint64_t abs_time_us) { | |
11fdf7f2 TL |
54 | PERF_CONDITIONAL_TIMER_FOR_MUTEX_GUARD( |
55 | db_condition_wait_nanos, stats_code_ == DB_MUTEX_WAIT_MICROS, | |
56 | stats_for_report(env_, stats_), stats_code_); | |
57 | return TimedWaitInternal(abs_time_us); | |
7c673cae FG |
58 | } |
59 | ||
60 | bool InstrumentedCondVar::TimedWaitInternal(uint64_t abs_time_us) { | |
61 | #ifndef NDEBUG | |
62 | ThreadStatusUtil::TEST_StateDelay(ThreadStatus::STATE_MUTEX_WAIT); | |
63 | #endif | |
64 | ||
65 | TEST_SYNC_POINT_CALLBACK("InstrumentedCondVar::TimedWaitInternal", | |
66 | &abs_time_us); | |
67 | ||
68 | return cond_.TimedWait(abs_time_us); | |
69 | } | |
70 | ||
f67539c2 | 71 | } // namespace ROCKSDB_NAMESPACE |