00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef __TBB_task_scheduler_init_H
00022 #define __TBB_task_scheduler_init_H
00023
00024 #include "tbb_stddef.h"
00025 #include "limits.h"
00026
00027 namespace tbb {
00028
00029 typedef std::size_t stack_size_type;
00030
00032 namespace internal {
00034
00035 class scheduler;
00036 }
00038
00040
00053 class task_scheduler_init: internal::no_copy {
00054 enum ExceptionPropagationMode {
00055 propagation_mode_exact = 1u,
00056 propagation_mode_captured = 2u,
00057 propagation_mode_mask = propagation_mode_exact | propagation_mode_captured
00058 };
00059 #if __TBB_SUPPORTS_WORKERS_WAITING_IN_TERMINATE
00060 enum {
00061 wait_workers_in_terminate_flag = 128u
00062 };
00063 #endif
00064
00066 internal::scheduler* my_scheduler;
00067 public:
00068
00070 static const int automatic = -1;
00071
00073 static const int deferred = -2;
00074
00076
00087 void __TBB_EXPORTED_METHOD initialize( int number_of_threads=automatic );
00088
00090
00091 void __TBB_EXPORTED_METHOD initialize( int number_of_threads, stack_size_type thread_stack_size );
00092
00094 void __TBB_EXPORTED_METHOD terminate();
00095
00097 #if __TBB_SUPPORTS_WORKERS_WAITING_IN_TERMINATE
00098 task_scheduler_init( int number_of_threads=automatic, stack_size_type thread_stack_size=0, bool wait_workers_in_terminate = false )
00099 #else
00100 task_scheduler_init( int number_of_threads=automatic, stack_size_type thread_stack_size=0 )
00101 #endif
00102 : my_scheduler(NULL) {
00103
00104
00105
00106
00107
00108
00109
00110 __TBB_ASSERT( !(thread_stack_size & propagation_mode_mask), "Requested stack size is not aligned" );
00111 #if TBB_USE_EXCEPTIONS
00112 thread_stack_size |= TBB_USE_CAPTURED_EXCEPTION ? propagation_mode_captured : propagation_mode_exact;
00113 #endif
00114 #if __TBB_SUPPORTS_WORKERS_WAITING_IN_TERMINATE
00115 if (wait_workers_in_terminate)
00116 my_scheduler = (internal::scheduler*)wait_workers_in_terminate_flag;
00117 #endif
00118 initialize( number_of_threads, thread_stack_size );
00119 }
00120
00122 ~task_scheduler_init() {
00123 if( my_scheduler )
00124 terminate();
00125 internal::poison_pointer( my_scheduler );
00126 }
00128
00145 static int __TBB_EXPORTED_FUNC default_num_threads ();
00146
00148 bool is_active() const { return my_scheduler != NULL; }
00149 };
00150
00151 }
00152
00153 #endif