]>
git.proxmox.com Git - ceph.git/blob - ceph/src/rocksdb/third-party/folly/folly/synchronization/detail/Sleeper.h
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).
9 * @author Keith Adams <kma@fb.com>
10 * @author Jordan DeLong <delong.j@fb.com>
16 #include <folly/portability/Asm.h>
20 //////////////////////////////////////////////////////////////////////
25 * A helper object for the contended case. Starts off with eager
26 * spinning, and falls back to sleeping for small quantums.
29 static const uint32_t kMaxActiveSpin
= 4000;
34 Sleeper() noexcept
: spinCount(0) {}
36 static void sleep() noexcept
{
38 * Always sleep 0.5ms, assuming this will make the kernel put
39 * us down for whatever its minimum timer resolution is (in
40 * linux this varies by kernel version from 1ms to 10ms).
42 std::this_thread::sleep_for(std::chrono::microseconds
{500});
45 void wait() noexcept
{
46 if (spinCount
< kMaxActiveSpin
) {