Intel(R) Threading Building Blocks Doxygen Documentation version 4.2.3
Loading...
Searching...
No Matches
tbb::internal::concurrent_monitor Class Reference

concurrent_monitor More...

#include <concurrent_monitor.h>

Inheritance diagram for tbb::internal::concurrent_monitor:
Collaboration diagram for tbb::internal::concurrent_monitor:

Classes

class  thread_context
 

Public Member Functions

 concurrent_monitor ()
 ctor More...
 
 ~concurrent_monitor ()
 dtor More...
 
void prepare_wait (thread_context &thr, uintptr_t ctx=0)
 prepare wait by inserting 'thr' into the wait queue More...
 
bool commit_wait (thread_context &thr)
 Commit wait if event count has not changed; otherwise, cancel wait. More...
 
void cancel_wait (thread_context &thr)
 Cancel the wait. Removes the thread from the wait queue if not removed yet. More...
 
template<typename WaitUntil , typename Context >
void wait (WaitUntil until, Context on)
 Wait for a condition to be satisfied with waiting-on context. More...
 
void notify_one ()
 Notify one thread about the event. More...
 
void notify_one_relaxed ()
 Notify one thread about the event. Relaxed version. More...
 
void notify_all ()
 Notify all waiting threads of the event. More...
 
void notify_all_relaxed ()
 Notify all waiting threads of the event; Relaxed version. More...
 
template<typename P >
void notify (const P &predicate)
 Notify waiting threads of the event that satisfies the given predicate. More...
 
template<typename P >
void notify_relaxed (const P &predicate)
 Notify waiting threads of the event that satisfies the given predicate; Relaxed version. More...
 
void abort_all ()
 Abort any sleeping threads at the time of the call. More...
 
void abort_all_relaxed ()
 Abort any sleeping threads at the time of the call; Relaxed version. More...
 

Private Member Functions

thread_contextto_thread_context (waitset_node_t *n)
 
- Private Member Functions inherited from tbb::internal::no_copy
 no_copy (const no_copy &)=delete
 
 no_copy ()=default
 

Private Attributes

tbb::spin_mutex mutex_ec
 
waitset_t waitset_ec
 
__TBB_atomic unsigned epoch
 

Detailed Description

concurrent_monitor

fine-grained concurrent_monitor implementation

Definition at line 93 of file concurrent_monitor.h.

Constructor & Destructor Documentation

◆ concurrent_monitor()

tbb::internal::concurrent_monitor::concurrent_monitor ( )
inline

ctor

Definition at line 125 of file concurrent_monitor.h.

void __TBB_store_relaxed(volatile T &location, V value)
Definition: tbb_machine.h:739

References tbb::internal::__TBB_store_relaxed(), and epoch.

Here is the call graph for this function:

◆ ~concurrent_monitor()

tbb::internal::concurrent_monitor::~concurrent_monitor ( )

dtor

Definition at line 27 of file concurrent_monitor.cpp.

27 {
28 abort_all();
29 __TBB_ASSERT( waitset_ec.empty(), "waitset not empty?" );
30}
#define __TBB_ASSERT(predicate, comment)
No-op version of __TBB_ASSERT.
Definition: tbb_stddef.h:165
void abort_all()
Abort any sleeping threads at the time of the call.

References __TBB_ASSERT, abort_all(), tbb::internal::circular_doubly_linked_list_with_sentinel::empty(), and waitset_ec.

Here is the call graph for this function:

Member Function Documentation

◆ abort_all()

void tbb::internal::concurrent_monitor::abort_all ( )
inline

Abort any sleeping threads at the time of the call.

Definition at line 175 of file concurrent_monitor.h.

void atomic_fence()
Sequentially consistent full memory fence.
Definition: tbb_machine.h:339
void abort_all_relaxed()
Abort any sleeping threads at the time of the call; Relaxed version.

References abort_all_relaxed(), and tbb::atomic_fence().

Referenced by tbb::internal::concurrent_queue_base_v3::internal_abort(), and ~concurrent_monitor().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ abort_all_relaxed()

void tbb::internal::concurrent_monitor::abort_all_relaxed ( )

Abort any sleeping threads at the time of the call; Relaxed version.

Definition at line 107 of file concurrent_monitor.cpp.

