task_scheduler_init.h Source File

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

- File List
- File Members

# task_scheduler_init.h

    00001 /*
    00002     Copyright 2005-2012 Intel Corporation.  All Rights Reserved.
    00003
    00004     The source code contained or described herein and all documents related
    00005     to the source code ("Material") are owned by Intel Corporation or its
    00006     suppliers or licensors.  Title to the Material remains with Intel
    00007     Corporation or its suppliers and licensors.  The Material is protected
    00008     by worldwide copyright laws and treaty provisions.  No part of the
    00009     Material may be used, copied, reproduced, modified, published, uploaded,
    00010     posted, transmitted, distributed, or disclosed in any way without
    00011     Intel's prior express written permission.
    00012
    00013     No license under any patent, copyright, trade secret or other
    00014     intellectual property right is granted to or conferred upon you by
    00015     disclosure or delivery of the Materials, either expressly, by
    00016     implication, inducement, estoppel or otherwise.  Any license under such
    00017     intellectual property rights must be express and approved by Intel in
    00018     writing.
    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 } // namespace internal
    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
    00061     internal::scheduler* my_scheduler;
    00062 public:
    00063
    00065     static const int automatic = -1;
    00066
    00068     static const int deferred = -2;
    00069
    00071
    00082     void __TBB_EXPORTED_METHOD initialize( int number_of_threads=automatic );
    00083
    00085
    00086     void __TBB_EXPORTED_METHOD initialize( int number_of_threads, stack_size_type thread_stack_size );
    00087
    00089     void __TBB_EXPORTED_METHOD terminate();
    00090
    00092     task_scheduler_init( int number_of_threads=automatic, stack_size_type thread_stack_size=0 ) : my_scheduler(NULL)  {
    00093         // Two lowest order bits of the stack size argument may be taken to communicate
    00094         // default exception propagation mode of the client to be used when the
    00095         // client manually creates tasks in the master thread and does not use
    00096         // explicit task group context object. This is necessary because newer
    00097         // TBB binaries with exact propagation enabled by default may be used
    00098         // by older clients that expect tbb::captured_exception wrapper.
    00099         // All zeros mean old client - no preference.
    00100         __TBB_ASSERT( !(thread_stack_size & propagation_mode_mask), "Requested stack size is not aligned" );
    00101 #if TBB_USE_EXCEPTIONS
    00102         thread_stack_size |= TBB_USE_CAPTURED_EXCEPTION ? propagation_mode_captured : propagation_mode_exact;
    00103 #endif /* TBB_USE_EXCEPTIONS */
    00104         initialize( number_of_threads, thread_stack_size );
    00105     }
    00106
    00108     ~task_scheduler_init() {
    00109         if( my_scheduler )
    00110             terminate();
    00111         internal::poison_pointer( my_scheduler );
    00112     }
    00114
    00131     static int __TBB_EXPORTED_FUNC default_num_threads ();
    00132
    00134     bool is_active() const { return my_scheduler != NULL; }
    00135 };
    00136
    00137 } // namespace tbb
    00138
    00139 #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.