include/boost/corosio/native/detail/iocp/win_timers.hpp
100.0% Lines (6/6)
100.0% Functions (3/3)
100.0% Branches (1/1)
| Line | Branch | TLA | Hits | Source Code |
|---|---|---|---|---|
| 1 | // | |||
| 2 | // Copyright (c) 2025 Vinnie Falco ([email protected]) | |||
| 3 | // Copyright (c) 2026 Steve Gerbino | |||
| 4 | // | |||
| 5 | // Distributed under the Boost Software License, Version 1.0. (See accompanying | |||
| 6 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) | |||
| 7 | // | |||
| 8 | // Official repository: https://github.com/cppalliance/corosio | |||
| 9 | // | |||
| 10 | ||||
| 11 | #ifndef BOOST_COROSIO_NATIVE_DETAIL_IOCP_WIN_TIMERS_HPP | |||
| 12 | #define BOOST_COROSIO_NATIVE_DETAIL_IOCP_WIN_TIMERS_HPP | |||
| 13 | ||||
| 14 | #include <boost/corosio/detail/platform.hpp> | |||
| 15 | ||||
| 16 | #if BOOST_COROSIO_HAS_IOCP | |||
| 17 | ||||
| 18 | #include <boost/corosio/native/detail/iocp/win_completion_key.hpp> | |||
| 19 | #include <boost/corosio/native/detail/iocp/win_windows.hpp> | |||
| 20 | ||||
| 21 | #include <chrono> | |||
| 22 | #include <memory> | |||
| 23 | ||||
| 24 | namespace boost::corosio::detail { | |||
| 25 | ||||
| 26 | /** Abstract interface for timer wakeup mechanisms. | |||
| 27 | ||||
| 28 | Posts key_wake_dispatch to the IOCP to trigger timer processing. | |||
| 29 | */ | |||
| 30 | class win_timers | |||
| 31 | { | |||
| 32 | protected: | |||
| 33 | long* dispatch_required_; | |||
| 34 | ||||
| 35 | public: | |||
| 36 | using time_point = std::chrono::steady_clock::time_point; | |||
| 37 | ||||
| 38 | 290 | explicit win_timers(long* dispatch_required) noexcept | ||
| 39 | 290 | : dispatch_required_(dispatch_required) | ||
| 40 | { | |||
| 41 | 290 | } | ||
| 42 | ||||
| 43 | 290 | virtual ~win_timers() = default; | ||
| 44 | ||||
| 45 | virtual void start() = 0; | |||
| 46 | virtual void stop() = 0; | |||
| 47 | virtual void update_timeout(time_point next_expiry) = 0; | |||
| 48 | }; | |||
| 49 | ||||
| 50 | std::unique_ptr<win_timers> | |||
| 51 | make_win_timers(void* iocp, long* dispatch_required); | |||
| 52 | ||||
| 53 | } // namespace boost::corosio::detail | |||
| 54 | ||||
| 55 | // Include concrete implementations needed by make_win_timers | |||
| 56 | #include <boost/corosio/native/detail/iocp/win_timers_nt.hpp> | |||
| 57 | #include <boost/corosio/native/detail/iocp/win_timers_thread.hpp> | |||
| 58 | ||||
| 59 | namespace boost::corosio::detail { | |||
| 60 | ||||
| 61 | inline std::unique_ptr<win_timers> | |||
| 62 | 290 | make_win_timers(void* iocp, long* dispatch_required) | ||
| 63 | { | |||
| 64 | // Thread-based is faster; NT API requires one-shot re-association per | |||
| 65 | // wakeup which tanks performance. See timers_nt.hpp for details. | |||
| 66 |
1/1✓ Branch 2 → 3 taken 290 times.
|
290 | return std::make_unique<win_timers_thread>(iocp, dispatch_required); | |
| 67 | ||||
| 68 | #if 0 | |||
| 69 | // NT native API (Windows 8+) | |||
| 70 | if (auto p = win_timers_nt::try_create(iocp, dispatch_required)) | |||
| 71 | return p; | |||
| 72 | #endif | |||
| 73 | } | |||
| 74 | ||||
| 75 | } // namespace boost::corosio::detail | |||
| 76 | ||||
| 77 | #endif // BOOST_COROSIO_HAS_IOCP | |||
| 78 | ||||
| 79 | #endif // BOOST_COROSIO_NATIVE_DETAIL_IOCP_WIN_TIMERS_HPP | |||
| 80 |