Intel(R) Threading Building Blocks Doxygen Documentation  version 4.2.3
tbb::internal::rml::private_server Class Reference
Inheritance diagram for tbb::internal::rml::private_server:
Collaboration diagram for tbb::internal::rml::private_server:

Public Member Functions

 private_server (tbb_client &client)
 
version_type version () const __TBB_override
 
void request_close_connection (bool) __TBB_override
 
void yield () __TBB_override
 
void independent_thread_number_changed (int) __TBB_override
 
unsigned default_concurrency () const __TBB_override
 
void adjust_job_count_estimate (int delta) __TBB_override
 

Private Types

typedef scheduler_mutex_type asleep_list_mutex_type
 Protects my_asleep_list_root. More...
 

Private Member Functions

void propagate_chain_reaction ()
 Wake up to two sleeping workers, if there are any sleeping. More...
 
bool try_insert_in_asleep_list (private_worker &t)
 Try to add t to list of sleeping workers. More...
 
void wake_some (int additional_slack)
 Equivalent of adding additional_slack to my_slack and waking up to 2 threads if my_slack permits. More...
 
virtual ~private_server ()
 
void remove_server_ref ()
 
- Private Member Functions inherited from tbb::internal::no_copy
 no_copy ()
 Allow default construction. More...
 

Private Attributes

tbb_client & my_client
 
const tbb_client::size_type my_n_thread
 Maximum number of threads to be created. More...
 
const size_t my_stack_size
 Stack size for each thread. */. More...
 
atomic< intmy_slack
 Number of jobs that could use their associated thread minus number of active threads. More...
 
atomic< intmy_ref_count
 Counter used to determine when to delete this. More...
 
padded_private_workermy_thread_array
 
tbb::atomic< private_worker * > my_asleep_list_root
 List of workers that are asleep or committed to sleeping until notified by another thread. More...
 
asleep_list_mutex_type my_asleep_list_mutex
 

Friends

class private_worker
 

Detailed Description

Definition at line 122 of file private_server.cpp.

Member Typedef Documentation

◆ asleep_list_mutex_type

Protects my_asleep_list_root.

Definition at line 148 of file private_server.cpp.

Constructor & Destructor Documentation

◆ ~private_server()

tbb::internal::rml::private_server::~private_server ( )
privatevirtual

Definition at line 343 of file private_server.cpp.

343  {
344  __TBB_ASSERT( my_net_slack_requests==0, NULL );
345  for( size_t i=my_n_thread; i--; )
346  my_thread_array[i].~padded_private_worker();
349 }
Meets "allocator" requirements of ISO C++ Standard, Section 20.1.5.
#define __TBB_ASSERT(predicate, comment)
No-op version of __TBB_ASSERT.
Definition: tbb_stddef.h:169
const tbb_client::size_type my_n_thread
Maximum number of threads to be created.
void deallocate(pointer p, size_type)
Free block of memory that starts on a cache line.
padded_private_worker * my_thread_array
void poison_pointer(T *__TBB_atomic &)
Definition: tbb_stddef.h:309

References __TBB_ASSERT, tbb::cache_aligned_allocator< T >::deallocate(), my_n_thread, my_thread_array, and tbb::internal::poison_pointer().

Referenced by remove_server_ref().

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

◆ private_server()

tbb::internal::rml::private_server::private_server ( tbb_client &  client)

Definition at line 323 of file private_server.cpp.

323  :
324  my_client(client),
325  my_n_thread(client.max_job_count()),
326  my_stack_size(client.min_stack_size()),
327  my_thread_array(NULL)
328 {
330  my_slack = 0;
331 #if TBB_USE_ASSERT
332  my_net_slack_requests = 0;
333 #endif /* TBB_USE_ASSERT */
334  my_asleep_list_root = NULL;
336  for( size_t i=0; i<my_n_thread; ++i ) {
337  private_worker* t = new( &my_thread_array[i] ) padded_private_worker( *this, client, i );
338  t->my_next = my_asleep_list_root;
340  }
341 }
Meets "allocator" requirements of ISO C++ Standard, Section 20.1.5.
atomic< int > my_ref_count
Counter used to determine when to delete this.
const size_t my_stack_size
Stack size for each thread. */.
const tbb_client::size_type my_n_thread
Maximum number of threads to be created.
pointer allocate(size_type n, const void *hint=0)
Allocate space for n objects, starting on a cache/sector line.
atomic< int > my_slack
Number of jobs that could use their associated thread minus number of active threads.
padded_private_worker * my_thread_array
tbb::atomic< private_worker * > my_asleep_list_root
List of workers that are asleep or committed to sleeping until notified by another thread.

References tbb::cache_aligned_allocator< T >::allocate(), my_asleep_list_root, my_n_thread, tbb::internal::rml::private_worker::my_next, my_ref_count, my_slack, and my_thread_array.

Here is the call graph for this function:

Member Function Documentation

◆ adjust_job_count_estimate()

