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 #if TBB_USE_EXCEPTIONS
00055 enum ExceptionPropagationMode {
00056 propagation_mode_exact = 1u,
00057 propagation_mode_captured = 2u,
00058 propagation_mode_mask = propagation_mode_exact | propagation_mode_captured
00059 };
00060 #endif
00061
00063 internal::scheduler* my_scheduler;
00064 public:
00065
00067 static const int automatic = -1;
00068
00070 static const int deferred = -2;
00071
00073
00084 void __TBB_EXPORTED_METHOD initialize( int number_of_threads=automatic );
00085
00087
00088 void __TBB_EXPORTED_METHOD initialize( int number_of_threads, stack_size_type thread_stack_size );
00089
00091 void __TBB_EXPORTED_METHOD terminate();
00092
00094 task_scheduler_init( int number_of_threads=automatic, stack_size_type thread_stack_size=0 ) : my_scheduler(NULL) {
00095 #if TBB_USE_EXCEPTIONS
00096
00097
00098
00099
00100
00101
00102
00103 __TBB_ASSERT( !(thread_stack_size & propagation_mode_mask), "Requested stack size is not aligned" );
00104 thread_stack_size |= TBB_USE_CAPTURED_EXCEPTION ? propagation_mode_captured : propagation_mode_exact;
00105 #endif
00106 initialize( number_of_threads, thread_stack_size );
00107 }
00108
00110 ~task_scheduler_init() {
00111 if( my_scheduler )
00112 terminate();
00113 internal::poison_pointer( my_scheduler );
00114 }
00116
00133 static int __TBB_EXPORTED_FUNC default_num_threads ();
00134
00136 bool is_active() const { return my_scheduler != NULL; }
00137 };
00138
00139 }
00140
00141 #endif