Intel(R) Threading Building Blocks Doxygen Documentation  version 4.2.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
tbb::interface5 Namespace Reference

Namespaces

 internal
 

Classes

class  concurrent_hash_map
 Unordered map from Key to T. More...
 
class  concurrent_priority_queue
 Concurrent priority queue. More...
 
class  concurrent_unordered_map_traits
 
class  concurrent_unordered_multimap
 
class  concurrent_unordered_map
 
class  concurrent_unordered_set_traits
 
class  concurrent_unordered_multiset
 
class  concurrent_unordered_set
 
class  scoped_lock
 The scoped lock pattern for write locks. More...
 
class  scoped_lock_read
 The scoped lock pattern for read locks. More...
 

Enumerations

enum  status_t { waiting_nonblocking, waiting, active, invalid }
 Status type for nodes associated with lock instances. More...
 

Functions

template<typename T >
 __TBB_DEPRECATED_MSG ("tbb::tbb_hasher is deprecated, use std::hash") inline size_t tbb_hasher(const T &t)
 Hasher functions. More...
 
template<typename E , typename S , typename A >
 __TBB_DEPRECATED_MSG ("tbb::tbb_hasher is deprecated, use std::hash") inline size_t tbb_hasher(const std
 
template<typename F , typename S >
 __TBB_DEPRECATED_MSG ("tbb::tbb_hasher is deprecated, use std::hash") inline size_t tbb_hasher(const std
 
 reader_writer_lock ()
 Constructs a new reader_writer_lock. More...
 
 ~reader_writer_lock ()
 Destructs a reader_writer_lock object. More...
 
void __TBB_EXPORTED_METHOD lock ()
 Acquires the reader_writer_lock for write. More...
 
bool __TBB_EXPORTED_METHOD try_lock ()
 Tries to acquire the reader_writer_lock for write. More...
 
void __TBB_EXPORTED_METHOD lock_read ()
 Acquires the reader_writer_lock for read. More...
 
bool __TBB_EXPORTED_METHOD try_lock_read ()
 Tries to acquire the reader_writer_lock for read. More...
 
void __TBB_EXPORTED_METHOD unlock ()
 Releases the reader_writer_lock. More...
 
void __TBB_EXPORTED_METHOD internal_construct ()
 
void __TBB_EXPORTED_METHOD internal_destroy ()
 
bool start_write (scoped_lock *)
 Attempts to acquire write lock. More...
 
void set_next_writer (scoped_lock *w)
 Sets writer_head to w and attempts to unblock. More...
 
void end_write (scoped_lock *)
 Relinquishes write lock to next waiting writer or group of readers. More...
 
bool is_current_writer ()
 Checks if current thread holds write lock. More...
 
void start_read (scoped_lock_read *)
 Attempts to acquire read lock. More...
 
void unblock_readers ()
 Unblocks pending readers. More...
 
void end_read ()
 Relinquishes read lock by decrementing counter; last reader wakes pending writer. More...
 
uintptr_t fetch_and_or (atomic< uintptr_t > &operand, uintptr_t value)
 
uintptr_t fetch_and_and (atomic< uintptr_t > &operand, uintptr_t value)
 
template<typename T , typename U >
void spin_wait_while_geq (const volatile T &location, U value)
 Spin WHILE the value at the location is greater than or equal to a given value. More...
 
template<typename T , typename U >
void spin_wait_until_and (const volatile T &location, U value)
 Spin UNTIL (location & value) is true. More...
 

Variables

class friend class("tbb::reader_writer_lock
is deprecated, use
std::shared_mutex")
reader_writer_lock 
scoped_lock_read
 Writer-preference reader-writer lock with local-only spinning on readers. More...
 
atomic< scoped_lock_read * > reader_head
 The list of pending readers. More...
 
atomic< scoped_lock * > writer_head
 The list of pending writers. More...
 
atomic< scoped_lock * > writer_tail
 The last node in the list of pending writers. More...
 
tbb_thread::id my_current_writer
 Writer that owns the mutex; tbb_thread::id() otherwise. More...
 
atomic< uintptr_t > rdr_count_and_flags
 Status of mutex. More...
 
const uintptr_t WFLAG1 = 0x1
 
const uintptr_t WFLAG2 = 0x2
 
const uintptr_t RFLAG = 0x4
 
const uintptr_t RC_INCR = 0x8
 

Enumeration Type Documentation

Status type for nodes associated with lock instances.

waiting_nonblocking: the wait state for nonblocking lock instances; for writes, these transition straight to active states; for reads, these are unused.

waiting: the start and spin state for all lock instances; these will transition to active state when appropriate. Non-blocking write locks transition from this state to waiting_nonblocking immediately.

active: the active state means that the lock instance holds the lock; it will transition to invalid state during node deletion

invalid: the end state for all nodes; this is set in the destructor so if we encounter this state, we are looking at memory that has already been freed

The state diagrams below describe the status transitions. Single arrows indicate that the thread that owns the node is responsible for the transition; double arrows indicate that any thread could make the transition.

State diagram for scoped_lock status:

waiting -------—> waiting_nonblocking | _____________/ | V V V active --------------—> invalid

State diagram for scoped_lock_read status:

waiting | V active --------------—>invalid

Enumerator
waiting_nonblocking 
waiting 
active 
invalid 

Definition at line 85 of file reader_writer_lock.h.

Function Documentation

template<typename T >
tbb::interface5::__TBB_DEPRECATED_MSG ( "tbb::tbb_hasher is  deprecated,
use std::hash"   
) const

Hasher functions.

Definition at line 61 of file _tbb_hash_compare_impl.h.

References tbb::interface5::internal::hash_multiplier.

61  {
62  return static_cast<size_t>( t ) * internal::hash_multiplier;
63 }
static const size_t hash_multiplier
Hash multiplier.
template<typename E , typename S , typename A >
tbb::interface5::__TBB_DEPRECATED_MSG ( "tbb::tbb_hasher is  deprecated,
use std::hash"   
) const

Definition at line 70 of file _tbb_hash_compare_impl.h.

References h, and tbb::interface5::internal::hash_multiplier.

70  {
71  size_t h = 0;
72  for( const E* c = s.c_str(); *c; ++c )
73  h = static_cast<size_t>(*c) ^ (h * internal::hash_multiplier);
74  return h;
75 }
void const char const char int ITT_FORMAT __itt_group_sync s
static const size_t hash_multiplier
Hash multiplier.
void const char const char int ITT_FORMAT __itt_group_sync x void const char ITT_FORMAT __itt_group_sync s void ITT_FORMAT __itt_group_sync p void ITT_FORMAT p void ITT_FORMAT p no args __itt_suppress_mode_t unsigned int void size_t ITT_FORMAT d void ITT_FORMAT p void ITT_FORMAT p __itt_model_site __itt_model_site_instance ITT_FORMAT p __itt_model_task __itt_model_task_instance ITT_FORMAT p void ITT_FORMAT p void ITT_FORMAT p void size_t ITT_FORMAT d void ITT_FORMAT p const wchar_t ITT_FORMAT s const char ITT_FORMAT s const char ITT_FORMAT s const char ITT_FORMAT s no args void ITT_FORMAT p size_t ITT_FORMAT d no args const wchar_t const wchar_t ITT_FORMAT s __itt_heap_function h
template<typename F , typename S >
tbb::interface5::__TBB_DEPRECATED_MSG ( "tbb::tbb_hasher is  deprecated,
use std::hash"   
) const

Definition at line 77 of file _tbb_hash_compare_impl.h.

77  {
78  return tbb_hasher(p.first) ^ tbb_hasher(p.second);
79 }
void const char const char int ITT_FORMAT __itt_group_sync p
void tbb::interface5::reader_writer_lock::end_read ( )
private

Relinquishes read lock by decrementing counter; last reader wakes pending writer.

Definition at line 282 of file reader_writer_lock.cpp.

References __TBB_ASSERT, ITT_NOTIFY, RC_INCR, rdr_count_and_flags, and sync_releasing.

282  {
283  ITT_NOTIFY(sync_releasing, this);
284  __TBB_ASSERT(rdr_count_and_flags >= RC_INCR, "unlock() called but no readers hold the lock.");
286 }
#define __TBB_ASSERT(predicate, comment)
No-op version of __TBB_ASSERT.
Definition: tbb_stddef.h:165
#define ITT_NOTIFY(name, obj)
Definition: itt_notify.h:112
atomic< uintptr_t > rdr_count_and_flags
Status of mutex.
void const char const char int ITT_FORMAT __itt_group_sync x void const char ITT_FORMAT __itt_group_sync s void ITT_FORMAT __itt_group_sync p void ITT_FORMAT p sync_releasing
const uintptr_t RC_INCR
void tbb::interface5::reader_writer_lock::end_write ( scoped_lock *  I)
private

Relinquishes write lock to next waiting writer or group of readers.

Definition at line 260 of file reader_writer_lock.cpp.

References __TBB_ASSERT, active, fetch_and_and(), id, ITT_NOTIFY, my_current_writer, tbb::interface5::scoped_lock::next, rdr_count_and_flags, RFLAG, set_next_writer(), tbb::internal::spin_wait_while_eq(), sync_releasing, unblock_readers(), WFLAG1, WFLAG2, writer_head, and writer_tail.

260  {
261  __TBB_ASSERT(I==writer_head, "Internal error: can't unlock a thread that is not holding the lock.");
263  ITT_NOTIFY(sync_releasing, this);
264  if (I->next) { // potentially more writers
265  writer_head = I->next;
266  writer_head->status = active;
267  }
268  else { // No more writers; clear writer flag, test reader interest flag
269  __TBB_ASSERT(writer_head, NULL);
271  unblock_readers();
272  }
273  writer_head.fetch_and_store(NULL);
274  if (I != writer_tail.compare_and_swap(NULL, I)) { // an incoming writer is in the process of being added
275  spin_wait_while_eq(I->next, (scoped_lock *)NULL); // wait for new writer to be added
276  __TBB_ASSERT(I->next, "There should be a node following the last writer.");
277  set_next_writer(I->next);
278  }
279  }
280 }
uintptr_t fetch_and_and(atomic< uintptr_t > &operand, uintptr_t value)
void spin_wait_while_eq(const volatile T &location, U value)
Spin WHILE the value of the variable is equal to a given value.
Definition: tbb_machine.h:391
tbb_thread::id my_current_writer
Writer that owns the mutex; tbb_thread::id() otherwise.
atomic< scoped_lock * > writer_head
The list of pending writers.
#define __TBB_ASSERT(predicate, comment)
No-op version of __TBB_ASSERT.
Definition: tbb_stddef.h:165
void set_next_writer(scoped_lock *w)
Sets writer_head to w and attempts to unblock.
#define ITT_NOTIFY(name, obj)
Definition: itt_notify.h:112
friend class scoped_lock
Definition: mutex.h:79
const uintptr_t RFLAG
const uintptr_t WFLAG2
atomic< uintptr_t > rdr_count_and_flags
Status of mutex.
atomic< scoped_lock * > writer_tail
The last node in the list of pending writers.
void const char const char int ITT_FORMAT __itt_group_sync x void const char ITT_FORMAT __itt_group_sync s void ITT_FORMAT __itt_group_sync p void ITT_FORMAT p sync_releasing
const uintptr_t WFLAG1
void unblock_readers()
Unblocks pending readers.
void const char const char int ITT_FORMAT __itt_group_sync x void const char ITT_FORMAT __itt_group_sync s void ITT_FORMAT __itt_group_sync p void ITT_FORMAT p void ITT_FORMAT p no args __itt_suppress_mode_t unsigned int void size_t ITT_FORMAT d void ITT_FORMAT p void ITT_FORMAT p __itt_model_site __itt_model_site_instance ITT_FORMAT p __itt_model_task __itt_model_task_instance ITT_FORMAT p void ITT_FORMAT p void ITT_FORMAT p void size_t ITT_FORMAT d void ITT_FORMAT p const wchar_t ITT_FORMAT s const char ITT_FORMAT s const char ITT_FORMAT s const char ITT_FORMAT s no args void ITT_FORMAT p size_t ITT_FORMAT d no args const wchar_t const wchar_t ITT_FORMAT s __itt_heap_function void size_t int ITT_FORMAT d __itt_heap_function void ITT_FORMAT p __itt_heap_function void void size_t int ITT_FORMAT d no args no args unsigned int ITT_FORMAT u const __itt_domain __itt_id id

Here is the call graph for this function:

uintptr_t tbb::interface5::fetch_and_and ( atomic< uintptr_t > &  operand,
uintptr_t  value 
)
inline

Definition at line 46 of file reader_writer_lock.cpp.

References tbb::internal::atomic_backoff::pause().

Referenced by end_write().

46  {
48  uintptr_t old = operand;
49  uintptr_t result = operand.compare_and_swap(old&value, old);
50  if (result==old) return result;
51  }
52 }
void const char const char int ITT_FORMAT __itt_group_sync x void const char ITT_FORMAT __itt_group_sync s void ITT_FORMAT __itt_group_sync p void ITT_FORMAT p void ITT_FORMAT p no args __itt_suppress_mode_t unsigned int void size_t ITT_FORMAT d void ITT_FORMAT p void ITT_FORMAT p __itt_model_site __itt_model_site_instance ITT_FORMAT p __itt_model_task __itt_model_task_instance ITT_FORMAT p void ITT_FORMAT p void ITT_FORMAT p void size_t ITT_FORMAT d void ITT_FORMAT p const wchar_t ITT_FORMAT s const char ITT_FORMAT s const char ITT_FORMAT s const char ITT_FORMAT s no args void ITT_FORMAT p size_t ITT_FORMAT d no args const wchar_t const wchar_t ITT_FORMAT s __itt_heap_function void size_t int ITT_FORMAT d __itt_heap_function void ITT_FORMAT p __itt_heap_function void void size_t int ITT_FORMAT d no args no args unsigned int ITT_FORMAT u const __itt_domain __itt_id ITT_FORMAT lu const __itt_domain __itt_id __itt_id __itt_string_handle ITT_FORMAT p const __itt_domain __itt_id ITT_FORMAT p const __itt_domain __itt_id __itt_timestamp __itt_timestamp ITT_FORMAT lu const __itt_domain __itt_id __itt_id __itt_string_handle ITT_FORMAT p const __itt_domain ITT_FORMAT p const __itt_domain __itt_string_handle unsigned long long value
void pause()
Pause for a while.
Definition: tbb_machine.h:360
Class that implements exponential backoff.
Definition: tbb_machine.h:345

Here is the call graph for this function:

Here is the caller graph for this function:

uintptr_t tbb::interface5::fetch_and_or ( atomic< uintptr_t > &  operand,
uintptr_t  value 
)
inline

Definition at line 37 of file reader_writer_lock.cpp.

References tbb::internal::atomic_backoff::pause().

Referenced by set_next_writer(), and start_read().

37  {
39  uintptr_t old = operand;
40  uintptr_t result = operand.compare_and_swap(old|value, old);
41  if (result==old) return result;
42  }
43 }
void const char const char int ITT_FORMAT __itt_group_sync x void const char ITT_FORMAT __itt_group_sync s void ITT_FORMAT __itt_group_sync p void ITT_FORMAT p void ITT_FORMAT p no args __itt_suppress_mode_t unsigned int void size_t ITT_FORMAT d void ITT_FORMAT p void ITT_FORMAT p __itt_model_site __itt_model_site_instance ITT_FORMAT p __itt_model_task __itt_model_task_instance ITT_FORMAT p void ITT_FORMAT p void ITT_FORMAT p void size_t ITT_FORMAT d void ITT_FORMAT p const wchar_t ITT_FORMAT s const char ITT_FORMAT s const char ITT_FORMAT s const char ITT_FORMAT s no args void ITT_FORMAT p size_t ITT_FORMAT d no args const wchar_t const wchar_t ITT_FORMAT s __itt_heap_function void size_t int ITT_FORMAT d __itt_heap_function void ITT_FORMAT p __itt_heap_function void void size_t int ITT_FORMAT d no args no args unsigned int ITT_FORMAT u const __itt_domain __itt_id ITT_FORMAT lu const __itt_domain __itt_id __itt_id __itt_string_handle ITT_FORMAT p const __itt_domain __itt_id ITT_FORMAT p const __itt_domain __itt_id __itt_timestamp __itt_timestamp ITT_FORMAT lu const __itt_domain __itt_id __itt_id __itt_string_handle ITT_FORMAT p const __itt_domain ITT_FORMAT p const __itt_domain __itt_string_handle unsigned long long value
void pause()
Pause for a while.
Definition: tbb_machine.h:360
Class that implements exponential backoff.
Definition: tbb_machine.h:345

