rotor
Event loop friendly C++ actor micro-framework
 
Loading...
Searching...
No Matches
system_context_thread.h
1#pragma once
2
3//
4// Copyright (c) 2019-2022 Ivan Baidakou (basiliscos) (the dot dmol at gmail dot com)
5//
6// Distributed under the MIT Software License
7//
8
9#include "rotor/arc.hpp"
10#include "rotor/system_context.h"
11#include "rotor/timer_handler.hpp"
12#include "rotor/thread/export.h"
13#include <chrono>
14#include <condition_variable>
15#include <list>
16#include <mutex>
17#include <thread>
18
19#if defined(_MSC_VER)
20#pragma warning(push)
21#pragma warning(disable : 4251)
22#endif
23
24namespace rotor {
25namespace thread {
26
27struct supervisor_thread_t;
28
31
36struct ROTOR_THREAD_API system_context_thread_t : public system_context_t {
39
45 virtual void run() noexcept;
46
48 void check() noexcept;
49
50 protected:
52 using clock_t = std::chrono::steady_clock;
53
60
62 clock_t::time_point deadline;
63 };
64
66 using list_t = std::list<deadline_info_t>;
67
69 void update_time() noexcept;
70
72 void start_timer(const pt::time_duration &interval, timer_handler_base_t &handler) noexcept;
73
76 void cancel_timer(request_id_t timer_id) noexcept;
77
79 std::mutex mutex;
80
82 std::condition_variable cv;
83
85 clock_t::time_point now;
86
88 list_t timer_nodes;
89
91 bool intercepting = false;
92
93 friend struct supervisor_thread_t;
94};
95
98
99} // namespace thread
100} // namespace rotor
101
102#if defined(_MSC_VER)
103#pragma warning(pop)
104#endif
intrusive_ptr_t< supervisor_thread_t > supervisor_ptr_t
intrusive pointer for thread supervisor
Definition system_context_thread.h:30
rotor::intrusive_ptr_t< system_context_thread_t > system_context_ptr_t
intrusive pointer type for system context thread context
Definition system_context_thread.h:97
Basic namespace for all rotor functionalities.
Definition rotor.hpp:21
std::size_t request_id_t
timer identifier type in the scope of the actor
Definition forward.hpp:34
boost::intrusive_ptr< T > intrusive_ptr_t
alias for intrusive pointer
Definition arc.hpp:27
The system context holds root supervisor_t (intrusive pointer) and may be loop-related details in der...
Definition system_context.h:32
pure thread supervisor dedicated for blocking I/O or computing operations
Definition supervisor_thread.h:24
struct to keep timer handlers
Definition system_context_thread.h:57
timer_handler_base_t * handler
non-owning pointer to timer handler
Definition system_context_thread.h:59
clock_t::time_point deadline
time point, after which the timer is considered expired
Definition system_context_thread.h:62
The thread system context, for blocking operations.
Definition system_context_thread.h:36
system_context_thread_t() noexcept
constructs thread system context
void update_time() noexcept
fires handlers for expired timers
std::chrono::steady_clock clock_t
an alias for monotonic clock
Definition system_context_thread.h:52
std::list< deadline_info_t > list_t
ordered list of deadline infos (type)
Definition system_context_thread.h:66
Base class for timer handler.
Definition timer_handler.hpp:17