107 {
108 if( waitset_ec.empty() )
109 return;
110 waitset_t temp;
111 const waitset_node_t* end;
112 {
115 waitset_ec.flush_to( temp );
116 end = temp.end();
117 for( waitset_node_t* n=temp.front(); n!=end; n=n->next )
118 to_thread_context(n)->in_waitset = false;
119 }
120 waitset_node_t* nxt;
121 for( waitset_node_t* n=temp.front(); n!=end; n=nxt ) {
122 nxt = n->next;
123 to_thread_context(n)->aborted = true;
125 }
126#if TBB_USE_ASSERT
127 temp.clear();
128#endif
129}
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 end
circular_doubly_linked_list_with_sentinel::node_t waitset_node_t
T __TBB_load_relaxed(const volatile T &location)
Definition: tbb_machine.h:735
circular_doubly_linked_list_with_sentinel waitset_t
Represents acquisition of a mutex.
Definition: spin_mutex.h:53
void flush_to(circular_doubly_linked_list_with_sentinel &lst)
move all elements to 'lst' and initialize the 'this' list
thread_context * to_thread_context(waitset_node_t *n)

References tbb::internal::__TBB_load_relaxed(), tbb::internal::__TBB_store_relaxed(), tbb::internal::concurrent_monitor::thread_context::aborted, tbb::internal::circular_doubly_linked_list_with_sentinel::clear(), tbb::internal::circular_doubly_linked_list_with_sentinel::empty(), tbb::internal::circular_doubly_linked_list_with_sentinel::end(), end, epoch, tbb::internal::circular_doubly_linked_list_with_sentinel::flush_to(), tbb::internal::circular_doubly_linked_list_with_sentinel::front(), tbb::internal::concurrent_monitor::thread_context::in_waitset, mutex_ec, tbb::internal::circular_doubly_linked_list_with_sentinel::node_t::next, tbb::internal::concurrent_monitor::thread_context::semaphore(), to_thread_context(), tbb::internal::binary_semaphore::V(), and waitset_ec.

Referenced by abort_all().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ cancel_wait()

void tbb::internal::concurrent_monitor::cancel_wait ( thread_context thr)

Cancel the wait. Removes the thread from the wait queue if not removed yet.

Definition at line 50 of file concurrent_monitor.cpp.

50 {
51 // possible skipped wakeup will be pumped in the following prepare_wait()
52 thr.skipped_wakeup = true;
53 // try to remove node from waitset
54 bool th_in_waitset = thr.in_waitset;
55 if( th_in_waitset ) {
57 if (thr.in_waitset) {
58 waitset_ec.remove( (waitset_t::node_t&)thr );
59 // node is removed from waitset, so there will be no wakeup
60 thr.in_waitset = false;
61 thr.skipped_wakeup = false;
62 }
63 }
64}

References tbb::internal::concurrent_monitor::thread_context::in_waitset, mutex_ec, tbb::internal::circular_doubly_linked_list_with_sentinel::remove(), tbb::internal::concurrent_monitor::thread_context::skipped_wakeup, and waitset_ec.

Referenced by commit_wait(), tbb::internal::concurrent_queue_base_v3::internal_insert_item(), tbb::internal::concurrent_queue_base_v3::internal_pop(), and wait().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ commit_wait()

bool tbb::internal::concurrent_monitor::commit_wait ( thread_context thr)
inline

Commit wait if event count has not changed; otherwise, cancel wait.

Returns true if committed, false if canceled.

Definition at line 135 of file concurrent_monitor.h.

135 {
136 const bool do_it = thr.epoch == __TBB_load_relaxed(epoch);
137 // this check is just an optimization
138 if( do_it ) {
139 __TBB_ASSERT( thr.ready, "use of commit_wait() without prior prepare_wait()");
140 thr.semaphore().P();
141 __TBB_ASSERT( !thr.in_waitset, "still in the queue?" );
142 if( thr.aborted )
144 } else {
145 cancel_wait( thr );
146 }
147 return do_it;
148 }
void throw_exception(exception_id eid)
Versionless convenience wrapper for throw_exception_v4()
void cancel_wait(thread_context &thr)
Cancel the wait. Removes the thread from the wait queue if not removed yet.

References __TBB_ASSERT, tbb::internal::__TBB_load_relaxed(), tbb::internal::concurrent_monitor::thread_context::aborted, cancel_wait(), tbb::internal::eid_user_abort, tbb::internal::concurrent_monitor::thread_context::epoch, epoch, tbb::internal::concurrent_monitor::thread_context::in_waitset, tbb::internal::binary_semaphore::P(), tbb::internal::concurrent_monitor::thread_context::ready, tbb::internal::concurrent_monitor::thread_context::semaphore(), and tbb::internal::throw_exception().

Referenced by tbb::internal::concurrent_queue_base_v3::internal_insert_item(), tbb::internal::concurrent_queue_base_v3::internal_pop(), and wait().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ notify()

template<typename P >
void tbb::internal::concurrent_monitor::notify ( const P &  predicate)
inline

Notify waiting threads of the event that satisfies the given predicate.

Definition at line 169 of file concurrent_monitor.h.

169{atomic_fence(); notify_relaxed( predicate );}
void notify_relaxed(const P &predicate)
Notify waiting threads of the event that satisfies the given predicate; Relaxed version.

