BRE12
global_control.h
1 /*
2  Copyright 2005-2016 Intel Corporation. All Rights Reserved.
3 
4  This file is part of Threading Building Blocks. Threading Building Blocks is free software;
5  you can redistribute it and/or modify it under the terms of the GNU General Public License
6  version 2 as published by the Free Software Foundation. Threading Building Blocks is
7  distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the
8  implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
9  See the GNU General Public License for more details. You should have received a copy of
10  the GNU General Public License along with Threading Building Blocks; if not, write to the
11  Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
12 
13  As a special exception, you may use this file as part of a free software library without
14  restriction. Specifically, if other files instantiate templates or use macros or inline
15  functions from this file, or you compile this file and link it with other files to produce
16  an executable, this file does not by itself cause the resulting executable to be covered
17  by the GNU General Public License. This exception does not however invalidate any other
18  reasons why the executable file might be covered by the GNU General Public License.
19 */
20 
21 #ifndef __TBB_global_control_H
22 #define __TBB_global_control_H
23 
24 #if !TBB_PREVIEW_GLOBAL_CONTROL && !__TBB_BUILD
25 #error Set TBB_PREVIEW_GLOBAL_CONTROL before including global_control.h
26 #endif
27 
28 #include "tbb_stddef.h"
29 
30 namespace tbb {
31 namespace interface9 {
32 
34 public:
35  enum parameter {
36  max_allowed_parallelism,
37  thread_stack_size,
38  parameter_max // insert new parameters above this point
39  };
40 
41  global_control(parameter p, size_t value) :
42  my_value(value), my_next(NULL), my_param(p) {
43  __TBB_ASSERT(my_param < parameter_max, "Invalid parameter");
44 #if __TBB_WIN8UI_SUPPORT
45  // For Windows Store* apps it's impossible to set stack size
46  if (p==thread_stack_size)
47  return;
48 #elif __TBB_x86_64 && (_WIN32 || _WIN64)
49  if (p==thread_stack_size)
50  __TBB_ASSERT_RELEASE((unsigned)value == value, "Stack size is limited to unsigned int range");
51 #endif
52  if (my_param==max_allowed_parallelism)
53  __TBB_ASSERT_RELEASE(my_value>0, "max_allowed_parallelism cannot be 0.");
54  internal_create();
55  }
56 
57  ~global_control() {
58  __TBB_ASSERT(my_param < parameter_max, "Invalid parameter. Probably the object was corrupted.");
59 #if __TBB_WIN8UI_SUPPORT
60  // For Windows Store* apps it's impossible to set stack size
61  if (my_param==thread_stack_size)
62  return;
63 #endif
64  internal_destroy();
65  }
66 
67  static size_t active_value(parameter p) {
68  __TBB_ASSERT(p < parameter_max, "Invalid parameter");
69  return active_value((int)p);
70  }
71 private:
72  size_t my_value;
73  global_control *my_next;
74  parameter my_param;
75 
76  void __TBB_EXPORTED_METHOD internal_create();
77  void __TBB_EXPORTED_METHOD internal_destroy();
78  static size_t __TBB_EXPORTED_FUNC active_value(int param);
79 };
80 } // namespace interface9
81 
83 
84 } // tbb
85 
86 #endif // __TBB_global_control_H
Definition: global_control.h:33
The namespace tbb contains all components of the library.
Definition: parallel_for.h:44