Here is the call graph for this function:

Here is the caller graph for this function:

void __TBB_EXPORTED_METHOD tbb::interface5::internal_construct ( )
private
void __TBB_EXPORTED_METHOD tbb::interface5::internal_destroy ( )
private
bool tbb::interface5::reader_writer_lock::is_current_writer ( )
inlineprivate

Checks if current thread holds write lock.

Definition at line 288 of file reader_writer_lock.cpp.

References tbb::this_tbb_thread::get_id(), and my_current_writer.

288  {
290 }
tbb_thread::id my_current_writer
Writer that owns the mutex; tbb_thread::id() otherwise.
__TBB_DEPRECATED_IN_VERBOSE_MODE tbb_thread::id get_id()
Definition: tbb_thread.h:331

Here is the call graph for this function:

void __TBB_EXPORTED_METHOD tbb::interface5::lock ( )

Acquires the reader_writer_lock for write.

If the lock is currently held in write mode by another context, the writer will block by spinning on a local variable. Exceptions thrown: improper_lock The context tries to acquire a reader_writer_lock that it already has write ownership of.

Acquires the reader_writer_lock for write.

Definition at line 157 of file mutex.h.

References tbb::internal::handle_perror(), tbb::impl, and tbb::scoped_lock.

Referenced by tbb::flow::interface11::source_node< Output >::activate(), tbb::internal::market::arena_in_need(), tbb::internal::generic_scheduler::cleanup_master(), tbb::internal::market::create_arena(), tbb::internal::generic_scheduler::create_master(), tbb::flow::interface11::limiter_node< T, U >::decrement_counter(), tbb::internal::task_stream< num_priority_levels >::drain(), tbb::flow::interface11::limiter_node< T, U >::forward_task(), tbb::internal::market::global_market(), tbb::internal::input_buffer::has_item(), tbb::flow::interface11::internal::join_node_FE< queueing, InputTuple, OutputTuple >::increment_port_count(), tbb::flow::interface11::opencl_factory< default_device_filter >::init(), tbb::flow::interface11::opencl_factory< default_device_filter >::init_once(), tbb::interface9::global_control::internal_create(), tbb::interface9::global_control::internal_destroy(), tbb::interface5::concurrent_hash_map< Key, T, HashCompare, A >::internal_fast_find(), tbb::strict_ppl::internal::micro_queue< T >::invalidate_page_and_rethrow(), tbb::internal::msvc_inline_asm::lock_and(), tbb::internal::msvc_inline_asm::lock_or(), tbb::internal::micro_queue::make_invalid(), tbb::internal::market::max_num_workers(), tbb::internal::input_buffer::note_done(), tbb::internal::task_stream< num_priority_levels >::pop(), tbb::internal::task_stream< num_priority_levels >::pop_specific(), tbb::internal::micro_queue::push(), tbb::internal::task_stream< num_priority_levels >::push(), tbb::strict_ppl::internal::micro_queue< T >::push(), tbb::internal::input_buffer::put_token(), tbb::flow::interface10::graph::register_node(), tbb::flow::interface11::limiter_node< T, U >::register_predecessor(), tbb::flow::interface11::input_node< Output >::register_successor(), tbb::flow::interface11::source_node< Output >::register_successor(), tbb::flow::interface11::limiter_node< T, U >::register_successor(), tbb::internal::market::release(), tbb::flow::interface10::graph::remove_node(), tbb::internal::input_buffer::return_item(), tbb::flow::interface11::opencl_memory< Factory >::send(), tbb::internal::market::set_active_num_workers(), tbb::flow::interface11::internal::join_node_FE< queueing, InputTuple, OutputTuple >::set_my_node(), tbb::flow::interface11::source_node< Output >::try_consume(), tbb::flow::interface11::input_node< Output >::try_get(), tbb::flow::interface11::source_node< Output >::try_get(), tbb::internal::rml::private_server::try_insert_in_asleep_list(), tbb::internal::task_stream< num_priority_levels >::try_pop(), tbb::internal::task_stream< num_priority_levels >::try_push(), tbb::flow::interface11::limiter_node< T, U >::try_put_task(), tbb::flow::interface11::input_node< Output >::try_release(), tbb::flow::interface11::source_node< Output >::try_release(), tbb::flow::interface11::input_node< Output >::try_reserve(), tbb::flow::interface11::source_node< Output >::try_reserve(), tbb::flow::interface11::input_node< Output >::try_reserve_apply_body(), tbb::flow::interface11::source_node< Output >::try_reserve_apply_body(), tbb::internal::rml::private_server::wake_some(), tbb::internal::micro_queue_pop_finalizer::~micro_queue_pop_finalizer(), and tbb::strict_ppl::internal::micro_queue_pop_finalizer< T >::~micro_queue_pop_finalizer().