References tbb::atomic_fence(), and notify_relaxed().

Referenced by tbb::internal::concurrent_queue_base_v3::internal_insert_if_not_full(), tbb::internal::concurrent_queue_base_v3::internal_insert_item(), tbb::internal::concurrent_queue_base_v3::internal_pop(), and tbb::internal::concurrent_queue_base_v3::internal_pop_if_present().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ notify_all()

void tbb::internal::concurrent_monitor::notify_all ( )
inline

Notify all waiting threads of the event.

Definition at line 163 of file concurrent_monitor.h.

void notify_all_relaxed()
Notify all waiting threads of the event; Relaxed version.

References tbb::atomic_fence(), and notify_all_relaxed().

Here is the call graph for this function:

◆ notify_all_relaxed()

void tbb::internal::concurrent_monitor::notify_all_relaxed ( )

Notify all waiting threads of the event; Relaxed version.

Definition at line 84 of file concurrent_monitor.cpp.

84 {
85 if( waitset_ec.empty() )
86 return;
87 waitset_t temp;
88 const waitset_node_t* end;
89 {
92 waitset_ec.flush_to( temp );
93 end = temp.end();
94 for( waitset_node_t* n=temp.front(); n!=end; n=n->next )
95 to_thread_context(n)->in_waitset = false;
96 }
97 waitset_node_t* nxt;
98 for( waitset_node_t* n=temp.front(); n!=end; n=nxt ) {
99 nxt = n->next;
101 }
102#if TBB_USE_ASSERT
103 temp.clear();
104#endif
105}

References tbb::internal::__TBB_load_relaxed(), tbb::internal::__TBB_store_relaxed(), tbb::internal::circular_doubly_linked_list_with_sentinel::clear(), tbb::internal::circular_doubly_linked_list_with_sentinel::empty(), tbb::internal::circular_doubly_linked_list_with_sentinel::end(), end, epoch, tbb::internal::circular_doubly_linked_list_with_sentinel::flush_to(), tbb::internal::circular_doubly_linked_list_with_sentinel::front(), tbb::internal::concurrent_monitor::thread_context::in_waitset, mutex_ec, tbb::internal::circular_doubly_linked_list_with_sentinel::node_t::next, tbb::internal::concurrent_monitor::thread_context::semaphore(), to_thread_context(), tbb::internal::binary_semaphore::V(), and waitset_ec.

Referenced by notify_all().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ notify_one()

void tbb::internal::concurrent_monitor::notify_one ( )
inline

Notify one thread about the event.

Definition at line 157 of file concurrent_monitor.h.

void notify_one_relaxed()
Notify one thread about the event. Relaxed version.

References tbb::atomic_fence(), and notify_one_relaxed().

Here is the call graph for this function:

◆ notify_one_relaxed()

void tbb::internal::concurrent_monitor::notify_one_relaxed ( )

Notify one thread about the event. Relaxed version.

Definition at line 66 of file concurrent_monitor.cpp.

66 {
67 if( waitset_ec.empty() )
68 return;
71 {
74 n = waitset_ec.front();
75 if( n!=end ) {
76 waitset_ec.remove( *n );
77 to_thread_context(n)->in_waitset = false;
78 }
79 }
80 if( n!=end )
82}

References tbb::internal::__TBB_load_relaxed(), tbb::internal::__TBB_store_relaxed(), tbb::internal::circular_doubly_linked_list_with_sentinel::empty(), tbb::internal::circular_doubly_linked_list_with_sentinel::end(), end, epoch, tbb::internal::circular_doubly_linked_list_with_sentinel::front(), tbb::internal::concurrent_monitor::thread_context::in_waitset, mutex_ec, tbb::internal::circular_doubly_linked_list_with_sentinel::remove(), tbb::internal::concurrent_monitor::thread_context::semaphore(), to_thread_context(), tbb::internal::binary_semaphore::V(), and waitset_ec.

Referenced by notify_one().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ notify_relaxed()

template<typename P >
void tbb::internal::concurrent_monitor::notify_relaxed ( const P &  predicate)

Notify waiting threads of the event that satisfies the given predicate; Relaxed version.

Definition at line 204 of file concurrent_monitor.h.

204 {
205 if( waitset_ec.empty() )
206 return;
207 waitset_t temp;
208 waitset_node_t* nxt;
209 const waitset_node_t* end = waitset_ec.end();
210 {
213 for( waitset_node_t* n=waitset_ec.last(); n!=end; n=nxt ) {
214 nxt = n->prev;
215 thread_context* thr = to_thread_context( n );
216 if( predicate( thr->context ) ) {
217 waitset_ec.remove( *n );
218 thr->in_waitset = false;
219 temp.add( n );
220 }
221 }
222 }
223
224 end = temp.end();
225 for( waitset_node_t* n=temp.front(); n!=end; n=nxt ) {
226 nxt = n->next;
228 }
229#if TBB_USE_ASSERT
230 temp.clear();
231#endif
232}

