brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.2 KiB · 35a72eb Raw
45 lines · c
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-exception7//8//===----------------------------------------------------------------------===//9 10#ifndef _LIBCPP___THREAD_TIMED_BACKOFF_POLICY_H11#define _LIBCPP___THREAD_TIMED_BACKOFF_POLICY_H12 13#include <__config>14 15#if _LIBCPP_HAS_THREADS16 17#  include <__chrono/duration.h>18#  include <__thread/support.h>19 20#  if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)21#    pragma GCC system_header22#  endif23 24_LIBCPP_BEGIN_NAMESPACE_STD25 26struct __libcpp_timed_backoff_policy {27  _LIBCPP_HIDE_FROM_ABI bool operator()(chrono::nanoseconds __elapsed) const {28    if (__elapsed > chrono::milliseconds(128))29      __libcpp_thread_sleep_for(chrono::milliseconds(8));30    else if (__elapsed > chrono::microseconds(64))31      __libcpp_thread_sleep_for(__elapsed / 2);32    else if (__elapsed > chrono::microseconds(4))33      __libcpp_thread_yield();34    else {35    } // poll36    return false;37  }38};39 40_LIBCPP_END_NAMESPACE_STD41 42#endif // _LIBCPP_HAS_THREADS43 44#endif // _LIBCPP___THREAD_TIMED_BACKOFF_POLICY_H45