157  {
158 #if TBB_USE_ASSERT
159  aligned_space<scoped_lock> tmp;
160  new(tmp.begin()) scoped_lock(*this);
161 #else
162  #if _WIN32||_WIN64
163  EnterCriticalSection(&impl);
164  #else
165  int error_code = pthread_mutex_lock(&impl);
166  if( error_code )
167  tbb::internal::handle_perror(error_code,"mutex: pthread_mutex_lock failed");
168  #endif /* _WIN32||_WIN64 */
169 #endif /* TBB_USE_ASSERT */
170  }
friend class scoped_lock
Definition: mutex.h:79
pthread_mutex_t impl
Definition: mutex.h:223
void __TBB_EXPORTED_FUNC handle_perror(int error_code, const char *aux_info)
Throws std::runtime_error with what() returning error_code description prefixed with aux_info...
Definition: tbb_misc.cpp:87

Here is the call graph for this function:

Here is the caller graph for this function:

void __TBB_EXPORTED_METHOD tbb::interface5::lock_read ( )

Acquires the reader_writer_lock for read.

If the lock is currently held by a writer, this reader will block and wait until the writers are done. Exceptions thrown: improper_lock The context tries to acquire a reader_writer_lock that it already has write ownership of.

tbb::interface5::reader_writer_lock ( )

