tbb::internal::rml::private_worker Class Reference
Inheritance diagram for tbb::internal::rml::private_worker:
Collaboration diagram for tbb::internal::rml::private_worker:

## Protected Member Functions

| private_worker (private_server &server, tbb_client &client, const size_t i)

## Private Types

enum | state_t { st_init, st_starting, st_normal, st_quit }
| State in finite-state machine that controls the worker. More...

## Private Member Functions

void | run ()
| Actions executed by the associated thread. More...
void | wake_or_launch ()
| Wake up associated thread (or launch a thread if there is none) More...
void | start_shutdown ()
| Called by a thread (usually not the associated thread) to commence termination. More...
Private Member Functions inherited from tbb::internal::no_copy
| no_copy (const no_copy &)=delete
| no_copy ()=default

## Static Private Member Functions

static __RML_DECL_THREAD_ROUTINE | thread_routine (void *arg)
static void | release_handle (thread_handle my_handle, bool join)

## Private Attributes

atomic< state_t > | my_state
private_server & | my_server
| Associated server. More...
tbb_client & | my_client
| Associated client. More...
const size_t | my_index
| index used for avoiding the 64K aliasing problem More...
thread_monitor | my_thread_monitor
| Monitor for sleeping when there is no work to do. More...
thread_handle | my_handle
| Handle of the OS thread associated with this worker. More...
private_worker * | my_next
| Link for list of workers that are sleeping or have no associated thread. More...

## Friends

class | private_server

## Detailed Description

Definition at line 35 of file private_server.cpp.

## Member Enumeration Documentation

## state_t

enum tbb::internal::rml::private_worker::state_t

private

State in finite-state machine that controls the worker.

State diagram: init --> starting --> normal | | | | V | ---—> quit <---—/

Enumerator
st_init | *this is initialized
st_starting | *this has associated thread that is starting up.
st_normal | Associated thread is doing normal life sequence.
st_quit | Associated thread has ended normal life sequence and promises to never touch *this again.

Definition at line 44 of file private_server.cpp.

{
st_init,
st_starting,
st_normal,
st_quit
};

## Constructor & Destructor Documentation

## private_worker()

tbb::internal::rml::private_worker::private_worker | ( | private_server & | server,
|  | tbb_client & | client,
|  | const size_t | i
| ) |  |

inline protected

Definition at line 92 of file private_server.cpp.

:
my_server(server), my_client(client), my_index(i),
my_thread_monitor(), my_handle(), my_next()
{
my_state = st_init;
}

References my_state, and st_init.

## Member Function Documentation

## release_handle()

void tbb::internal::rml::private_worker::release_handle | ( | thread_handle | my_handle,
|  | bool | join
| ) |  |

static private

Definition at line 226 of file private_server.cpp.

{
if (join)
thread_monitor::join(handle);
else
thread_monitor::detach_thread(handle);
}

Referenced by start_shutdown(), and wake_or_launch().

Here is the caller graph for this function:

## run()

void tbb::internal::rml::private_worker::run | ( |  | ) |

private

Actions executed by the associated thread.

Definition at line 256 of file private_server.cpp.

{
my_server.propagate_chain_reaction();
// Transiting to st_normal here would require setting my_handle,
// which would create race with the launching thread and
// complications in handle management on Windows.
::rml::job& j = *my_client.create_one_job();
while( my_state!=st_quit ) {
if( my_server.my_slack>=0 ) {
my_client.process(j);
} else {
thread_monitor::cookie c;
// Prepare to wait
my_thread_monitor.prepare_wait(c);
// Check/set the invariant for sleeping
if( my_state!=st_quit && my_server.try_insert_in_asleep_list(*this) ) {
my_thread_monitor.commit_wait(c);
__TBB_ASSERT( my_state==st_quit || !my_next, "Thread monitor missed a spurious wakeup?" );
my_server.propagate_chain_reaction();
} else {
// Invariant broken
my_thread_monitor.cancel_wait();
}
}
}
my_client.cleanup(j);
++my_server.my_slack;
my_server.remove_server_ref();
}

References __TBB_ASSERT, my_client, my_next, my_server, tbb::internal::rml::private_server::my_slack, my_state, my_thread_monitor, tbb::internal::rml::private_server::propagate_chain_reaction(), tbb::internal::rml::private_server::remove_server_ref(), st_quit, and tbb::internal::rml::private_server::try_insert_in_asleep_list().

Here is the call graph for this function:

