src/corosio/src/timer.cpp

100.0% Lines (26/26) 100.0% Functions (8/8) 83.3% Branches (5/6)
src/corosio/src/timer.cpp
Line Branch 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 #include <boost/corosio/detail/except.hpp>
14 #include "src/detail/timer_service.hpp"
15
16 namespace boost::corosio {
17
18 namespace detail {
19
20 // Defined in timer_service.cpp
21 extern std::size_t timer_service_update_expiry(timer::implementation&);
22 extern std::size_t timer_service_cancel(timer::implementation&) noexcept;
23 extern std::size_t timer_service_cancel_one(timer::implementation&) noexcept;
24
25 } // namespace detail
26
27 8882 timer::
28 ~timer() = default;
29
30 8878 timer::
31 8878 timer(capy::execution_context& ctx)
32
1/1
✓ Branch 1 taken 8878 times.
8878 : io_object(create_handle<detail::timer_service>(ctx))
33 {
34 8878 }
35
36 2 timer::
37 2 timer(capy::execution_context& ctx, time_point t)
38 2 : timer(ctx)
39 {
40
1/1
✓ Branch 1 taken 2 times.
2 expires_at(t);
41 2 }
42
43 2 timer::
44 2 timer(timer&& other) noexcept
45 2 : io_object(std::move(other))
46 {
47 2 }
48
49 timer&
50 4 timer::
51 operator=(timer&& other)
52 {
53
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 if (this != &other)
54 {
55
2/2
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 2 times.
4 if (&context() != &other.context())
56 2 detail::throw_logic_error(
57 "cannot move timer across execution contexts");
58 2 h_ = std::move(other.h_);
59 }
60 2 return *this;
61 }
62
63 std::size_t
64 8 timer::
65 do_cancel()
66 {
67 8 return detail::timer_service_cancel(get());
68 }
69
70 std::size_t
71 2 timer::
72 do_cancel_one()
73 {
74 2 return detail::timer_service_cancel_one(get());
75 }
76
77 std::size_t
78 6 timer::
79 do_update_expiry()
80 {
81 6 return detail::timer_service_update_expiry(get());
82 }
83
84 } // namespace boost::corosio
85