void tbb::internal::rml::private_server::adjust_job_count_estimate ( int  delta)

Definition at line 403 of file private_server.cpp.

403  {
404 #if TBB_USE_ASSERT
405  my_net_slack_requests+=delta;
406 #endif /* TBB_USE_ASSERT */
407  if( delta<0 ) {
408  my_slack+=delta;
409  } else if( delta>0 ) {
410  wake_some( delta );
411  }
412 }
void wake_some(int additional_slack)
Equivalent of adding additional_slack to my_slack and waking up to 2 threads if my_slack permits.
atomic< int > my_slack
Number of jobs that could use their associated thread minus number of active threads.

References my_slack, and wake_some().

Here is the call graph for this function:

◆ default_concurrency()

unsigned tbb::internal::rml::private_server::default_concurrency ( ) const
inline

Definition at line 198 of file private_server.cpp.

198 { return governor::default_num_threads() - 1; }
static unsigned default_num_threads()
Definition: governor.h:85

References tbb::internal::governor::default_num_threads().

Here is the call graph for this function:

◆ independent_thread_number_changed()

void tbb::internal::rml::private_server::independent_thread_number_changed ( int  )
inline

Definition at line 196 of file private_server.cpp.

196 {__TBB_ASSERT(false,NULL);}
#define __TBB_ASSERT(predicate, comment)
No-op version of __TBB_ASSERT.
Definition: tbb_stddef.h:169

References __TBB_ASSERT.

◆ propagate_chain_reaction()

void tbb::internal::rml::private_server::propagate_chain_reaction ( )
inlineprivate

Wake up to two sleeping workers, if there are any sleeping.

The call is used to propagate a chain reaction where each thread wakes up two threads, which in turn each wake up two threads, etc.

Definition at line 158 of file private_server.cpp.

158  {
159  // First test of a double-check idiom. Second test is inside wake_some(0).
160  if( my_asleep_list_root )
161  wake_some(0);
162  }
void wake_some(int additional_slack)
Equivalent of adding additional_slack to my_slack and waking up to 2 threads if my_slack permits.
tbb::atomic< private_worker * > my_asleep_list_root
List of workers that are asleep or committed to sleeping until notified by another thread.

References my_asleep_list_root, and wake_some().

Referenced by tbb::internal::rml::private_worker::run().

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

◆ remove_server_ref()

void tbb::internal::rml::private_server::remove_server_ref ( )
inlineprivate

Definition at line 172 of file private_server.cpp.

172  {
173  if( --my_ref_count==0 ) {
174  my_client.acknowledge_close_connection();
175  this->~private_server();
177  }
178  }
Meets "allocator" requirements of ISO C++ Standard, Section 20.1.5.
atomic< int > my_ref_count
Counter used to determine when to delete this.
void deallocate(pointer p, size_type)
Free block of memory that starts on a cache line.

References tbb::cache_aligned_allocator< T >::deallocate(), my_client, my_ref_count, and ~private_server().

Referenced by request_close_connection(), tbb::internal::rml::private_worker::run(), and tbb::internal::rml::private_worker::start_shutdown().

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

◆ request_close_connection()

void tbb::internal::rml::private_server::request_close_connection ( bool  )
inline

Definition at line 188 of file private_server.cpp.

188  {
189  for( size_t i=0; i<my_n_thread; ++i )
190  my_thread_array[i].start_shutdown();
192  }
const tbb_client::size_type my_n_thread
Maximum number of threads to be created.
padded_private_worker * my_thread_array

References my_n_thread, my_thread_array, and remove_server_ref().

Here is the call graph for this function:

◆ try_insert_in_asleep_list()

bool tbb::internal::rml::private_server::try_insert_in_asleep_list ( private_worker t)
inlineprivate

Try to add t to list of sleeping workers.

Definition at line 351 of file private_server.cpp.

351  {
352  asleep_list_mutex_type::scoped_lock lock;
353  if( !lock.try_acquire(my_asleep_list_mutex) )
354  return false;
355  // Contribute to slack under lock so that if another takes that unit of slack,
356  // it sees us sleeping on the list and wakes us up.
357  int k = ++my_slack;
358  if( k<=0 ) {
359  t.my_next = my_asleep_list_root;
360  my_asleep_list_root = &t;
361  return true;
362  } else {
363  --my_slack;
364  return false;
365  }
366 }
atomic< int > my_slack
Number of jobs that could use their associated thread minus number of active threads.
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 * lock
tbb::atomic< private_worker * > my_asleep_list_root
List of workers that are asleep or committed to sleeping until notified by another thread.
asleep_list_mutex_type my_asleep_list_mutex

References lock, my_asleep_list_mutex, my_asleep_list_root, tbb::internal::rml::private_worker::my_next, and my_slack.

Referenced by tbb::internal::rml::private_worker::run().

Here is the caller graph for this function:

◆ version()

version_type tbb::internal::rml::private_server::version ( ) const
inline

Definition at line 184 of file private_server.cpp.

