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_pm_client_H 18 #define _TBB_pm_client_H 19 20 #include "arena.h" 21 22 namespace tbb { 23 namespace detail { 24 namespace r1 { 25 26 class pm_client { 27 public: pm_client(arena & a)28 pm_client(arena& a) : my_arena(a) {} ~pm_client()29 virtual ~pm_client() {} 30 priority_level()31 unsigned priority_level() { 32 return my_arena.priority_level(); 33 } 34 set_top_priority(bool b)35 void set_top_priority(bool b) { 36 my_arena.set_top_priority(b); 37 } 38 min_workers()39 int min_workers() const { 40 return my_min_workers; 41 } 42 max_workers()43 int max_workers() const { 44 return my_max_workers; 45 } 46 update_request(int mandatory_delta,int workers_delta)47 int update_request(int mandatory_delta, int workers_delta) { 48 auto min_max_workers = my_arena.update_request(mandatory_delta, workers_delta); 49 int delta = min_max_workers.second - my_max_workers; 50 set_workers(min_max_workers.first, min_max_workers.second); 51 return delta; 52 } 53 54 virtual void register_thread() = 0; 55 56 virtual void unregister_thread() = 0; 57 58 59 protected: set_workers(int mn_w,int mx_w)60 void set_workers(int mn_w, int mx_w) { 61 __TBB_ASSERT(mn_w >= 0, nullptr); 62 __TBB_ASSERT(mx_w >= 0, nullptr); 63 my_min_workers = mn_w; 64 my_max_workers = mx_w; 65 } 66 67 arena& my_arena; 68 int my_min_workers{0}; 69 int my_max_workers{0}; 70 }; 71 72 } // namespace r1 73 } // namespace detail 74 } // namespace tbb 75 76 #endif // _TBB_pm_client_H 77