1 /*
2     Copyright (c) 2005-2020 Intel Corporation
3 
4     Licensed under the Apache License, Version 2.0 (the "License");
5     you may not use this file except in compliance with the License.
6     You may obtain a copy of the License at
7 
8         http://www.apache.org/licenses/LICENSE-2.0
9 
10     Unless required by applicable law or agreed to in writing, software
11     distributed under the License is distributed on an "AS IS" BASIS,
12     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13     See the License for the specific language governing permissions and
14     limitations under the License.
15 */
16 
17 #ifndef __TBB_global_control_H
18 #define __TBB_global_control_H
19 
20 #include "tbb_stddef.h"
21 
22 namespace tbb {
23 namespace interface9 {
24 
25 class global_control {
26 public:
27     enum parameter {
28         max_allowed_parallelism,
29         thread_stack_size,
30         parameter_max // insert new parameters above this point
31     };
32 
global_control(parameter p,size_t value)33     global_control(parameter p, size_t value) :
34         my_value(value), my_next(NULL), my_param(p) {
35         __TBB_ASSERT(my_param < parameter_max, "Invalid parameter");
36 #if __TBB_WIN8UI_SUPPORT && (_WIN32_WINNT < 0x0A00)
37         // For Windows 8 Store* apps it's impossible to set stack size
38         if (p==thread_stack_size)
39             return;
40 #elif __TBB_x86_64 && (_WIN32 || _WIN64)
41         if (p==thread_stack_size)
42             __TBB_ASSERT_RELEASE((unsigned)value == value, "Stack size is limited to unsigned int range");
43 #endif
44         if (my_param==max_allowed_parallelism)
45             __TBB_ASSERT_RELEASE(my_value>0, "max_allowed_parallelism cannot be 0.");
46         internal_create();
47     }
48 
~global_control()49     ~global_control() {
50         __TBB_ASSERT(my_param < parameter_max, "Invalid parameter. Probably the object was corrupted.");
51 #if __TBB_WIN8UI_SUPPORT && (_WIN32_WINNT < 0x0A00)
52         // For Windows 8 Store* apps it's impossible to set stack size
53         if (my_param==thread_stack_size)
54             return;
55 #endif
56         internal_destroy();
57     }
58 
active_value(parameter p)59     static size_t active_value(parameter p) {
60         __TBB_ASSERT(p < parameter_max, "Invalid parameter");
61         return active_value((int)p);
62     }
63 private:
64     size_t    my_value;
65     global_control *my_next;
66     parameter my_param;
67 
68     void __TBB_EXPORTED_METHOD internal_create();
69     void __TBB_EXPORTED_METHOD internal_destroy();
70     static size_t __TBB_EXPORTED_FUNC active_value(int param);
71 };
72 } // namespace interface9
73 
74 using interface9::global_control;
75 
76 } // tbb
77 
78 #endif // __TBB_global_control_H
79