Constructs a new reader_writer_lock.

Definition at line 88 of file reader_writer_lock.h.

References internal_construct().

88  {
90  }
void __TBB_EXPORTED_METHOD internal_construct()

Here is the call graph for this function:

void tbb::interface5::reader_writer_lock::set_next_writer ( scoped_lock *  w)
private

Sets writer_head to w and attempts to unblock.

Definition at line 157 of file reader_writer_lock.cpp.

References __TBB_AtomicOR(), active, fetch_and_or(), RC_INCR, rdr_count_and_flags, RFLAG, spin_wait_until_and(), spin_wait_while_geq(), tbb::interface5::scoped_lock::status, waiting_nonblocking, WFLAG1, WFLAG2, and writer_head.

Referenced by end_write(), and start_write().

157  {
158  writer_head = W;
159  if (W->status == waiting_nonblocking) {
160  if (rdr_count_and_flags.compare_and_swap(WFLAG1+WFLAG2, 0) == 0) {
161  W->status = active;
162  }
163  }
164  else {
165  if (fetch_and_or(rdr_count_and_flags, WFLAG1) & RFLAG) { // reader present
166  spin_wait_until_and(rdr_count_and_flags, WFLAG2); // block until readers set WFLAG2
167  }
168  else { // no reader in timing window
170  }
171  spin_wait_while_geq(rdr_count_and_flags, RC_INCR); // block until readers finish
172  W->status = active;
173  }
174 }
atomic< scoped_lock * > writer_head
The list of pending writers.
void __TBB_AtomicOR(volatile void *operand, uintptr_t addend)
Definition: tbb_machine.h:878
const uintptr_t RFLAG
const uintptr_t WFLAG2
atomic< uintptr_t > rdr_count_and_flags
Status of mutex.
uintptr_t fetch_and_or(atomic< uintptr_t > &operand, uintptr_t value)
const uintptr_t WFLAG1
void spin_wait_while_geq(const volatile T &location, U value)
Spin WHILE the value at the location is greater than or equal to a given value.
const uintptr_t RC_INCR
void spin_wait_until_and(const volatile T &location, U value)
Spin UNTIL (location & value) is true.

