src/corosio/src/timer.cpp

100.0% Lines (18/18) 100.0% Functions (8/8)
src/corosio/src/timer.cpp
Line Hits Source Code
1 //
2 // Copyright (c) 2025 Vinnie Falco (vinnie.falco@gmail.com)
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 #include <boost/corosio/timer.hpp>
12
13 namespace boost::corosio {
14
15 namespace detail {
16
17 // Defined in timer_service.cpp
18 extern std::size_t timer_service_update_expiry(timer::implementation&);
19 extern std::size_t timer_service_cancel(timer::implementation&) noexcept;
20 extern std::size_t timer_service_cancel_one(timer::implementation&) noexcept;
21 extern io_object::io_service&
22 timer_service_direct(capy::execution_context&) noexcept;
23
24 } // namespace detail
25
26 9126 timer::~timer() = default;
27
28 9122 timer::timer(capy::execution_context& ctx)
29 9122 : io_object(handle(ctx, detail::timer_service_direct(ctx)))
30 {
31 9122 }
32
33 2 timer::timer(capy::execution_context& ctx, time_point t) : timer(ctx)
34 {
35 2 expires_at(t);
36 2 }
37
38 2 timer::timer(timer&& other) noexcept : io_object(std::move(other)) {}
39
40 timer&
41 4 timer::operator=(timer&& other) noexcept
42 {
43 4 if (this != &other)
44 4 h_ = std::move(other.h_);
45 4 return *this;
46 }
47
48 std::size_t
49 8 timer::do_cancel()
50 {
51 8 return detail::timer_service_cancel(get());
52 }
53
54 std::size_t
55 2 timer::do_cancel_one()
56 {
57 2 return detail::timer_service_cancel_one(get());
58 }
59
60 std::size_t
61 6 timer::do_update_expiry()
62 {
63 6 return detail::timer_service_update_expiry(get());
64 }
65
66 } // namespace boost::corosio
67