Intel(R) Threading Building Blocks Doxygen Documentation  version 4.2.3
tbb::internal::atomic_backoff Class Reference

Class that implements exponential backoff. More...

#include <tbb_machine.h>

Inheritance diagram for tbb::internal::atomic_backoff:
Collaboration diagram for tbb::internal::atomic_backoff:

Public Member Functions

 atomic_backoff ()
 
 atomic_backoff (bool)
 
void pause ()
 Pause for a while. More...
 
bool bounded_pause ()
 Pause for a few times and return false if saturated. More...
 
void reset ()
 

Private Attributes

int32_t count
 

Static Private Attributes

static const int32_t LOOPS_BEFORE_YIELD = 16
 Time delay, in units of "pause" instructions. More...
 

Additional Inherited Members

- Private Member Functions inherited from tbb::internal::no_copy
 no_copy ()
 Allow default construction. More...
 

Detailed Description

Class that implements exponential backoff.

See implementation of spin_wait_while_eq for an example.

Definition at line 348 of file tbb_machine.h.

Constructor & Destructor Documentation

◆ atomic_backoff() [1/2]

tbb::internal::atomic_backoff::atomic_backoff ( )
inline

Definition at line 358 of file tbb_machine.h.

358 : count(1) {}

◆ atomic_backoff() [2/2]

tbb::internal::atomic_backoff::atomic_backoff ( bool  )
inline

Definition at line 360 of file tbb_machine.h.

References tbb::internal::pause().

360 : count(1) { pause(); }
void pause()
Pause for a while.
Definition: tbb_machine.h:363
Here is the call graph for this function:

Member Function Documentation

◆ bounded_pause()

bool tbb::internal::atomic_backoff::bounded_pause ( )
inline

Pause for a few times and return false if saturated.

Definition at line 375 of file tbb_machine.h.

References __TBB_Pause().

Referenced by tbb::internal::prolonged_pause().

375  {
377  if( count<LOOPS_BEFORE_YIELD ) {
378  // Pause twice as long the next time.
379  count*=2;
380  return true;
381  } else {
382  return false;
383  }
384  }
void __TBB_Pause(int32_t)
Definition: tbb_machine.h:334
static const int32_t LOOPS_BEFORE_YIELD
Time delay, in units of "pause" instructions.
Definition: tbb_machine.h:352
Here is the call graph for this function:
Here is the caller graph for this function:

◆ pause()

void tbb::internal::atomic_backoff::pause ( )
inline

Pause for a while.

Definition at line 363 of file tbb_machine.h.

References __TBB_Pause(), and __TBB_Yield.

Referenced by __TBB_AtomicAND(), __TBB_AtomicOR(), tbb::internal::__TBB_FetchAndAddGeneric(), tbb::internal::__TBB_FetchAndStoreGeneric(), __TBB_LockByte(), tbb::internal::__TBB_MaskedCompareAndSwap(), tbb::internal::generic_scheduler::acquire_task_pool(), tbb::internal::concurrent_vector_base_v3::helper::extend_segment_table(), tbb::interface5::fetch_and_and(), tbb::interface5::fetch_and_or(), tbb::internal::concurrent_vector_base_v3::internal_grow_to_at_least_with_result(), tbb::internal::mail_outbox::internal_pop(), tbb::internal::micro_queue::push(), tbb::interface5::spin_wait_until_and(), tbb::internal::spin_wait_until_eq(), tbb::strict_ppl::internal::micro_queue< Value >::spin_wait_until_my_turn(), tbb::internal::spin_wait_while(), tbb::internal::spin_wait_while_eq(), tbb::interface5::spin_wait_while_geq(), and tbb::TBB_runtime_interface_version().

363  {
364  if( count<=LOOPS_BEFORE_YIELD ) {
366  // Pause twice as long the next time.
367  count*=2;
368  } else {
369  // Pause is so long that we might as well yield CPU to scheduler.
370  __TBB_Yield();
371  }
372  }
void __TBB_Pause(int32_t)
Definition: tbb_machine.h:334
#define __TBB_Yield()
Definition: ibm_aix51.h:44
static const int32_t LOOPS_BEFORE_YIELD
Time delay, in units of "pause" instructions.
Definition: tbb_machine.h:352
Here is the call graph for this function:
Here is the caller graph for this function:

◆ reset()

void tbb::internal::atomic_backoff::reset ( )
inline

Definition at line 386 of file tbb_machine.h.

386  {
387  count = 1;
388  }

Member Data Documentation

◆ count

int32_t tbb::internal::atomic_backoff::count
private

Definition at line 353 of file tbb_machine.h.

◆ LOOPS_BEFORE_YIELD

const int32_t tbb::internal::atomic_backoff::LOOPS_BEFORE_YIELD = 16
staticprivate

Time delay, in units of "pause" instructions.

Should be equal to approximately the number of "pause" instructions that take the same time as an context switch. Must be a power of two.

Definition at line 352 of file tbb_machine.h.


The documentation for this class was generated from the following file:

Copyright © 2005-2019 Intel Corporation. All Rights Reserved.

Intel, Pentium, Intel Xeon, Itanium, Intel XScale and VTune are registered trademarks or trademarks of Intel Corporation or its subsidiaries in the United States and other countries.

* Other names and brands may be claimed as the property of others.