Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-08-17 08:39:20

0001 //
0002 // Copyright (c) 2025 Klemens Morgenstern (klemens.morgenstern@gmx.net)
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_COBALT_IO_SYSTEM_TIMER_HPP
0009 #define BOOST_COBALT_IO_SYSTEM_TIMER_HPP
0010 
0011 #include <boost/cobalt/io/detail/config.hpp>
0012 #include <boost/cobalt/op.hpp>
0013 #include <boost/cobalt/io/ops.hpp>
0014 #include <boost/asio/basic_waitable_timer.hpp>
0015 
0016 #include <boost/system/result.hpp>
0017 
0018 namespace boost::cobalt::io
0019 {
0020 
0021 struct BOOST_SYMBOL_VISIBLE system_timer final
0022 {
0023   /// The clock type.
0024   typedef std::chrono::system_clock clock_type;
0025 
0026   /// The duration type of the clock.
0027   typedef typename clock_type::duration duration;
0028 
0029   /// The time point type of the clock.
0030   typedef typename clock_type::time_point time_point;
0031 
0032   BOOST_COBALT_IO_DECL system_timer(const cobalt::executor & executor = this_thread::get_executor());
0033   BOOST_COBALT_IO_DECL system_timer(const time_point& expiry_time,
0034                const cobalt::executor & executor = this_thread::get_executor());
0035   BOOST_COBALT_IO_DECL system_timer(const duration& expiry_time,
0036                const cobalt::executor & executor = this_thread::get_executor());
0037 
0038   void cancel();
0039 
0040   BOOST_COBALT_IO_DECL time_point expiry() const;
0041   BOOST_COBALT_IO_DECL void reset(const time_point& expiry_time);
0042   BOOST_COBALT_IO_DECL void reset(const duration& expiry_time);
0043   BOOST_COBALT_IO_DECL bool expired() const;
0044 
0045   [[nodiscard]] wait_op wait() { return {this, initiate_wait_, try_wait_}; }
0046  private:
0047   BOOST_COBALT_IO_DECL static void initiate_wait_(void *, boost::cobalt::completion_handler<system::error_code>);
0048   BOOST_COBALT_IO_DECL static void try_wait_(void *, boost::cobalt::handler<system::error_code>);
0049   asio::basic_waitable_timer<std::chrono::system_clock,
0050                              asio::wait_traits<std::chrono::system_clock>,
0051                              executor> timer_;
0052 };
0053 
0054 }
0055 
0056 #endif //BOOST_COBALT_IO_SYSTEM_TIMER_HPP