Intel(R) Threading Building Blocks Doxygen Documentation  version 4.2.3
task_scheduler_init.h
Go to the documentation of this file.
1 /*
2  Copyright (c) 2005-2019 Intel Corporation
3 
4  Licensed under the Apache License, Version 2.0 (the "License");
5  you may not use this file except in compliance with the License.
6  You may obtain a copy of the License at
7 
8  http://www.apache.org/licenses/LICENSE-2.0
9 
10  Unless required by applicable law or agreed to in writing, software
11  distributed under the License is distributed on an "AS IS" BASIS,
12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  See the License for the specific language governing permissions and
14  limitations under the License.
15 
16 
17 
18 
19 */
20 
21 #ifndef __TBB_task_scheduler_init_H
22 #define __TBB_task_scheduler_init_H
23 
24 #include "tbb_stddef.h"
25 #include "limits.h"
26 #if __TBB_SUPPORTS_WORKERS_WAITING_IN_TERMINATE
27 #include <new> // nothrow_t
28 #endif
29 
30 namespace tbb {
31 
32 typedef std::size_t stack_size_type;
33 
35 namespace internal {
37 
38  class scheduler;
39 } // namespace internal
41 
43 
56 class task_scheduler_init: internal::no_copy {
61  };
62 
64  internal::scheduler* my_scheduler;
65 
66  bool internal_terminate( bool blocking );
67 #if __TBB_SUPPORTS_WORKERS_WAITING_IN_TERMINATE
68  bool __TBB_EXPORTED_METHOD internal_blocking_terminate( bool throwing );
69 #endif
70 public:
71 
73  static const int automatic = -1;
74 
76  static const int deferred = -2;
77 
79 
90  void __TBB_EXPORTED_METHOD initialize( int number_of_threads=automatic );
91 
93 
94  void __TBB_EXPORTED_METHOD initialize( int number_of_threads, stack_size_type thread_stack_size );
95 
98 
99 #if __TBB_SUPPORTS_WORKERS_WAITING_IN_TERMINATE
100 #if TBB_USE_EXCEPTIONS
101  void blocking_terminate() {
103  internal_blocking_terminate( /*throwing=*/true );
104  }
105 #endif
106  bool blocking_terminate(const std::nothrow_t&) __TBB_NOEXCEPT(true) {
108  return internal_blocking_terminate( /*throwing=*/false );
109  }
110 #endif // __TBB_SUPPORTS_WORKERS_WAITING_IN_TERMINATE
111 
113  task_scheduler_init( int number_of_threads=automatic, stack_size_type thread_stack_size=0 ) : my_scheduler(NULL)
114  {
115  // Two lowest order bits of the stack size argument may be taken to communicate
116  // default exception propagation mode of the client to be used when the
117  // client manually creates tasks in the master thread and does not use
118  // explicit task group context object. This is necessary because newer
119  // TBB binaries with exact propagation enabled by default may be used
120  // by older clients that expect tbb::captured_exception wrapper.
121  // All zeros mean old client - no preference.
122  __TBB_ASSERT( !(thread_stack_size & propagation_mode_mask), "Requested stack size is not aligned" );
123 #if TBB_USE_EXCEPTIONS
125 #endif /* TBB_USE_EXCEPTIONS */
126  initialize( number_of_threads, thread_stack_size );
127  }
128 
131  if( my_scheduler )
132  terminate();
134  }
136 
154 
156  bool is_active() const { return my_scheduler != NULL; }
157 };
158 
159 } // namespace tbb
160 
161 #endif /* __TBB_task_scheduler_init_H */
#define __TBB_ASSERT(predicate, comment)
No-op version of __TBB_ASSERT.
Definition: tbb_stddef.h:169
#define __TBB_NOEXCEPT(expression)
Definition: tbb_stddef.h:114
static const int automatic
Typedef for number of threads that is automatic.
void __TBB_EXPORTED_METHOD initialize(int number_of_threads=automatic)
Ensure that scheduler exists for this thread.
Definition: governor.cpp:307
bool is_active() const
Returns true if scheduler is active (initialized); false otherwise.
internal::scheduler * my_scheduler
static const int deferred
Argument to initialize() or constructor that causes initialization to be deferred.
#define __TBB_EXPORTED_METHOD
Definition: tbb_stddef.h:102
The graph class.
static int __TBB_EXPORTED_FUNC default_num_threads()
Returns the number of threads TBB scheduler would create if initialized by default.
Definition: governor.cpp:375
void poison_pointer(T *__TBB_atomic &)
Definition: tbb_stddef.h:309
Class delimiting the scope of task scheduler activity.
#define __TBB_EXPORTED_FUNC
std::size_t stack_size_type
task_scheduler_init(int number_of_threads=automatic, stack_size_type thread_stack_size=0)
Shorthand for default constructor followed by call to initialize(number_of_threads).
#define TBB_USE_CAPTURED_EXCEPTION
Definition: tbb_config.h:506
~task_scheduler_init()
Destroy scheduler for this thread if thread has no other live task_scheduler_inits.
void __TBB_EXPORTED_METHOD terminate()
Inverse of method initialize.
Definition: governor.cpp:358
bool internal_terminate(bool blocking)
Definition: governor.cpp:340

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.