2022-01-10 09:43:29 -05:00
|
|
|
// -*- C++ -*-
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
2022-11-25 10:25:10 -05:00
|
|
|
|
2022-01-10 09:43:29 -05:00
|
|
|
#ifndef _LIBCPP___THREAD_TIMED_BACKOFF_POLICY_H
|
|
|
|
#define _LIBCPP___THREAD_TIMED_BACKOFF_POLICY_H
|
|
|
|
|
|
|
|
#include <__config>
|
|
|
|
|
2024-11-06 10:39:19 +01:00
|
|
|
#if _LIBCPP_HAS_THREADS
|
2022-01-10 09:43:29 -05:00
|
|
|
|
2022-02-23 23:05:22 +01:00
|
|
|
# include <__chrono/duration.h>
|
2024-01-30 08:35:15 -05:00
|
|
|
# include <__thread/support.h>
|
2022-01-10 09:43:29 -05:00
|
|
|
|
|
|
|
# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
|
2022-02-01 20:16:40 -05:00
|
|
|
# pragma GCC system_header
|
2022-01-10 09:43:29 -05:00
|
|
|
# endif
|
|
|
|
|
|
|
|
_LIBCPP_BEGIN_NAMESPACE_STD
|
|
|
|
|
|
|
|
struct __libcpp_timed_backoff_policy {
|
|
|
|
_LIBCPP_HIDE_FROM_ABI bool operator()(chrono::nanoseconds __elapsed) const {
|
|
|
|
if (__elapsed > chrono::milliseconds(128))
|
|
|
|
__libcpp_thread_sleep_for(chrono::milliseconds(8));
|
|
|
|
else if (__elapsed > chrono::microseconds(64))
|
|
|
|
__libcpp_thread_sleep_for(__elapsed / 2);
|
|
|
|
else if (__elapsed > chrono::microseconds(4))
|
|
|
|
__libcpp_thread_yield();
|
|
|
|
else {
|
|
|
|
} // poll
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
_LIBCPP_END_NAMESPACE_STD
|
|
|
|
|
2024-11-06 10:39:19 +01:00
|
|
|
#endif // _LIBCPP_HAS_THREADS
|
2022-01-10 09:43:29 -05:00
|
|
|
|
|
|
|
#endif // _LIBCPP___THREAD_TIMED_BACKOFF_POLICY_H
|