corosio


Directory: ../corosio_lcov_PR-139/
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 100.0% 36 / 0 / 36
Functions: 100.0% 8 / 0 / 8
Branches: 80.0% 8 / 0 / 10

src/corosio/src/timer.cpp
Line Branch Exec Source
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 8211 timer::
29 8209 ~timer()
30 {
31
2/2
✓ Branch 0 taken 8205 times.
✓ Branch 1 taken 4 times.
8209 if (impl_)
32 8205 detail::timer_service_destroy(get());
33 8211 }
34
35 8207 timer::
36 8207 timer(capy::execution_context& ctx)
37 8207 : io_object(ctx)
38 {
39
1/1
✓ Branch 1 taken 8207 times.
8207 impl_ = detail::timer_service_create(ctx);
40 8207 }
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