Home ⌂Doc Index ◂Up ▴
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 (const no_copy &)=delete
 
 no_copy ()=default
 

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 118 of file private_server.cpp.

Member Typedef Documentation

◆ asleep_list_mutex_type

Protects my_asleep_list_root.

Definition at line 144 of file private_server.cpp.

Constructor & Destructor Documentation

◆ ~private_server()

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

Definition at line 339 of file private_server.cpp.

339  {
340  __TBB_ASSERT( my_net_slack_requests==0, NULL );
341  for( size_t i=my_n_thread; i--; )
342  my_thread_array[i].~padded_private_worker();
345 }
padded_private_worker * my_thread_array
const tbb_client::size_type my_n_thread
Maximum number of threads to be created.
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:165
void deallocate(pointer p, size_type)
Free block of memory that starts on a cache line.
void poison_pointer(T *__TBB_atomic &)
Definition: tbb_stddef.h:305

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 319 of file private_server.cpp.

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

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 399 of file private_server.cpp.

399  {
400 #if TBB_USE_ASSERT
401  my_net_slack_requests+=delta;
402 #endif /* TBB_USE_ASSERT */
403  if( delta<0 ) {
404  my_slack+=delta;
405  } else if( delta>0 ) {
406  wake_some( delta );
407  }
408 }
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 194 of file private_server.cpp.

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

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 192 of file private_server.cpp.

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

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 154 of file private_server.cpp.

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

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 168 of file private_server.cpp.

168  {
169  if( --my_ref_count==0 ) {
170  my_client.acknowledge_close_connection();
171  this->~private_server();
173  }
174  }
atomic< int > my_ref_count
Counter used to determine when to delete this.
Meets "allocator" requirements of ISO C++ Standard, Section 20.1.5.
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 184 of file private_server.cpp.

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

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 347 of file private_server.cpp.

347  {
348  asleep_list_mutex_type::scoped_lock lock;
349  if( !lock.try_acquire(my_asleep_list_mutex) )
350  return false;
351  // Contribute to slack under lock so that if another takes that unit of slack,
352  // it sees us sleeping on the list and wakes us up.
353  int k = ++my_slack;
354  if( k<=0 ) {
355  t.my_next = my_asleep_list_root;
356  my_asleep_list_root = &t;
357  return true;
358  } else {
359  --my_slack;
360  return false;
361  }
362 }
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
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

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 180 of file private_server.cpp.

180  {
181  return 0;
182  }

◆ 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 364 of file private_server.cpp.

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

References __TBB_ASSERT, 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 190 of file private_server.cpp.

190 {__TBB_Yield();}
#define __TBB_Yield()
Definition: ibm_aix51.h:44

References __TBB_Yield.

Friends And Related Function Documentation

◆ private_worker

friend class private_worker
friend

Definition at line 176 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 145 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 141 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 120 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 123 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 136 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 133 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 126 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 138 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-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.