Here is the call graph for this function:

Here is the caller graph for this function:

template<typename T , typename U >
void tbb::interface5::spin_wait_until_and ( const volatile T &  location,
value 
)

Spin UNTIL (location & value) is true.

T and U should be comparable types.

Definition at line 65 of file reader_writer_lock.cpp.

References tbb::internal::atomic_backoff::pause().

Referenced by set_next_writer().

65  {
67  while( !(location & value) ) backoff.pause();
68 }
void const char const char int ITT_FORMAT __itt_group_sync x void const char ITT_FORMAT __itt_group_sync s void ITT_FORMAT __itt_group_sync p void ITT_FORMAT p void ITT_FORMAT p no args __itt_suppress_mode_t unsigned int void size_t ITT_FORMAT d void ITT_FORMAT p void ITT_FORMAT p __itt_model_site __itt_model_site_instance ITT_FORMAT p __itt_model_task __itt_model_task_instance ITT_FORMAT p void ITT_FORMAT p void ITT_FORMAT p void size_t ITT_FORMAT d void ITT_FORMAT p const wchar_t ITT_FORMAT s const char ITT_FORMAT s const char ITT_FORMAT s const char ITT_FORMAT s no args void ITT_FORMAT p size_t ITT_FORMAT d no args const wchar_t const wchar_t ITT_FORMAT s __itt_heap_function void size_t int ITT_FORMAT d __itt_heap_function void ITT_FORMAT p __itt_heap_function void void size_t int ITT_FORMAT d no args no args unsigned int ITT_FORMAT u const __itt_domain __itt_id ITT_FORMAT lu const __itt_domain __itt_id __itt_id __itt_string_handle ITT_FORMAT p const __itt_domain __itt_id ITT_FORMAT p const __itt_domain __itt_id __itt_timestamp __itt_timestamp ITT_FORMAT lu const __itt_domain __itt_id __itt_id __itt_string_handle ITT_FORMAT p const __itt_domain ITT_FORMAT p const __itt_domain __itt_string_handle unsigned long long value
void pause()
Pause for a while.
Definition: tbb_machine.h:360
Class that implements exponential backoff.
Definition: tbb_machine.h:345

