Intel(R) Threading Building Blocks Doxygen Documentation  version 4.2.3
tbb::internal::mail_outbox Class Reference

Class representing where mail is put. More...

#include <mailbox.h>

Inheritance diagram for tbb::internal::mail_outbox:
Collaboration diagram for tbb::internal::mail_outbox:

Public Member Functions

void push (task_proxy *t)
 Push task_proxy onto the mailbox queue of another thread. More...
 
bool empty ()
 Return true if mailbox is empty. More...
 
void construct ()
 Construct *this as a mailbox from zeroed memory. More...
 
intptr_t drain ()
 Drain the mailbox. More...
 
bool recipient_is_idle ()
 True if thread that owns this mailbox is looking for work. More...
 

Private Member Functions

task_proxyinternal_pop (__TBB_ISOLATION_EXPR(isolation_tag isolation))
 

Friends

class mail_inbox
 

Additional Inherited Members

- Private Types inherited from tbb::internal::unpadded_mail_outbox
typedef task_proxy *__TBB_atomic proxy_ptr
 
- Private Attributes inherited from tbb::internal::padded_base< unpadded_mail_outbox, NFS_MaxLineSize, sizeof(unpadded_mail_outbox) % NFS_MaxLineSize >
char pad [S - R]
 
- Private Attributes inherited from tbb::internal::unpadded_mail_outbox
proxy_ptr my_first
 Pointer to first task_proxy in mailbox, or NULL if box is empty. More...
 
proxy_ptr *__TBB_atomic my_last
 Pointer to pointer that will point to next item in the queue. Never NULL. More...
 
bool my_is_idle
 Owner of mailbox is not executing a task, and has drained its own task pool. More...
 

Detailed Description

Class representing where mail is put.

Padded to occupy a cache line.

Definition at line 100 of file mailbox.h.

Member Function Documentation

◆ construct()

void tbb::internal::mail_outbox::construct ( )
inline

Construct *this as a mailbox from zeroed memory.

Raise assertion if *this is not previously zeroed, or sizeof(this) is wrong. This method is provided instead of a full constructor since we know the object will be constructed in zeroed memory.

Definition at line 162 of file mailbox.h.

162  {
163  __TBB_ASSERT( sizeof(*this)==NFS_MaxLineSize, NULL );
164  __TBB_ASSERT( !my_first, NULL );
165  __TBB_ASSERT( !my_last, NULL );
166  __TBB_ASSERT( !my_is_idle, NULL );
167  my_last=&my_first;
169  }
bool my_is_idle
Owner of mailbox is not executing a task, and has drained its own task pool.
Definition: mailbox.h:95
#define __TBB_ASSERT(predicate, comment)
No-op version of __TBB_ASSERT.
Definition: tbb_stddef.h:169
void suppress_unused_warning(const T1 &)
Utility template function to prevent "unused" warnings by various compilers.
Definition: tbb_stddef.h:381
proxy_ptr *__TBB_atomic my_last
Pointer to pointer that will point to next item in the queue. Never NULL.
Definition: mailbox.h:92
const size_t NFS_MaxLineSize
Compile-time constant that is upper bound on cache line/sector size.
Definition: tbb_stddef.h:220
proxy_ptr my_first
Pointer to first task_proxy in mailbox, or NULL if box is empty.
Definition: mailbox.h:89

References __TBB_ASSERT, tbb::internal::unpadded_mail_outbox::my_first, tbb::internal::unpadded_mail_outbox::my_is_idle, tbb::internal::unpadded_mail_outbox::my_last, tbb::internal::NFS_MaxLineSize, tbb::internal::padded_base< unpadded_mail_outbox, NFS_MaxLineSize, sizeof(unpadded_mail_outbox) % NFS_MaxLineSize >::pad, and tbb::internal::suppress_unused_warning().

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

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

◆ drain()

intptr_t tbb::internal::mail_outbox::drain ( )
inline

Drain the mailbox.

Definition at line 172 of file mailbox.h.

172  {
173  intptr_t k = 0;
174  // No fences here because other threads have already quit.
175  for( ; task_proxy* t = my_first; ++k ) {
176  my_first = t->next_in_mailbox;
178  }
179  return k;
180  }
void __TBB_EXPORTED_FUNC NFS_Free(void *)
Free memory allocated by NFS_Allocate.
proxy_ptr my_first
Pointer to first task_proxy in mailbox, or NULL if box is empty.
Definition: mailbox.h:89
const size_t task_prefix_reservation_size
Number of bytes reserved for a task prefix.

References tbb::internal::unpadded_mail_outbox::my_first, tbb::internal::task_proxy::next_in_mailbox, tbb::internal::NFS_Free(), and tbb::internal::task_prefix_reservation_size.

Referenced by tbb::internal::arena::free_arena().

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

◆ empty()

bool tbb::internal::mail_outbox::empty ( )
inline

Return true if mailbox is empty.

Definition at line 154 of file mailbox.h.

154  {
155  return __TBB_load_relaxed(my_first) == NULL;
156  }
T __TBB_load_relaxed(const volatile T &location)
Definition: tbb_machine.h:739
proxy_ptr my_first
Pointer to first task_proxy in mailbox, or NULL if box is empty.
Definition: mailbox.h:89

