• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

traintastic / traintastic / 23667775307

27 Mar 2026 09:13PM UTC coverage: 28.009% (-0.002%) from 28.011%
23667775307

push

github

reinder
[boost] fix timer cancel() error_code overload is removed in 1.87, see #220

0 of 5 new or added lines in 1 file covered. (0.0%)

220 existing lines in 10 files now uncovered.

8182 of 29212 relevant lines covered (28.01%)

194.75 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

32.0
/server/src/core/eventloop.hpp
1
/**
2
 * This file is part of Traintastic,
3
 * see <https://github.com/traintastic/traintastic>.
4
 *
5
 * Copyright (C) 2019-2026 Reinder Feenstra
6
 *
7
 * This program is free software; you can redistribute it and/or
8
 * modify it under the terms of the GNU General Public License
9
 * as published by the Free Software Foundation; either version 2
10
 * of the License, or (at your option) any later version.
11
 *
12
 * This program is distributed in the hope that it will be useful,
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
 * GNU General Public License for more details.
16
 *
17
 * You should have received a copy of the GNU General Public License
18
 * along with this program; if not, write to the Free Software
19
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
20
 */
21

22
#ifndef TRAINTASTIC_SERVER_CORE_EVENTLOOP_HPP
23
#define TRAINTASTIC_SERVER_CORE_EVENTLOOP_HPP
24

25
#include <thread>
26
#include <boost/asio/io_context.hpp>
27
#include <boost/asio/post.hpp>
28

29
class EventLoop
30
{
31
  private:
32
    EventLoop() = default;
33
    ~EventLoop() = default;
34

35
    EventLoop(const EventLoop&) = delete;
36
    EventLoop& operator =(const EventLoop&) = delete;
37

38
    inline static std::unique_ptr<boost::asio::io_context> s_ioContext;
39
    inline static std::shared_ptr<boost::asio::executor_work_guard<decltype(s_ioContext->get_executor())>> s_keepAlive;
40

41
  public:
42
#ifdef TRAINTASTIC_TEST
43
    inline static std::thread::id threadId;
44
#else
45
    inline static const std::thread::id threadId = std::this_thread::get_id();
46
#endif
47

48
    static boost::asio::io_context& ioContext()
296✔
49
    {
50
      assert(s_ioContext);
296✔
51
      return *s_ioContext;
296✔
52
    }
53

54
    static void reset()
208✔
55
    {
56
      s_ioContext = std::make_unique<boost::asio::io_context>();
208✔
57
    }
208✔
58

UNCOV
59
    static void exec()
×
60
    {
61
#ifdef TRAINTASTIC_TEST
UNCOV
62
      threadId = std::this_thread::get_id();
×
63
#endif
64
      s_keepAlive = std::make_shared<boost::asio::executor_work_guard<decltype(ioContext().get_executor())>>(ioContext().get_executor());
×
65
      ioContext().run();
×
66
      s_keepAlive.reset();
×
UNCOV
67
    }
×
68

UNCOV
69
    static void stop()
×
70
    {
71
      s_keepAlive.reset();
×
UNCOV
72
    }
×
73

74
    template<typename _Callable, typename... _Args>
UNCOV
75
    inline static void call(_Callable&& __f, _Args&&... __args)
×
76
    {
77
      boost::asio::post(ioContext(), std::bind(__f, __args...));
×
UNCOV
78
    }
×
79

80
    template<typename T>
UNCOV
81
    inline static void deleteLater(T* object)
×
82
    {
83
      boost::asio::post(ioContext(),
×
UNCOV
84
        [object]()
×
85
        {
UNCOV
86
          delete object;
×
87
        });
UNCOV
88
    }
×
89
};
90

91
inline bool isEventLoopThread()
119✔
92
{
93
  return std::this_thread::get_id() == EventLoop::threadId;
119✔
94
}
95

96
#endif
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc