00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #ifndef __TBB_task_scheduler_init_H
00030 #define __TBB_task_scheduler_init_H
00031
00032 #include "tbb_stddef.h"
00033 #include "limits.h"
00034
00035 namespace tbb {
00036
00037 typedef std::size_t stack_size_type;
00038
00040 namespace internal {
00042
00043 class scheduler;
00044 }
00046
00048
00061 class task_scheduler_init: internal::no_copy {
00062 enum ExceptionPropagationMode {
00063 propagation_mode_exact = 1u,
00064 propagation_mode_captured = 2u,
00065 propagation_mode_mask = propagation_mode_exact | propagation_mode_captured
00066 };
00067 #if __TBB_SUPPORTS_WORKERS_WAITING_IN_TERMINATE
00068 enum {
00069 wait_workers_in_terminate_flag = 128u
00070 };
00071 #endif
00072
00074 internal::scheduler* my_scheduler;
00075 public:
00076
00078 static const int automatic = -1;
00079
00081 static const int deferred = -2;
00082
00084
00095 void __TBB_EXPORTED_METHOD initialize( int number_of_threads=automatic );
00096
00098
00099 void __TBB_EXPORTED_METHOD initialize( int number_of_threads, stack_size_type thread_stack_size );
00100
00102 void __TBB_EXPORTED_METHOD terminate();
00103
00105 #if __TBB_SUPPORTS_WORKERS_WAITING_IN_TERMINATE
00106 task_scheduler_init( int number_of_threads=automatic, stack_size_type thread_stack_size=0, bool wait_workers_in_terminate = false )
00107 #else
00108 task_scheduler_init( int number_of_threads=automatic, stack_size_type thread_stack_size=0 )
00109 #endif
00110 : my_scheduler(NULL) {
00111
00112
00113
00114
00115
00116
00117
00118 __TBB_ASSERT( !(thread_stack_size & propagation_mode_mask), "Requested stack size is not aligned" );
00119 #if TBB_USE_EXCEPTIONS
00120 thread_stack_size |= TBB_USE_CAPTURED_EXCEPTION ? propagation_mode_captured : propagation_mode_exact;
00121 #endif
00122 #if __TBB_SUPPORTS_WORKERS_WAITING_IN_TERMINATE
00123 if (wait_workers_in_terminate)
00124 my_scheduler = (internal::scheduler*)wait_workers_in_terminate_flag;
00125 #endif
00126 initialize( number_of_threads, thread_stack_size );
00127 }
00128
00130 ~task_scheduler_init() {
00131 if( my_scheduler )
00132 terminate();
00133 internal::poison_pointer( my_scheduler );
00134 }
00136
00153 static int __TBB_EXPORTED_FUNC default_num_threads ();
00154
00156 bool is_active() const { return my_scheduler != NULL; }
00157 };
00158
00159 }
00160
00161 #endif