Here is the call graph for this function:

Here is the caller graph for this function:

template<typename T , typename U >
void tbb::interface5::spin_wait_while_geq ( const volatile T &  location,
value 
)

Spin WHILE the value at the location is greater than or equal to a given value.

T and U should be comparable types.

Definition at line 57 of file reader_writer_lock.cpp.

References tbb::internal::atomic_backoff::pause().

Referenced by set_next_writer().

57  {
59  while( location>=value ) backoff.pause();
60 }
void const char const char int ITT_FORMAT __itt_group_sync x void const char ITT_FORMAT __itt_group_sync s void ITT_FORMAT __itt_group_sync p void ITT_FORMAT p void ITT_FORMAT p no args __itt_suppress_mode_t unsigned int void size_t ITT_FORMAT d void ITT_FORMAT p void ITT_FORMAT p __itt_model_site __itt_model_site_instance ITT_FORMAT p __itt_model_task __itt_model_task_instance ITT_FORMAT p void ITT_FORMAT p void ITT_FORMAT p void size_t ITT_FORMAT d void ITT_FORMAT p const wchar_t ITT_FORMAT s const char ITT_FORMAT s const char ITT_FORMAT s const char ITT_FORMAT s no args void ITT_FORMAT p size_t ITT_FORMAT d no args const wchar_t const wchar_t ITT_FORMAT s __itt_heap_function void size_t int ITT_FORMAT d __itt_heap_function void ITT_FORMAT p __itt_heap_function void void size_t int ITT_FORMAT d no args no args unsigned int ITT_FORMAT u const __itt_domain __itt_id ITT_FORMAT lu const __itt_domain __itt_id __itt_id __itt_string_handle ITT_FORMAT p const __itt_domain __itt_id ITT_FORMAT p const __itt_domain __itt_id __itt_timestamp __itt_timestamp ITT_FORMAT lu const __itt_domain __itt_id __itt_id __itt_string_handle ITT_FORMAT p const __itt_domain ITT_FORMAT p const __itt_domain __itt_string_handle unsigned long long value
void pause()
Pause for a while.
Definition: tbb_machine.h:360
Class that implements exponential backoff.
Definition: tbb_machine.h:345

Here is the call graph for this function:

Here is the caller graph for this function:

void tbb::interface5::reader_writer_lock::start_read ( scoped_lock_read *  I)
private

Attempts to acquire read lock.

If unavailable, spins in blocking case, returns false in non-blocking case.

Definition at line 209 of file reader_writer_lock.cpp.

References __TBB_ASSERT, active, fetch_and_or(), ITT_NOTIFY, tbb::interface5::scoped_lock_read::next, RC_INCR, rdr_count_and_flags, reader_head, RFLAG, tbb::internal::spin_wait_while_eq(), tbb::interface5::scoped_lock_read::status, unblock_readers(), waiting, WFLAG1, and WFLAG2.

209  {
210  ITT_NOTIFY(sync_prepare, this);
211  I->next = reader_head.fetch_and_store(I);
212  if (!I->next) { // first arriving reader in my group; set RFLAG, test writer flags
213  // unblock and/or update statuses of non-blocking readers
214  if (!(fetch_and_or(rdr_count_and_flags, RFLAG) & (WFLAG1+WFLAG2))) { // no writers
215  unblock_readers();
216  }
217  }
218  __TBB_ASSERT(I->status == waiting || I->status == active, "Lock requests should be waiting or active before blocking.");
219  spin_wait_while_eq(I->status, waiting); // block
220  if (I->next) {
221  __TBB_ASSERT(I->next->status == waiting, NULL);
223  I->next->status = active; // wake successor
224  }
225  ITT_NOTIFY(sync_acquired, this);
226 }
void spin_wait_while_eq(const volatile T &location, U value)
Spin WHILE the value of the variable is equal to a given value.
Definition: tbb_machine.h:391
#define __TBB_ASSERT(predicate, comment)
No-op version of __TBB_ASSERT.
Definition: tbb_stddef.h:165
#define ITT_NOTIFY(name, obj)
Definition: itt_notify.h:112
const uintptr_t RFLAG
const uintptr_t WFLAG2
atomic< uintptr_t > rdr_count_and_flags
Status of mutex.
atomic< scoped_lock_read * > reader_head
The list of pending readers.
uintptr_t fetch_and_or(atomic< uintptr_t > &operand, uintptr_t value)
const uintptr_t WFLAG1
void unblock_readers()
Unblocks pending readers.
const uintptr_t RC_INCR

Here is the call graph for this function:

bool tbb::interface5::reader_writer_lock::start_write ( scoped_lock *  I)
private

Attempts to acquire write lock.

If unavailable, spins in blocking case, returns false in non-blocking case.

Definition at line 118 of file reader_writer_lock.cpp.

References __TBB_ASSERT, tbb::this_tbb_thread::get_id(), id, ITT_NOTIFY, my_current_writer, tbb::interface5::scoped_lock::next, set_next_writer(), tbb::internal::spin_wait_while_eq(), tbb::interface5::scoped_lock::status, waiting, waiting_nonblocking, writer_head, and writer_tail.

