- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

# task_scheduler_init.h

    00001 /*
    00002     Copyright 2005-2012 Intel Corporation.  All Rights Reserved.
    00003
    00004     This file is part of Threading Building Blocks.
    00005
    00006     Threading Building Blocks is free software; you can redistribute it
    00007     and/or modify it under the terms of the GNU General Public License
    00008     version 2 as published by the Free Software Foundation.
    00009
    00010     Threading Building Blocks is distributed in the hope that it will be
    00011     useful, but WITHOUT ANY WARRANTY; without even the implied warranty
    00012     of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    00013     GNU General Public License for more details.
    00014
    00015     You should have received a copy of the GNU General Public License
    00016     along with Threading Building Blocks; if not, write to the Free Software
    00017     Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    00018
    00019     As a special exception, you may use this file as part of a free software
    00020     library without restriction.  Specifically, if other files instantiate
    00021     templates or use macros or inline functions from this file, or you compile
    00022     this file and link it with other files to produce an executable, this
    00023     file does not by itself cause the resulting executable to be covered by
    00024     the GNU General Public License.  This exception does not however
    00025     invalidate any other reasons why the executable file might be covered by
    00026     the GNU General Public License.
    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 } // namespace internal
    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
    00069     internal::scheduler* my_scheduler;
    00070 public:
    00071
    00073     static const int automatic = -1;
    00074
    00076     static const int deferred = -2;
    00077
    00079
    00090     void __TBB_EXPORTED_METHOD initialize( int number_of_threads=automatic );
    00091
    00093
    00094     void __TBB_EXPORTED_METHOD initialize( int number_of_threads, stack_size_type thread_stack_size );
    00095
    00097     void __TBB_EXPORTED_METHOD terminate();
    00098
    00100     task_scheduler_init( int number_of_threads=automatic, stack_size_type thread_stack_size=0 ) : my_scheduler(NULL)  {
    00101         // Two lowest order bits of the stack size argument may be taken to communicate
    00102         // default exception propagation mode of the client to be used when the
    00103         // client manually creates tasks in the master thread and does not use
    00104         // explicit task group context object. This is necessary because newer
    00105         // TBB binaries with exact propagation enabled by default may be used
    00106         // by older clients that expect tbb::captured_exception wrapper.
    00107         // All zeros mean old client - no preference.
    00108         __TBB_ASSERT( !(thread_stack_size & propagation_mode_mask), "Requested stack size is not aligned" );
    00109 #if TBB_USE_EXCEPTIONS
    00110         thread_stack_size |= TBB_USE_CAPTURED_EXCEPTION ? propagation_mode_captured : propagation_mode_exact;
    00111 #endif /* TBB_USE_EXCEPTIONS */
    00112         initialize( number_of_threads, thread_stack_size );
    00113     }
    00114
    00116     ~task_scheduler_init() {
    00117         if( my_scheduler )
    00118             terminate();
    00119         internal::poison_pointer( my_scheduler );
    00120     }
    00122
    00139     static int __TBB_EXPORTED_FUNC default_num_threads ();
    00140
    00142     bool is_active() const { return my_scheduler != NULL; }
    00143 };
    00144
    00145 } // namespace tbb
    00146
    00147 #endif /* __TBB_task_scheduler_init_H */

Copyright © 2005-2012 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.