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-2011 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 #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 /* TBB_USE_EXCEPTIONS */
    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         // Take two lowest order bits of the stack size argument to communicate
    00097         // default exception propagation mode of the client to be used when the
    00098         // client manually creates tasks in the master thread and does not use
    00099         // explicit task group context object. This is necessary because newer
    00100         // TBB binaries with exact propagation enabled by default may be used
    00101         // by older clients that expect tbb::captured_exception wrapper.
    00102         // All zeros mean old client - no preference.
    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 /* TBB_USE_EXCEPTIONS */
    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 } // namespace tbb
    00140
    00141 #endif /* __TBB_task_scheduler_init_H */

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