## start_shutdown()

void tbb::internal::rml::private_worker::start_shutdown | ( |  | ) |

private

Called by a thread (usually not the associated thread) to commence termination.

Definition at line 233 of file private_server.cpp.

{
state_t s;
do {
s = my_state;
__TBB_ASSERT( s!=st_quit, NULL );
} while( my_state.compare_and_swap( st_quit, s )!=s );
if( s==st_normal || s==st_starting ) {
// May have invalidated invariant for sleeping, so wake up the thread.
// Note that the notify() here occurs without maintaining invariants for my_slack.
// It does not matter, because my_state==st_quit overrides checking of my_slack.
my_thread_monitor.notify();
// Do not need release handle in st_init state,
// because in this case the thread wasn't started yet.
// For st_starting release is done at launch site.
if (s==st_normal)
release_handle(my_handle, governor::does_client_join_workers(my_client));
} else if( s==st_init ) {
// Perform action that otherwise would be performed by associated thread when it quits.
my_server.remove_server_ref();
}
}

References __TBB_ASSERT, tbb::internal::governor::does_client_join_workers(), my_client, my_handle, my_server, my_state, my_thread_monitor, release_handle(), tbb::internal::rml::private_server::remove_server_ref(), s, st_init, st_normal, st_quit, and st_starting.

Here is the call graph for this function:

## thread_routine()

__RML_DECL_THREAD_ROUTINE tbb::internal::rml::private_worker::thread_routine | ( | void * | arg | ) |

static private

Definition at line 216 of file private_server.cpp.

{
private_worker* self = static_cast<private_worker*>(arg);
AVOID_64K_ALIASING( self->my_index );
self->run();
return 0;
}

Referenced by wake_or_launch().

Here is the caller graph for this function:

## wake_or_launch()

void tbb::internal::rml::private_worker::wake_or_launch | ( |  | ) |

inline private

Wake up associated thread (or launch a thread if there is none)

Definition at line 288 of file private_server.cpp.

{
if( my_state==st_init && my_state.compare_and_swap( st_starting, st_init )==st_init ) {
// after this point, remove_server_ref() must be done by created thread
#if USE_WINTHREAD
my_handle = thread_monitor::launch( thread_routine, this, my_server.my_stack_size, &this->my_index );
#elif USE_PTHREAD
{
affinity_helper fpa;
fpa.protect_affinity_mask( /*restore_process_mask=*/true );
my_handle = thread_monitor::launch( thread_routine, this, my_server.my_stack_size );
// Implicit destruction of fpa resets original affinity mask.
}
#endif /* USE_PTHREAD */
state_t s = my_state.compare_and_swap( st_normal, st_starting );
if (st_starting != s) {
// Do shutdown during startup. my_handle can't be released
// by start_shutdown, because my_handle value might be not set yet
// at time of transition from st_starting to st_quit.
__TBB_ASSERT( s==st_quit, NULL );
release_handle(my_handle, governor::does_client_join_workers(my_client));
}
}
else {
__TBB_ASSERT( !my_next, "Should not wake a thread while it's still in asleep list" );
my_thread_monitor.notify();
}
}

References __TBB_ASSERT, tbb::internal::governor::does_client_join_workers(), my_client, my_handle, my_next, my_server, tbb::internal::rml::private_server::my_stack_size, my_state, my_thread_monitor, tbb::internal::affinity_helper::protect_affinity_mask(), release_handle(), s, st_init, st_normal, st_quit, st_starting, and thread_routine().

Referenced by tbb::internal::rml::private_server::wake_some().

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

## Friends And Related Function Documentation

## private_server

friend class private_server

friend

Definition at line 76 of file private_server.cpp.

## Member Data Documentation

## my_client

tbb_client& tbb::internal::rml::private_worker::my_client

private

Associated client.

Definition at line 60 of file private_server.cpp.

Referenced by run(), start_shutdown(), and wake_or_launch().

## my_handle

thread_handle tbb::internal::rml::private_worker::my_handle

private

Handle of the OS thread associated with this worker.

Definition at line 71 of file private_server.cpp.

Referenced by start_shutdown(), and wake_or_launch().

## my_index

const size_t tbb::internal::rml::private_worker::my_index

private

index used for avoiding the 64K aliasing problem

Definition at line 63 of file private_server.cpp.

## my_next

private_worker* tbb::internal::rml::private_worker::my_next

private

Link for list of workers that are sleeping or have no associated thread.

