Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-04-19 08:33:50

0001 //
0002 // Copyright (c) 2019-2024 Ruben Perez Hidalgo (rubenperez038 at gmail dot com)
0003 //
0004 // Distributed under the Boost Software License, Version 1.0. (See accompanying
0005 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0006 //
0007 
0008 #ifndef BOOST_MYSQL_IMPL_INTERNAL_CONNECTION_POOL_TIMER_LIST_HPP
0009 #define BOOST_MYSQL_IMPL_INTERNAL_CONNECTION_POOL_TIMER_LIST_HPP
0010 
0011 #include <boost/asio/any_io_executor.hpp>
0012 #include <boost/intrusive/list.hpp>
0013 #include <boost/intrusive/list_hook.hpp>
0014 
0015 #include <cstddef>
0016 
0017 namespace boost {
0018 namespace mysql {
0019 namespace detail {
0020 
0021 template <class TimerType>
0022 struct timer_block : intrusive::list_base_hook<intrusive::link_mode<intrusive::auto_unlink>>
0023 {
0024     TimerType timer;
0025 
0026     timer_block(asio::any_io_executor ex) : timer(std::move(ex)) {}
0027 };
0028 
0029 template <class TimerType>
0030 class timer_list
0031 {
0032     intrusive::list<timer_block<TimerType>, intrusive::constant_time_size<false>> requests_;
0033 
0034 public:
0035     timer_list() = default;
0036     void push_back(timer_block<TimerType>& req) noexcept { requests_.push_back(req); }
0037     void notify_one()
0038     {
0039         for (auto& req : requests_)
0040         {
0041             if (req.timer.cancel())
0042                 return;
0043         }
0044     }
0045     void notify_all()
0046     {
0047         for (auto& req : requests_)
0048             req.timer.cancel();
0049     }
0050     std::size_t size() const noexcept { return requests_.size(); }
0051 };
0052 
0053 }  // namespace detail
0054 }  // namespace mysql
0055 }  // namespace boost
0056 
0057 #endif