xref: /oneTBB/src/tbb/permit_manager.h (revision 71e1bb8e)
1 /*
2     Copyright (c) 2022-2023 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_permit_manager_H
18 #define _TBB_permit_manager_H
19 
20 #include "oneapi/tbb/info.h"
21 #include "oneapi/tbb/detail/_utils.h"
22 #include "thread_request_serializer.h"
23 
24 namespace tbb {
25 namespace detail {
26 namespace r1 {
27 
28 class arena;
29 class pm_client;
30 
31 class permit_manager : no_copy {
32 public:
~permit_manager()33     virtual ~permit_manager() {}
34     virtual pm_client* create_client(arena& a) = 0;
35     virtual void register_client(pm_client* client, d1::constraints& constraints) = 0;
36     virtual void unregister_and_destroy_client(pm_client& c) = 0;
37 
38     virtual void set_active_num_workers(int soft_limit) = 0;
39     virtual void adjust_demand(pm_client&, int mandatory_delta, int workers_delta) = 0;
40 
set_thread_request_observer(thread_request_observer & tr_observer)41     void set_thread_request_observer(thread_request_observer& tr_observer) {
42         __TBB_ASSERT(!my_thread_request_observer, "set_thread_request_observer was called already?");
43         my_thread_request_observer = &tr_observer;
44     }
45 protected:
notify_thread_request(int delta)46     void notify_thread_request(int delta) {
47         __TBB_ASSERT(my_thread_request_observer, "set_thread_request_observer was not called?");
48         if (delta) {
49             my_thread_request_observer->update(delta);
50         }
51     }
52 private:
53     thread_request_observer* my_thread_request_observer{nullptr};
54 };
55 
56 
57 } // namespace r1
58 } // namespace detail
59 } // namespace tbb
60 
61 #endif // _TBB_permit_manager_H
62