Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / libcxx / include / __thread / timed_backoff_policy.h
bloba54b296ae5c5f80ac02a91f76c1befae34e0800d
1 // -*- C++ -*-
2 //===----------------------------------------------------------------------===//
3 //
4 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5 // See https://llvm.org/LICENSE.txt for license information.
6 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //
8 //===----------------------------------------------------------------------===//
10 #ifndef _LIBCPP___THREAD_TIMED_BACKOFF_POLICY_H
11 #define _LIBCPP___THREAD_TIMED_BACKOFF_POLICY_H
13 #include <__config>
15 #ifndef _LIBCPP_HAS_NO_THREADS
17 # include <__chrono/duration.h>
18 # include <__threading_support>
20 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
21 # pragma GCC system_header
22 #endif
24 _LIBCPP_BEGIN_NAMESPACE_STD
26 struct __libcpp_timed_backoff_policy {
27 _LIBCPP_INLINE_VISIBILITY
28 bool operator()(chrono::nanoseconds __elapsed) const
30 if(__elapsed > chrono::milliseconds(128))
31 __libcpp_thread_sleep_for(chrono::milliseconds(8));
32 else if(__elapsed > chrono::microseconds(64))
33 __libcpp_thread_sleep_for(__elapsed / 2);
34 else if(__elapsed > chrono::microseconds(4))
35 __libcpp_thread_yield();
36 else
37 {} // poll
38 return false;
42 _LIBCPP_END_NAMESPACE_STD
44 #endif // _LIBCPP_HAS_NO_THREADS
46 #endif // _LIBCPP___THREAD_TIMED_BACKOFF_POLICY_H