1 // Copyright Maciej Sobczak 2008-2019. 2 // This file is part of YAMI4. 3 // 4 // YAMI4 is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // YAMI4 is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU General Public License for more details. 13 // 14 // You should have received a copy of the GNU General Public License 15 // along with YAMI4. If not, see <http://www.gnu.org/licenses/>. 16 17 #ifndef YAMICPP_WATER_FLOW_MANAGER_H_INCLUDED 18 #define YAMICPP_WATER_FLOW_MANAGER_H_INCLUDED 19 20 #include <mutex.h> 21 #include <cstddef> 22 23 namespace yami 24 { 25 26 namespace details 27 { 28 29 enum water_flow_control { suppress, allow, no_change }; 30 31 class water_flow_manager 32 { 33 public: 34 water_flow_manager(); 35 ~water_flow_manager(); 36 37 void set_limits(std::size_t high_mark, std::size_t low_mark); 38 39 water_flow_control increase(); 40 water_flow_control decrease(); 41 42 void get_state(std::size_t & current_level, 43 std::size_t & high_water_mark, 44 std::size_t & low_water_mark) const; 45 46 private: 47 std::size_t current_level_; 48 std::size_t high_water_mark_; 49 std::size_t low_water_mark_; 50 mutable mutex mtx_; 51 }; 52 53 } // namespace details 54 55 } // namespace yami 56 57 #endif // YAMICPP_WATER_FLOW_MANAGER_H_INCLUDED 58