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 #ifndef __TBB_task_scheduler_init_H
18 #define __TBB_task_scheduler_init_H
19 
20 #include "tbb_stddef.h"
21 #include "limits.h"
22 #if __TBB_SUPPORTS_WORKERS_WAITING_IN_TERMINATE
23 #include <new> // nothrow_t
24 #endif
25 
26 namespace tbb {
27 
28 typedef std::size_t stack_size_type;
29 
31 namespace internal {
33 
34  class scheduler;
35 } // namespace internal
37 
39 
52 class task_scheduler_init: internal::no_copy {
57  };
58 
60  internal::scheduler* my_scheduler;
61 
62  bool internal_terminate( bool blocking );
63 #if __TBB_SUPPORTS_WORKERS_WAITING_IN_TERMINATE
64  bool __TBB_EXPORTED_METHOD internal_blocking_terminate( bool throwing );
65 #endif
66 public:
67 
69  static const int automatic = -1;
70 
72  static const int deferred = -2;
73 
75 
86  void __TBB_EXPORTED_METHOD initialize( int number_of_threads=automatic );
87 
89 
90  void __TBB_EXPORTED_METHOD initialize( int number_of_threads, stack_size_type thread_stack_size );
91 
94 
95 #if __TBB_SUPPORTS_WORKERS_WAITING_IN_TERMINATE
96 #if TBB_USE_EXCEPTIONS
97  void blocking_terminate() {
99  internal_blocking_terminate( /*throwing=*/true );
100  }
101 #endif
102  bool blocking_terminate(const std::nothrow_t&) __TBB_NOEXCEPT(true) {
104  return internal_blocking_terminate( /*throwing=*/false );
105  }
106 #endif // __TBB_SUPPORTS_WORKERS_WAITING_IN_TERMINATE
107 
109  task_scheduler_init( int number_of_threads=automatic, stack_size_type thread_stack_size=0 ) : my_scheduler(NULL)
110  {
111  // Two lowest order bits of the stack size argument may be taken to communicate
112  // default exception propagation mode of the client to be used when the
113  // client manually creates tasks in the master thread and does not use
114  // explicit task group context object. This is necessary because newer
115  // TBB binaries with exact propagation enabled by default may be used
116  // by older clients that expect tbb::captured_exception wrapper.
117  // All zeros mean old client - no preference.
118  __TBB_ASSERT( !(thread_stack_size & propagation_mode_mask), "Requested stack size is not aligned" );
119 #if TBB_USE_EXCEPTIONS
121 #endif /* TBB_USE_EXCEPTIONS */
122  initialize( number_of_threads, thread_stack_size );
123  }
124 
127  if( my_scheduler )
128  terminate();
130  }
132 
150 
152  bool is_active() const { return my_scheduler != NULL; }
153 };
154 
155 } // namespace tbb
156 
157 #endif /* __TBB_task_scheduler_init_H */
~task_scheduler_init()
Destroy scheduler for this thread if thread has no other live task_scheduler_inits.
static int __TBB_EXPORTED_FUNC default_num_threads()
Returns the number of threads TBB scheduler would create if initialized by default.
Definition: governor.cpp:371
#define __TBB_EXPORTED_FUNC
bool internal_terminate(bool blocking)
Definition: governor.cpp:336
std::size_t stack_size_type
internal::scheduler * my_scheduler
static const int deferred
Argument to initialize() or constructor that causes initialization to be deferred.
void __TBB_EXPORTED_METHOD terminate()
Inverse of method initialize.
Definition: governor.cpp:354
Class delimiting the scope of task scheduler activity.
#define __TBB_EXPORTED_METHOD
Definition: tbb_stddef.h:98
#define __TBB_ASSERT(predicate, comment)
No-op version of __TBB_ASSERT.
Definition: tbb_stddef.h:165
The graph class.
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).
void poison_pointer(T *__TBB_atomic &)
Definition: tbb_stddef.h:305
#define TBB_USE_CAPTURED_EXCEPTION
Definition: tbb_config.h:495
bool is_active() const
Returns true if scheduler is active (initialized); false otherwise.
#define __TBB_NOEXCEPT(expression)
Definition: tbb_stddef.h:110
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:303

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.