Definition at line 74 of file private_server.cpp.

Referenced by tbb::internal::rml::private_server::private_server(), run(), tbb::internal::rml::private_server::try_insert_in_asleep_list(), wake_or_launch(), and tbb::internal::rml::private_server::wake_some().

## my_server

private_server& tbb::internal::rml::private_worker::my_server

private

Associated server.

Definition at line 57 of file private_server.cpp.

Referenced by run(), start_shutdown(), and wake_or_launch().

## my_state

atomic<state_t> tbb::internal::rml::private_worker::my_state

private

Definition at line 54 of file private_server.cpp.

Referenced by private_worker(), run(), start_shutdown(), and wake_or_launch().

## my_thread_monitor

thread_monitor tbb::internal::rml::private_worker::my_thread_monitor

private

Monitor for sleeping when there is no work to do.

The invariant that holds for sleeping workers is: "my_slack<=0 && my_state==st_normal && I am on server's list of asleep threads"

Definition at line 68 of file private_server.cpp.

Referenced by run(), start_shutdown(), and wake_or_launch().

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

- private_server.cpp

__TBB_ASSERT
#define __TBB_ASSERT(predicate, comment)
No-op version of __TBB_ASSERT.
Definition: tbb_stddef.h:165
tbb::internal::rml::private_server::my_slack
atomic< int > my_slack
Number of jobs that could use their associated thread minus number of active threads.
Definition: private_server.cpp:133
tbb::internal::rml::private_worker::st_normal
Associated thread is doing normal life sequence.
Definition: private_server.cpp:50
tbb::internal::rml::private_worker::my_client
tbb_client & my_client
Associated client.
Definition: private_server.cpp:60
tbb::internal::rml::private_worker::my_state
atomic< state_t > my_state
Definition: private_server.cpp:54
tbb::internal::rml::private_worker::st_init
*this is initialized
Definition: private_server.cpp:46
tbb::internal::rml::private_worker::my_index
const size_t my_index
index used for avoiding the 64K aliasing problem
Definition: private_server.cpp:63
tbb::internal::rml::private_worker::my_handle
thread_handle my_handle
Handle of the OS thread associated with this worker.
Definition: private_server.cpp:71
tbb::internal::governor::does_client_join_workers
static bool does_client_join_workers(const tbb::internal::rml::tbb_client &client)
Definition: market.cpp:304
tbb::internal::rml::private_worker::private_worker
private_worker(private_server &server, tbb_client &client, const size_t i)
Definition: private_server.cpp:92
tbb::internal::rml::private_worker::st_quit
Associated thread has ended normal life sequence and promises to never touch *this again.
Definition: private_server.cpp:52
tbb::internal::rml::private_worker::my_server
private_server & my_server
Associated server.
Definition: private_server.cpp:57
tbb::internal::rml::private_worker::thread_routine
static __RML_DECL_THREAD_ROUTINE thread_routine(void *arg)
Definition: private_server.cpp:216
s
void const char const char int ITT_FORMAT __itt_group_sync s
Definition: ittnotify_static.h:91
tbb::internal::rml::private_server::remove_server_ref
void remove_server_ref()
Definition: private_server.cpp:168
tbb::internal::rml::private_worker::my_next
private_worker * my_next
Link for list of workers that are sleeping or have no associated thread.
Definition: private_server.cpp:74
tbb::internal::rml::private_server::propagate_chain_reaction
void propagate_chain_reaction()
Wake up to two sleeping workers, if there are any sleeping.
Definition: private_server.cpp:154
tbb::internal::rml::private_worker::release_handle
static void release_handle(thread_handle my_handle, bool join)
Definition: private_server.cpp:226
tbb::internal::rml::private_server::try_insert_in_asleep_list
bool try_insert_in_asleep_list(private_worker &t)
Try to add t to list of sleeping workers.
Definition: private_server.cpp:347
tbb::internal::rml::private_worker::st_starting
*this has associated thread that is starting up.
Definition: private_server.cpp:48
tbb::internal::rml::private_worker::my_thread_monitor
thread_monitor my_thread_monitor
Monitor for sleeping when there is no work to do.
Definition: private_server.cpp:68
tbb::internal::rml::private_worker::state_t
state_t
State in finite-state machine that controls the worker.
Definition: private_server.cpp:44
tbb::internal::rml::private_server::my_stack_size
const size_t my_stack_size
Stack size for each thread. *‍/.
Definition: private_server.cpp:126

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.