118  {
120  scoped_lock *pred = NULL;
121  if (I->status == waiting_nonblocking) {
122  if ((pred = writer_tail.compare_and_swap(I, NULL)) != NULL) {
123  delete I;
124  return false;
125  }
126  }
127  else {
128  ITT_NOTIFY(sync_prepare, this);
129  pred = writer_tail.fetch_and_store(I);
130  }
131  if (pred)
132  pred->next = I;
133  else {
134  set_next_writer(I);
135  if (I->status == waiting_nonblocking) {
136  if (I->next) { // potentially more writers
137  set_next_writer(I->next);
138  }
139  else { // no more writers
140  writer_head.fetch_and_store(NULL);
141  if (I != writer_tail.compare_and_swap(NULL, I)) { // an incoming writer is in the process of being added
142  spin_wait_while_eq(I->next, (scoped_lock *)NULL); // wait for new writer to be added
143  __TBB_ASSERT(I->next, "There should be a node following the last writer.");
144  set_next_writer(I->next);
145  }
146  }
147  delete I;
148  return false;
149  }
150  }
151  spin_wait_while_eq(I->status, waiting);
152  ITT_NOTIFY(sync_acquired, this);
154  return true;
155 }
void spin_wait_while_eq(const volatile T &location, U value)
Spin WHILE the value of the variable is equal to a given value.
Definition: tbb_machine.h:391
tbb_thread::id my_current_writer
Writer that owns the mutex; tbb_thread::id() otherwise.
atomic< scoped_lock * > writer_head
The list of pending writers.
#define __TBB_ASSERT(predicate, comment)
No-op version of __TBB_ASSERT.
Definition: tbb_stddef.h:165
void set_next_writer(scoped_lock *w)
Sets writer_head to w and attempts to unblock.
#define ITT_NOTIFY(name, obj)
Definition: itt_notify.h:112
friend class scoped_lock
Definition: mutex.h:79
atomic< scoped_lock * > writer_tail
The last node in the list of pending writers.
__TBB_DEPRECATED_IN_VERBOSE_MODE tbb_thread::id get_id()
Definition: tbb_thread.h:331
void const char const char int ITT_FORMAT __itt_group_sync x void const char ITT_FORMAT __itt_group_sync s void ITT_FORMAT __itt_group_sync p void ITT_FORMAT p void ITT_FORMAT p no args __itt_suppress_mode_t unsigned int void size_t ITT_FORMAT d void ITT_FORMAT p void ITT_FORMAT p __itt_model_site __itt_model_site_instance ITT_FORMAT p __itt_model_task __itt_model_task_instance ITT_FORMAT p void ITT_FORMAT p void ITT_FORMAT p void size_t ITT_FORMAT d void ITT_FORMAT p const wchar_t ITT_FORMAT s const char ITT_FORMAT s const char ITT_FORMAT s const char ITT_FORMAT s no args void ITT_FORMAT p size_t ITT_FORMAT d no args const wchar_t const wchar_t ITT_FORMAT s __itt_heap_function void size_t int ITT_FORMAT d __itt_heap_function void ITT_FORMAT p __itt_heap_function void void size_t int ITT_FORMAT d no args no args unsigned int ITT_FORMAT u const __itt_domain __itt_id id

Here is the call graph for this function:

bool __TBB_EXPORTED_METHOD tbb::interface5::try_lock ( )

Tries to acquire the reader_writer_lock for write.

This function does not block. Return Value: True or false, depending on whether the lock is acquired or not. If the lock is already held by this acquiring context, try_lock() returns false.

Tries to acquire the reader_writer_lock for write.

Return true if lock acquired; false otherwise.

Definition at line 174 of file mutex.h.

References tbb::impl, and s.

174  {
175 #if TBB_USE_ASSERT
176  aligned_space<scoped_lock> tmp;
177  scoped_lock& s = *tmp.begin();
178  s.my_mutex = NULL;
179  return s.internal_try_acquire(*this);
180 #else
181  #if _WIN32||_WIN64
182  return TryEnterCriticalSection(&impl)!=0;
183  #else
184  return pthread_mutex_trylock(&impl)==0;
185  #endif /* _WIN32||_WIN64 */
186 #endif /* TBB_USE_ASSERT */
187  }
void const char const char int ITT_FORMAT __itt_group_sync s
friend class scoped_lock
Definition: mutex.h:79
pthread_mutex_t impl
Definition: mutex.h:223
bool __TBB_EXPORTED_METHOD tbb::interface5::try_lock_read ( )

Tries to acquire the reader_writer_lock for read.

This function does not block. Return Value: True or false, depending on whether the lock is acquired or not.

void tbb::interface5::reader_writer_lock::unblock_readers ( )
private

Unblocks pending readers.

Definition at line 228 of file reader_writer_lock.cpp.

References __TBB_ASSERT, __TBB_AtomicOR(), active, head, RC_INCR, rdr_count_and_flags, reader_head, RFLAG, tbb::interface5::scoped_lock_read::status, waiting, WFLAG1, and WFLAG2.

Referenced by end_write(), and start_read().

