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

bool | 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_proxy * | internal_pop (__TBB_ISOLATION_EXPR(isolation_tag isolation))

## Static Private Attributes

static const int | mailbox_task_limit = 32

## Friends

class | mail_inbox

## Additional Inherited Members

Private Attributes inherited from tbb::internal::padded_base< T, S, R >
char | pad [S - R]

## Detailed Description

Class representing where mail is put.

Padded to occupy a cache line.

Definition at line 99 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 169 of file mailbox.h.

{
__TBB_ASSERT( sizeof(*this)==NFS_MaxLineSize, NULL );
__TBB_ASSERT( !my_first, NULL );
__TBB_ASSERT( !my_last, NULL );
__TBB_ASSERT( !my_is_idle, NULL );
my_last=&my_first;
suppress_unused_warning(pad);
}
__TBB_ASSERT
#define __TBB_ASSERT(predicate, comment)
No-op version of __TBB_ASSERT.
Definition: tbb_stddef.h:165
tbb::internal::NFS_MaxLineSize
const size_t NFS_MaxLineSize
Compile-time constant that is upper bound on cache line/sector size.
Definition: tbb_stddef.h:216
tbb::internal::suppress_unused_warning
void suppress_unused_warning(const T1 &)
Utility template function to prevent "unused" warnings by various compilers.
Definition: tbb_stddef.h:398
tbb::internal::padded_base::pad
char pad[S - R]
Definition: tbb_stddef.h:255

References __TBB_ASSERT, tbb::internal::NFS_MaxLineSize, tbb::internal::padded_base< T, S, R >::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 179 of file mailbox.h.

{
intptr_t k = 0;
// No fences here because other threads have already quit.
for( ; task_proxy* t = my_first; ++k ) {
my_first = t->next_in_mailbox;
NFS_Free((char*)t - task_prefix_reservation_size);
}
return k;
}
tbb::internal::NFS_Free
void __TBB_EXPORTED_FUNC NFS_Free(void *)
Free memory allocated by NFS_Allocate.
Definition: cache_aligned_allocator.cpp:198
tbb::internal::task_prefix_reservation_size
const size_t task_prefix_reservation_size
Number of bytes reserved for a task prefix.
Definition: scheduler_common.h:159

References 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 161 of file mailbox.h.

{
return __TBB_load_relaxed(my_first) == NULL;
}
tbb::internal::__TBB_load_relaxed
T __TBB_load_relaxed(const volatile T &location)
Definition: tbb_machine.h:738

References tbb::internal::__TBB_load_relaxed().

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) |  | ) |

inline private

Definition at line 102 of file mailbox.h.

{
task_proxy* curr = __TBB_load_relaxed( my_first );
if ( !curr )
return NULL;
task_proxy **prev_ptr = &my_first;
#if __TBB_TASK_ISOLATION
if ( isolation != no_isolation ) {
while ( curr->prefix().isolation != isolation ) {
prev_ptr = &curr->next_in_mailbox;
curr = curr->next_in_mailbox;
if ( !curr )
return NULL;
}
}
#endif /* __TBB_TASK_ISOLATION */
__TBB_control_consistency_helper(); // on my_first
// There is a first item in the mailbox. See if there is a second.
if ( task_proxy* second = curr->next_in_mailbox ) {
// There are at least two items, so first item can be popped easily.
*prev_ptr = second;
} else {
// There is only one item. Some care is required to pop it.
*prev_ptr = NULL;
if ( as_atomic( my_last ).compare_and_swap( prev_ptr, &curr->next_in_mailbox ) == &curr->next_in_mailbox ) {
// Successfully transitioned mailbox from having one item to having none.
__TBB_ASSERT( !curr->next_in_mailbox, NULL );
} else {
// Some other thread updated my_last but has not filled in first->next_in_mailbox
// Wait until first item points to second item.
atomic_backoff backoff;
while ( !(second = curr->next_in_mailbox) ) backoff.pause();
*prev_ptr = second;
}
}
--my_task_count;
__TBB_ASSERT( my_task_count >= 0, NULL );
__TBB_ASSERT( curr, NULL );
return curr;
}
__TBB_control_consistency_helper
#define __TBB_control_consistency_helper()
Definition: gcc_generic.h:60
tbb::internal::no_isolation
const isolation_tag no_isolation
Definition: task.h:144
tbb::internal::as_atomic
atomic< T > & as_atomic(T &t)
Definition: atomic.h:572

References __TBB_ASSERT, __TBB_control_consistency_helper, tbb::internal::__TBB_load_relaxed(), tbb::internal::as_atomic(), tbb::internal::task_prefix::isolation, tbb::internal::task_proxy::next_in_mailbox, tbb::internal::no_isolation, tbb::internal::atomic_backoff::pause(), and tbb::task::prefix().

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

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

## push()

bool tbb::internal::mail_outbox::push | ( | task_proxy * | t | ) |

inline

Push task_proxy onto the mailbox queue of another thread.

Implementation is wait-free. Returns false if there are too many tasks.

Definition at line 147 of file mailbox.h.

{
if (my_task_count > mailbox_task_limit)
return false;
++my_task_count;
__TBB_ASSERT(t, NULL);
t->next_in_mailbox = NULL;
proxy_ptr * const link = (proxy_ptr *)__TBB_FetchAndStoreW(&my_last,(intptr_t)&t->next_in_mailbox);
// No release fence required for the next store, because there are no memory operations
// between the previous fully fenced atomic operation and the store.
__TBB_store_relaxed(*link, t);
return true;
}
tbb::internal::__TBB_store_relaxed
void __TBB_store_relaxed(volatile T &location, V value)
Definition: tbb_machine.h:742
tbb::internal::mail_outbox::mailbox_task_limit
static const int mailbox_task_limit
Definition: mailbox.h:100

References __TBB_ASSERT, tbb::internal::__TBB_store_relaxed(), mailbox_task_limit, 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 190 of file mailbox.h.

{
return 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 142 of file mailbox.h.

## Member Data Documentation

## mailbox_task_limit

const int tbb::internal::mail_outbox::mailbox_task_limit = 32

static private

Definition at line 100 of file mailbox.h.

Referenced by push().

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

- mailbox.h

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.