proxygen
Main Page
Related Pages
Namespaces
Classes
Files
Examples
File List
File Members
Sleeper.h
Go to the documentation of this file.
1
/*
2
* Copyright 2015-present Facebook, Inc.
3
*
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
* you may not use this file except in compliance with the License.
6
* You may obtain a copy of the License at
7
*
8
* http://www.apache.org/licenses/LICENSE-2.0
9
*
10
* Unless required by applicable law or agreed to in writing, software
11
* distributed under the License is distributed on an "AS IS" BASIS,
12
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
* See the License for the specific language governing permissions and
14
* limitations under the License.
15
*/
16
17
#pragma once
18
19
/*
20
* @author Keith Adams <kma@fb.com>
21
* @author Jordan DeLong <delong.j@fb.com>
22
*/
23
24
#include <cstdint>
25
26
#include <
folly/portability/Asm.h
>
27
#include <
folly/portability/Time.h
>
28
29
namespace
folly
{
30
32
33
namespace
detail
{
34
35
/*
36
* A helper object for the contended case. Starts off with eager
37
* spinning, and falls back to sleeping for small quantums.
38
*/
39
class
Sleeper
{
40
static
const
uint32_t
kMaxActiveSpin
= 4000;
41
42
uint32_t
spinCount
;
43
44
public
:
45
Sleeper
()
noexcept
: spinCount(0) {}
46
47
static
void
sleep
()
noexcept
{
48
/*
49
* Always sleep 0.5ms, assuming this will make the kernel put
50
* us down for whatever its minimum timer resolution is (in
51
* linux this varies by kernel version from 1ms to 10ms).
52
*/
53
struct
timespec ts = {0, 500000};
54
nanosleep(&ts,
nullptr
);
55
}
56
57
void
wait
()
noexcept
{
58
if
(spinCount < kMaxActiveSpin) {
59
++
spinCount
;
60
asm_volatile_pause
();
61
}
else
{
62
sleep
();
63
}
64
}
65
};
66
67
}
// namespace detail
68
}
// namespace folly
Time.h
folly::detail::Sleeper
Definition:
Sleeper.h:39
folly
—— Concurrent Priority Queue Implementation ——
Definition:
AtomicBitSet.h:29
folly::pushmi::__adl::noexcept
requires E e noexcept(noexcept(s.error(std::move(e))))
Definition:
extension_points.h:40
folly::detail::Sleeper::wait
void wait() noexcept
Definition:
Sleeper.h:57
detail
Definition:
HashBenchmark.cpp:32
folly::detail::Sleeper::Sleeper
Sleeper() noexcept
Definition:
Sleeper.h:45
folly::detail::Sleeper::kMaxActiveSpin
static const uint32_t kMaxActiveSpin
Definition:
Sleeper.h:40
uint32_t
uint32_t
Definition:
ConstexprMathBenchmark.cpp:186
folly::detail::Sleeper::sleep
static void sleep() noexcept
Definition:
Sleeper.h:47
folly::detail::Sleeper::spinCount
uint32_t spinCount
Definition:
Sleeper.h:42
Asm.h
folly::asm_volatile_pause
void asm_volatile_pause()
Definition:
Asm.h:37
proxygen
folly
folly
synchronization
detail
Sleeper.h
Generated by
1.8.11