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 (const no_copy &)=delete
 
 no_copy ()=default
 

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.

360 : count(1) { pause(); }

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

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  }

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

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  }

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::spin_rw_mutex_v3::internal_acquire_reader(), tbb::spin_rw_mutex_v3::internal_acquire_writer(), tbb::internal::concurrent_vector_base_v3::internal_grow_to_at_least_with_result(), tbb::internal::mail_outbox::internal_pop(), tbb::spin_rw_mutex_v3::internal_upgrade(), 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 386 of file tbb_machine.h.

386  {
387  count = 1;
388  }

References count.

Member Data Documentation

◆ count

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

Definition at line 353 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 352 of file tbb_machine.h.

Referenced by bounded_pause(), and pause().


The documentation for this class was generated from the following file:
tbb::internal::atomic_backoff::count
int32_t count
Definition: tbb_machine.h:353
tbb::internal::atomic_backoff::pause
void pause()
Pause for a while.
Definition: tbb_machine.h:363
__TBB_Yield
#define __TBB_Yield()
Definition: ibm_aix51.h:44
tbb::internal::atomic_backoff::LOOPS_BEFORE_YIELD
static const int32_t LOOPS_BEFORE_YIELD
Time delay, in units of "pause" instructions.
Definition: tbb_machine.h:352
__TBB_Pause
void __TBB_Pause(int32_t)
Definition: tbb_machine.h:334

Copyright © 2005-2020 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.