2
Copyright 2005-2009 Intel Corporation. All Rights Reserved.
4
This file is part of Threading Building Blocks.
6
Threading Building Blocks is free software; you can redistribute it
7
and/or modify it under the terms of the GNU General Public License
8
version 2 as published by the Free Software Foundation.
10
Threading Building Blocks is distributed in the hope that it will be
11
useful, but WITHOUT ANY WARRANTY; without even the implied warranty
12
of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
GNU General Public License for more details.
15
You should have received a copy of the GNU General Public License
16
along with Threading Building Blocks; if not, write to the Free Software
17
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19
As a special exception, you may use this file as part of a free software
20
library without restriction. Specifically, if other files instantiate
21
templates or use macros or inline functions from this file, or you compile
22
this file and link it with other files to produce an executable, this
23
file does not by itself cause the resulting executable to be covered by
24
the GNU General Public License. This exception does not however
25
invalidate any other reasons why the executable file might be covered by
26
the GNU General Public License.
29
#ifndef __TBB_task_scheduler_init_H
30
#define __TBB_task_scheduler_init_H
32
#include "tbb_stddef.h"
36
typedef std::size_t stack_size_type;
40
//! Internal to library. Should not be used by clients.
41
/** @ingroup task_scheduling */
43
} // namespace internal
46
//! Class representing reference to tbb scheduler.
47
/** A thread must construct a task_scheduler_init, and keep it alive,
48
during the time that it uses the services of class task.
49
@ingroup task_scheduling */
50
class task_scheduler_init: internal::no_copy {
51
/** NULL if not currently initialized. */
52
internal::scheduler* my_scheduler;
55
//! Typedef for number of threads that is automatic.
56
static const int automatic = -1;
58
//! Argument to initialize() or constructor that causes initialization to be deferred.
59
static const int deferred = -2;
61
//! Ensure that scheduler exists for this thread
62
/** A value of -1 lets tbb decide on the number of threads, which is typically
63
the number of hardware threads. For production code, the default value of -1
64
should be used, particularly if the client code is mixed with third party clients
65
that might also use tbb.
67
The number_of_threads is ignored if any other task_scheduler_inits
68
currently exist. A thread may construct multiple task_scheduler_inits.
69
Doing so does no harm because the underlying scheduler is reference counted. */
70
void __TBB_EXPORTED_METHOD initialize( int number_of_threads=automatic );
72
//! The overloaded method with stack size parameter
73
/** Overloading is necessary to preserve ABI compatibility */
74
void __TBB_EXPORTED_METHOD initialize( int number_of_threads, stack_size_type thread_stack_size );
76
//! Inverse of method initialize.
77
void __TBB_EXPORTED_METHOD terminate();
79
//! Shorthand for default constructor followed by call to intialize(number_of_threads).
80
task_scheduler_init( int number_of_threads=automatic, stack_size_type thread_stack_size=0 ) : my_scheduler(NULL) {
81
initialize( number_of_threads, thread_stack_size );
84
//! Destroy scheduler for this thread if thread has no other live task_scheduler_inits.
85
~task_scheduler_init() {
88
internal::poison_pointer( my_scheduler );
90
//! Returns the number of threads tbb scheduler would create if initialized by default.
91
/** Result returned by this method does not depend on whether the scheduler
92
has already been initialized.
94
Because tbb 2.0 does not support blocking tasks yet, you may use this method
95
to boost the number of threads in the tbb's internal pool, if your tasks are
96
doing I/O operations. The optimal number of additional threads depends on how
97
much time your tasks spend in the blocked state. */
98
static int __TBB_EXPORTED_FUNC default_num_threads ();
100
//! Returns true if scheduler is active (initialized); false otherwise
101
bool is_active() const { return my_scheduler != NULL; }
106
#endif /* __TBB_task_scheduler_init_H */