Home ⌂Doc Index ◂Up ▴
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 345 of file tbb_machine.h.

Constructor & Destructor Documentation

◆ atomic_backoff() [1/2]

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

Definition at line 355 of file tbb_machine.h.

355 : count(1) {}

◆ atomic_backoff() [2/2]

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

Definition at line 357 of file tbb_machine.h.

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

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

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

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

360  {
361  if( count<=LOOPS_BEFORE_YIELD ) {
363  // Pause twice as long the next time.
364  count*=2;
365  } else {
366  // Pause is so long that we might as well yield CPU to scheduler.
367  __TBB_Yield();
368  }
369  }
void __TBB_Pause(int32_t)
Definition: tbb_machine.h:331
#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:349

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

383  {
384  count = 1;
385  }

References count.

Member Data Documentation

◆ count

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

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

Referenced by bounded_pause(), and pause().


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

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.