228  {
229  // clear rdr interest flag, increment rdr count
233  // indicate clear of window
236  }
237  // unblock waiting readers
238  scoped_lock_read *head = reader_head.fetch_and_store(NULL);
239  __TBB_ASSERT(head, NULL);
240  __TBB_ASSERT(head->status == waiting, NULL);
241  head->status = active;
242 }
#define __TBB_ASSERT(predicate, comment)
No-op version of __TBB_ASSERT.
Definition: tbb_stddef.h:165
void const char const char int ITT_FORMAT __itt_group_sync x void const char ITT_FORMAT __itt_group_sync s void ITT_FORMAT __itt_group_sync p void ITT_FORMAT p void ITT_FORMAT p no args __itt_suppress_mode_t unsigned int void size_t ITT_FORMAT d void ITT_FORMAT p void ITT_FORMAT p __itt_model_site __itt_model_site_instance ITT_FORMAT p __itt_model_task __itt_model_task_instance ITT_FORMAT p void ITT_FORMAT p void ITT_FORMAT p void size_t ITT_FORMAT d void ITT_FORMAT p const wchar_t ITT_FORMAT s const char ITT_FORMAT s const char ITT_FORMAT s const char ITT_FORMAT s no args void ITT_FORMAT p size_t ITT_FORMAT d no args const wchar_t const wchar_t ITT_FORMAT s __itt_heap_function void size_t int ITT_FORMAT d __itt_heap_function void ITT_FORMAT p __itt_heap_function void void size_t int ITT_FORMAT d no args no args unsigned int ITT_FORMAT u const __itt_domain __itt_id ITT_FORMAT lu const __itt_domain __itt_id __itt_id __itt_string_handle ITT_FORMAT p const __itt_domain __itt_id ITT_FORMAT p const __itt_domain __itt_id __itt_timestamp __itt_timestamp ITT_FORMAT lu const __itt_domain __itt_id __itt_id __itt_string_handle ITT_FORMAT p const __itt_domain ITT_FORMAT p const __itt_domain __itt_string_handle unsigned long long ITT_FORMAT lu const __itt_domain __itt_string_handle unsigned long long ITT_FORMAT lu const __itt_domain __itt_id __itt_string_handle __itt_metadata_type size_t void ITT_FORMAT p const __itt_domain __itt_id __itt_string_handle const wchar_t size_t ITT_FORMAT lu const __itt_domain __itt_id head
void __TBB_AtomicOR(volatile void *operand, uintptr_t addend)
Definition: tbb_machine.h:878
const uintptr_t RFLAG
const uintptr_t WFLAG2
atomic< uintptr_t > rdr_count_and_flags
Status of mutex.
atomic< scoped_lock_read * > reader_head
The list of pending readers.
const uintptr_t WFLAG1
const uintptr_t RC_INCR
class friend class("tbb::reader_writer_lock is deprecated, use std::shared_mutex") reader_writer_lock scoped_lock_read
Writer-preference reader-writer lock with local-only spinning on readers.

Here is the call graph for this function:

Here is the caller graph for this function:

void __TBB_EXPORTED_METHOD tbb::interface5::unlock ( )

Releases the reader_writer_lock.

Releases the reader_writer_lock.

Definition at line 190 of file mutex.h.

References tbb::impl, and s.

Referenced by tbb::internal::generic_scheduler::steal_task_from().

190  {
191 #if TBB_USE_ASSERT
192  aligned_space<scoped_lock> tmp;
193  scoped_lock& s = *tmp.begin();
194  s.my_mutex = this;
195  s.internal_release();
196 #else
197  #if _WIN32||_WIN64
198  LeaveCriticalSection(&impl);
199  #else
200  pthread_mutex_unlock(&impl);
201  #endif /* _WIN32||_WIN64 */
202 #endif /* TBB_USE_ASSERT */
203  }
void const char const char int ITT_FORMAT __itt_group_sync s
friend class scoped_lock
Definition: mutex.h:79
pthread_mutex_t impl
Definition: mutex.h:223

Here is the caller graph for this function:

tbb::interface5::~reader_writer_lock ( )

Destructs a reader_writer_lock object.

Definition at line 93 of file reader_writer_lock.h.

References internal_destroy().

93  {
95  }
void __TBB_EXPORTED_METHOD internal_destroy()

Here is the call graph for this function:

Variable Documentation

tbb_thread::id tbb::interface5::my_current_writer

Writer that owns the mutex; tbb_thread::id() otherwise.

Definition at line 232 of file reader_writer_lock.h.

Referenced by end_write(), is_current_writer(), and start_write().

const uintptr_t tbb::interface5::RC_INCR = 0x8

Definition at line 33 of file reader_writer_lock.cpp.

Referenced by end_read(), set_next_writer(), start_read(), and unblock_readers().

atomic<uintptr_t> tbb::interface5::rdr_count_and_flags

Status of mutex.

Definition at line 234 of file reader_writer_lock.h.

Referenced by end_read(), end_write(), set_next_writer(), start_read(), and unblock_readers().

atomic<scoped_lock_read*> tbb::interface5::reader_head

The list of pending readers.

Definition at line 226 of file reader_writer_lock.h.

Referenced by start_read(), and unblock_readers().

const uintptr_t tbb::interface5::RFLAG = 0x4

Definition at line 32 of file reader_writer_lock.cpp.

Referenced by end_write(), set_next_writer(), start_read(), and unblock_readers().

const uintptr_t tbb::interface5::WFLAG1 = 0x1

Definition at line 30 of file reader_writer_lock.cpp.

Referenced by end_write(), set_next_writer(), start_read(), and unblock_readers().

const uintptr_t tbb::interface5::WFLAG2 = 0x2

Definition at line 31 of file reader_writer_lock.cpp.

Referenced by end_write(), set_next_writer(), start_read(), and unblock_readers().

atomic<scoped_lock*> tbb::interface5::writer_head

The list of pending writers.

Definition at line 228 of file reader_writer_lock.h.

Referenced by end_write(), set_next_writer(), and start_write().

atomic<scoped_lock*> tbb::interface5::writer_tail

The last node in the list of pending writers.

Definition at line 230 of file reader_writer_lock.h.

Referenced by end_write(), and start_write().


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.