References tbb::internal::__TBB_load_relaxed(), tbb::internal::__TBB_store_relaxed(), tbb::internal::circular_doubly_linked_list_with_sentinel::add(), tbb::internal::circular_doubly_linked_list_with_sentinel::clear(), tbb::internal::concurrent_monitor::thread_context::context, tbb::internal::circular_doubly_linked_list_with_sentinel::empty(), tbb::internal::circular_doubly_linked_list_with_sentinel::end(), end, epoch, tbb::internal::circular_doubly_linked_list_with_sentinel::front(), tbb::internal::concurrent_monitor::thread_context::in_waitset, tbb::internal::circular_doubly_linked_list_with_sentinel::last(), mutex_ec, tbb::internal::circular_doubly_linked_list_with_sentinel::node_t::next, tbb::internal::circular_doubly_linked_list_with_sentinel::node_t::prev, tbb::internal::circular_doubly_linked_list_with_sentinel::remove(), tbb::internal::concurrent_monitor::thread_context::semaphore(), to_thread_context(), tbb::internal::binary_semaphore::V(), and waitset_ec.

Referenced by notify().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ prepare_wait()

void tbb::internal::concurrent_monitor::prepare_wait ( thread_context thr,
uintptr_t  ctx = 0 
)

prepare wait by inserting 'thr' into the wait queue

Definition at line 32 of file concurrent_monitor.cpp.

32 {
33 if( !thr.ready )
34 thr.init();
35 // this is good place to pump previous skipped wakeup
36 else if( thr.skipped_wakeup ) {
37 thr.skipped_wakeup = false;
38 thr.semaphore().P();
39 }
40 thr.context = ctx;
41 thr.in_waitset = true;
42 {
45 waitset_ec.add( (waitset_t::node_t*)&thr );
46 }
48}
void add(node_t *n)
add to the back of the list

References tbb::internal::__TBB_load_relaxed(), tbb::internal::__TBB_store_relaxed(), tbb::internal::circular_doubly_linked_list_with_sentinel::add(), tbb::atomic_fence(), tbb::internal::concurrent_monitor::thread_context::context, tbb::internal::concurrent_monitor::thread_context::epoch, epoch, tbb::internal::concurrent_monitor::thread_context::in_waitset, mutex_ec, tbb::internal::binary_semaphore::P(), tbb::internal::concurrent_monitor::thread_context::ready, tbb::internal::concurrent_monitor::thread_context::semaphore(), tbb::internal::concurrent_monitor::thread_context::skipped_wakeup, and waitset_ec.

Referenced by tbb::internal::concurrent_queue_base_v3::internal_insert_item(), tbb::internal::concurrent_queue_base_v3::internal_pop(), and wait().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ to_thread_context()

thread_context * tbb::internal::concurrent_monitor::to_thread_context ( waitset_node_t n)
inlineprivate

Definition at line 184 of file concurrent_monitor.h.

184{ return static_cast<thread_context*>(n); }

Referenced by abort_all_relaxed(), notify_all_relaxed(), notify_one_relaxed(), and notify_relaxed().

Here is the caller graph for this function:

◆ wait()

template<typename WaitUntil , typename Context >
void tbb::internal::concurrent_monitor::wait ( WaitUntil  until,
Context  on 
)

Wait for a condition to be satisfied with waiting-on context.

Definition at line 188 of file concurrent_monitor.h.

189{
190 bool slept = false;
191 thread_context thr_ctx;
192 prepare_wait( thr_ctx, on() );
193 while( !until() ) {
194 if( (slept = commit_wait( thr_ctx ) )==true )
195 if( until() ) break;
196 slept = false;
197 prepare_wait( thr_ctx, on() );
198 }
199 if( !slept )
200 cancel_wait( thr_ctx );
201}
void prepare_wait(thread_context &thr, uintptr_t ctx=0)
prepare wait by inserting 'thr' into the wait queue
bool commit_wait(thread_context &thr)
Commit wait if event count has not changed; otherwise, cancel wait.

References cancel_wait(), commit_wait(), and prepare_wait().

Here is the call graph for this function:

Member Data Documentation

◆ epoch

__TBB_atomic unsigned tbb::internal::concurrent_monitor::epoch
private

◆ mutex_ec

tbb::spin_mutex tbb::internal::concurrent_monitor::mutex_ec
private

◆ waitset_ec

waitset_t tbb::internal::concurrent_monitor::waitset_ec
private

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

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.