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 349 of file tbb_machine.h.

Constructor & Destructor Documentation

◆ atomic_backoff() [1/2]

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

Definition at line 359 of file tbb_machine.h.

359 : count(1) {}

◆ atomic_backoff() [2/2]

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

Definition at line 361 of file tbb_machine.h.

361 : count(1) { pause(); }
void pause()
Pause for a while.
Definition: tbb_machine.h:364

References pause().

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 376 of file tbb_machine.h.

376  {
378  if( count<LOOPS_BEFORE_YIELD ) {
379  // Pause twice as long the next time.
380  count*=2;
381  return true;
382  } else {
383  return false;
384  }
385  }
static const int32_t LOOPS_BEFORE_YIELD
Time delay, in units of "pause" instructions.
Definition: tbb_machine.h:353
void __TBB_Pause(int32_t)
Definition: tbb_machine.h:335

References __TBB_Pause(), count, and LOOPS_BEFORE_YIELD.

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

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 364 of file tbb_machine.h.

364  {
365  if( count<=LOOPS_BEFORE_YIELD ) {
367  // Pause twice as long the next time.
368  count*=2;
369  } else {
370  // Pause is so long that we might as well yield CPU to scheduler.
371  __TBB_Yield();
372  }
373  }
static const int32_t LOOPS_BEFORE_YIELD
Time delay, in units of "pause" instructions.
Definition: tbb_machine.h:353
#define __TBB_Yield()
Definition: ibm_aix51.h:48
void __TBB_Pause(int32_t)
Definition: tbb_machine.h:335

References __TBB_Pause(), __TBB_Yield, count, and LOOPS_BEFORE_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(), atomic_backoff(), 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(), and tbb::interface5::spin_wait_while_geq().

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 387 of file tbb_machine.h.

387  {
388  count = 1;
389  }

References count.

Member Data Documentation

◆ count

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

Definition at line 354 of file tbb_machine.h.

Referenced by bounded_pause(), pause(), and reset().

◆ 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 353 of file tbb_machine.h.

Referenced by bounded_pause(), and pause().


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.