184  {
185  return 0;
186  }

◆ wake_some()

void tbb::internal::rml::private_server::wake_some ( int  additional_slack)
private

Equivalent of adding additional_slack to my_slack and waking up to 2 threads if my_slack permits.

Definition at line 368 of file private_server.cpp.

368  {
369  __TBB_ASSERT( additional_slack>=0, NULL );
370  private_worker* wakee[2];
371  private_worker**w = wakee;
372  {
373  asleep_list_mutex_type::scoped_lock lock(my_asleep_list_mutex);
374  while( my_asleep_list_root && w<wakee+2 ) {
375  if( additional_slack>0 ) {
376  if (additional_slack+my_slack<=0) // additional demand does not exceed surplus supply
377  break;
378  --additional_slack;
379  } else {
380  // Chain reaction; Try to claim unit of slack
381  int old;
382  do {
383  old = my_slack;
384  if( old<=0 ) goto done;
385  } while( my_slack.compare_and_swap(old-1,old)!=old );
386  }
387  // Pop sleeping worker to combine with claimed unit of slack
388  my_asleep_list_root = (*w++ = my_asleep_list_root)->my_next;
389  }
390  if( additional_slack ) {
391  // Contribute our unused slack to my_slack.
392  my_slack += additional_slack;
393  }
394  }
395 done:
396  while( w>wakee ) {
397  private_worker* ww = *--w;
398  ww->my_next = NULL;
399  ww->wake_or_launch();
400  }
401 }
#define __TBB_ASSERT(predicate, comment)
No-op version of __TBB_ASSERT.
Definition: tbb_stddef.h:169
atomic< int > my_slack
Number of jobs that could use their associated thread minus number of active threads.
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 * lock
tbb::atomic< private_worker * > my_asleep_list_root
List of workers that are asleep or committed to sleeping until notified by another thread.
value_type compare_and_swap(value_type value, value_type comparand)
Definition: atomic.h:289
asleep_list_mutex_type my_asleep_list_mutex

References __TBB_ASSERT, tbb::internal::atomic_impl< T >::compare_and_swap(), lock, my_asleep_list_mutex, my_asleep_list_root, tbb::internal::rml::private_worker::my_next, my_slack, and tbb::internal::rml::private_worker::wake_or_launch().

Referenced by adjust_job_count_estimate(), and propagate_chain_reaction().

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

◆ yield()

void tbb::internal::rml::private_server::yield ( )
inline

Definition at line 194 of file private_server.cpp.

194 {__TBB_Yield();}
#define __TBB_Yield()
Definition: ibm_aix51.h:48

References __TBB_Yield.

Friends And Related Function Documentation

◆ private_worker

friend class private_worker
friend

Definition at line 180 of file private_server.cpp.

Member Data Documentation

◆ my_asleep_list_mutex

asleep_list_mutex_type tbb::internal::rml::private_server::my_asleep_list_mutex
private

Definition at line 149 of file private_server.cpp.

Referenced by try_insert_in_asleep_list(), and wake_some().

◆ my_asleep_list_root

tbb::atomic<private_worker*> tbb::internal::rml::private_server::my_asleep_list_root
private

List of workers that are asleep or committed to sleeping until notified by another thread.

Definition at line 145 of file private_server.cpp.

Referenced by private_server(), propagate_chain_reaction(), try_insert_in_asleep_list(), and wake_some().

◆ my_client

tbb_client& tbb::internal::rml::private_server::my_client
private

Definition at line 124 of file private_server.cpp.

Referenced by remove_server_ref().

◆ my_n_thread

const tbb_client::size_type tbb::internal::rml::private_server::my_n_thread
private

Maximum number of threads to be created.

Threads are created lazily, so maximum might not actually be reached.

Definition at line 127 of file private_server.cpp.

Referenced by private_server(), request_close_connection(), and ~private_server().

◆ my_ref_count

atomic<int> tbb::internal::rml::private_server::my_ref_count
private

Counter used to determine when to delete this.

Definition at line 140 of file private_server.cpp.

Referenced by private_server(), and remove_server_ref().

◆ my_slack

atomic<int> tbb::internal::rml::private_server::my_slack
private

Number of jobs that could use their associated thread minus number of active threads.

If negative, indicates oversubscription. If positive, indicates that more threads should run. Can be lowered asynchronously, but must be raised only while holding my_asleep_list_mutex, because raising it impacts the invariant for sleeping threads.

Definition at line 137 of file private_server.cpp.

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

◆ my_stack_size

const size_t tbb::internal::rml::private_server::my_stack_size
private

Stack size for each thread. */.

Definition at line 130 of file private_server.cpp.

Referenced by tbb::internal::rml::private_worker::wake_or_launch().

◆ my_thread_array

padded_private_worker* tbb::internal::rml::private_server::my_thread_array
private

Definition at line 142 of file private_server.cpp.

Referenced by private_server(), request_close_connection(), and ~private_server().


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.