libs/corosio/src/corosio/src/timer.cpp

100.0% Lines (36/36) 100.0% Functions (8/8) 80.0% Branches (8/10)
libs/corosio/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
15 namespace boost::corosio {
16
17 namespace detail {
18
19 // Defined in timer_service.cpp
20 extern timer::timer_impl* timer_service_create(capy::execution_context&);
21 extern void timer_service_destroy(timer::timer_impl&) noexcept;
22 extern std::size_t timer_service_update_expiry(timer::timer_impl&);
23 extern std::size_t timer_service_cancel(timer::timer_impl&) noexcept;
24 extern std::size_t timer_service_cancel_one(timer::timer_impl&) noexcept;
25
26 } // namespace detail
27
28 9202 timer::
29 9200 ~timer()
30 {
31
2/2
✓ Branch 0 taken 9196 times.
✓ Branch 1 taken 4 times.
9200 if (impl_)
32 9196 detail::timer_service_destroy(get());
33 9202 }
34
35 9198 timer::
36 9198 timer(capy::execution_context& ctx)
37 9198 : io_object(ctx)
38 {
39
1/1
✓ Branch 1 taken 9198 times.
9198 impl_ = detail::timer_service_create(ctx);
40 9198 }
41
42 2 timer::
43 2 timer(capy::execution_context& ctx, time_point t)
44 2 : timer(ctx)
45 {
46
1/1
✓ Branch 1 taken 2 times.
2 expires_at(t);
47 2 }
48
49 2 timer::
50 2 timer(timer&& other) noexcept
51 2 : io_object(other.context())
52 {
53 2 impl_ = other.impl_;
54 2 other.impl_ = nullptr;
55 2 }
56
57 timer&
58 4 timer::
59 operator=(timer&& other)
60 {
61
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 if (this != &other)
62 {
63
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 2 times.
4 if (ctx_ != other.ctx_)
64 2 detail::throw_logic_error(
65 "cannot move timer across execution contexts");
66
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if (impl_)
67 2 detail::timer_service_destroy(get());
68 2 impl_ = other.impl_;
69 2 other.impl_ = nullptr;
70 }
71 2 return *this;
72 }
73
74 std::size_t
75 8 timer::
76 do_cancel()
77 {
78 8 return detail::timer_service_cancel(get());
79 }
80
81 std::size_t
82 2 timer::
83 do_cancel_one()
84 {
85 2 return detail::timer_service_cancel_one(get());
86 }
87
88 std::size_t
89 6 timer::
90 do_update_expiry()
91 {
92 6 return detail::timer_service_update_expiry(get());
93 }
94
95 } // namespace boost::corosio
96