References tbb::internal::__TBB_load_relaxed(), and tbb::internal::unpadded_mail_outbox::my_first.

Referenced by tbb::internal::mail_inbox::empty().

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

◆ internal_pop()

task_proxy* tbb::internal::mail_outbox::internal_pop ( __TBB_ISOLATION_EXPR(isolation_tag isolation)  )
inlineprivate

Definition at line 102 of file mailbox.h.

102  {
103  task_proxy* curr = __TBB_load_relaxed( my_first );
104  if ( !curr )
105  return NULL;
106  task_proxy **prev_ptr = &my_first;
107 #if __TBB_TASK_ISOLATION
108  if ( isolation != no_isolation ) {
109  while ( curr->prefix().isolation != isolation ) {
110  prev_ptr = &curr->next_in_mailbox;
111  curr = curr->next_in_mailbox;
112  if ( !curr )
113  return NULL;
114  }
115  }
116 #endif /* __TBB_TASK_ISOLATION */
117  __TBB_control_consistency_helper(); // on my_first
118  // There is a first item in the mailbox. See if there is a second.
119  if ( task_proxy* second = curr->next_in_mailbox ) {
120  // There are at least two items, so first item can be popped easily.
121  *prev_ptr = second;
122  } else {
123  // There is only one item. Some care is required to pop it.
124  *prev_ptr = NULL;
125  if ( as_atomic( my_last ).compare_and_swap( prev_ptr, &curr->next_in_mailbox ) == &curr->next_in_mailbox ) {
126  // Successfully transitioned mailbox from having one item to having none.
127  __TBB_ASSERT( !curr->next_in_mailbox, NULL );
128  } else {
129  // Some other thread updated my_last but has not filled in first->next_in_mailbox
130  // Wait until first item points to second item.
131  atomic_backoff backoff;
132  while ( !(second = curr->next_in_mailbox) ) backoff.pause();
133  *prev_ptr = second;
134  }
135  }
136  __TBB_ASSERT( curr, NULL );
137  return curr;
138  }
#define __TBB_ASSERT(predicate, comment)
No-op version of __TBB_ASSERT.
Definition: tbb_stddef.h:169
const isolation_tag no_isolation
Definition: task.h:129
proxy_ptr *__TBB_atomic my_last
Pointer to pointer that will point to next item in the queue. Never NULL.
Definition: mailbox.h:92
T __TBB_load_relaxed(const volatile T &location)
Definition: tbb_machine.h:739
proxy_ptr my_first
Pointer to first task_proxy in mailbox, or NULL if box is empty.
Definition: mailbox.h:89
#define __TBB_control_consistency_helper()
Definition: gcc_generic.h:64
atomic< T > & as_atomic(T &t)
Definition: atomic.h:547

References __TBB_ASSERT, __TBB_control_consistency_helper, tbb::internal::__TBB_load_relaxed(), tbb::internal::as_atomic(), tbb::internal::unpadded_mail_outbox::my_first, tbb::internal::unpadded_mail_outbox::my_last, tbb::internal::task_proxy::next_in_mailbox, tbb::internal::no_isolation, and tbb::internal::atomic_backoff::pause().

Referenced by tbb::internal::mail_inbox::pop().

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

◆ push()

void tbb::internal::mail_outbox::push ( task_proxy t)
inline

Push task_proxy onto the mailbox queue of another thread.

Implementation is wait-free.

Definition at line 144 of file mailbox.h.

144  {
145  __TBB_ASSERT(t, NULL);
146  t->next_in_mailbox = NULL;
147  proxy_ptr * const link = (proxy_ptr *)__TBB_FetchAndStoreW(&my_last,(intptr_t)&t->next_in_mailbox);
148  // No release fence required for the next store, because there are no memory operations
149  // between the previous fully fenced atomic operation and the store.
150  __TBB_store_relaxed(*link, t);
151  }
#define __TBB_ASSERT(predicate, comment)
No-op version of __TBB_ASSERT.
Definition: tbb_stddef.h:169
proxy_ptr *__TBB_atomic my_last
Pointer to pointer that will point to next item in the queue. Never NULL.
Definition: mailbox.h:92
void __TBB_store_relaxed(volatile T &location, V value)
Definition: tbb_machine.h:743
task_proxy *__TBB_atomic proxy_ptr
Definition: mailbox.h:86

References __TBB_ASSERT, tbb::internal::__TBB_store_relaxed(), tbb::internal::unpadded_mail_outbox::my_last, and tbb::internal::task_proxy::next_in_mailbox.

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

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

◆ recipient_is_idle()

bool tbb::internal::mail_outbox::recipient_is_idle ( )
inline

True if thread that owns this mailbox is looking for work.

Definition at line 183 of file mailbox.h.

183  {
184  return my_is_idle;
185  }
bool my_is_idle
Owner of mailbox is not executing a task, and has drained its own task pool.
Definition: mailbox.h:95

References tbb::internal::unpadded_mail_outbox::my_is_idle.

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

Here is the caller graph for this function:

Friends And Related Function Documentation

◆ mail_inbox

friend class mail_inbox
friend

Definition at line 140 of file mailbox.h.


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.