L4Re Operating System Framework
Interface and Usage Documentation
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
ipc_timeout_queue
1// vim:set ft=cpp: -*- Mode: C++ -*-
2/*
3 * (c) 2014 Steffen Liebergeld <steffen.liebergeld@kernkonzept.com>
4 *
5 * License: see LICENSE.spdx (in this directory or the directories above)
6 */
7#pragma once
8
9#include <l4/cxx/hlist>
10#include <l4/sys/cxx/ipc_server_loop>
11
12namespace L4 { namespace Ipc_svr {
13
19{
20 friend class Timeout_queue;
21public:
23 Timeout() : _timeout(0) {}
24
26 virtual ~Timeout() = 0;
27
34 virtual void expired() = 0;
35
43 { return _timeout; }
44
45private:
46 l4_kernel_clock_t _timeout;
47};
48
50
56{
57public:
60
66 {
67 if (auto e = _timeouts.front())
68 return e->timeout();
69
70 return 0;
71 }
72
82 {
84 return (next != 0) && (next <= now);
85 }
86
92 {
93 while (!_timeouts.empty())
94 {
95 Queue::Iterator top = _timeouts.begin();
96 if ((*top)->_timeout > now)
97 return;
98
99 Timeout *t = *top;
100 top = _timeouts.erase(top);
101 t->expired();
102 }
103 }
104
111 void add(Timeout *timeout, l4_kernel_clock_t time)
112 {
113 timeout->_timeout = time;
114 Queue::Iterator i = _timeouts.begin();
115 while (i != _timeouts.end() && (*i)->timeout() < time)
116 ++i;
117
118 _timeouts.insert_before(timeout, i);
119 }
120
126 void remove(Timeout *timeout)
127 {
128 _timeouts.remove(timeout);
129 }
130
131private:
132 typedef cxx::H_list<Timeout> Queue;
133 Queue _timeouts;
134};
135
149template< typename HOOKS, typename BR_MAN = Br_manager_no_buffers >
150class Timeout_queue_hooks : public BR_MAN
151{
152 l4_kernel_clock_t _now()
153 { return static_cast<HOOKS*>(this)->now(); }
154
155 unsigned _timeout_br()
156 { return this->first_free_br(); }
157
158public:
161 {
163 if (t)
164 return l4_timeout(L4_IPC_TIMEOUT_0, l4_timeout_abs(t, _timeout_br()));
166 }
167
170 {
171 // we must handle the timer only when called after a possible reply
172 // otherwise we probably destroy the reply message.
173 if (mode == L4::Ipc_svr::Reply_separate)
174 {
175 l4_kernel_clock_t now = _now();
176 if (queue.timeout_expired(now))
178 }
179
180 BR_MAN::setup_wait(utcb, mode);
181 }
182
185 {
186 // split up reply and wait when a timeout has expired
187 if (queue.timeout_expired(_now()))
190 }
191
203 {
204 queue.add(timeout, time);
205 return 0;
206 }
207
216 {
218 return 0;
219 }
220
222};
223
224}}
unsigned first_free_br() const
Returns 1 as first free buffer.
Loop hooks mixin for integrating a timeout queue into the server loop.
int add_timeout(Timeout *timeout, l4_kernel_clock_t time) override
Add a timeout to the queue for time time.
L4::Ipc_svr::Reply_mode before_reply(l4_msgtag_t, l4_utcb_t *)
server loop hook
int remove_timeout(Timeout *timeout) override
Remove timeout from the queue.
void setup_wait(l4_utcb_t *utcb, L4::Ipc_svr::Reply_mode mode)
setup_wait() for the server loop
l4_timeout_t timeout()
get the time for the next timeout
Timeout_queue queue
Use this timeout queue.
Timeout queue to be used in l4re server loop.
void remove(Timeout *timeout)
Remove timeout from the queue.
L4::Ipc_svr::Timeout Timeout
Provide a local definition of Timeout for backward compatibility.
l4_kernel_clock_t next_timeout() const
Get the time for the next timeout.
void handle_expired_timeouts(l4_kernel_clock_t now)
run the callbacks of expired timeouts
bool timeout_expired(l4_kernel_clock_t now) const
Determine if a timeout has happened.
void add(Timeout *timeout, l4_kernel_clock_t time)
Add a timeout to the queue.
Callback interface for Timeout_queue.
virtual void expired()=0
callback function to be called when timeout happened
virtual ~Timeout()=0
Destroy a timeout.
Timeout()
Make a timeout.
l4_kernel_clock_t timeout() const
return absolute timeout of this callback.
Const_iterator end() const
Return a const iterator to the end of the list.
bool empty() const
Check if the list is empty.
Iterator begin()
Return an iterator to the beginning of the list.
Value_type front() const
Return the first element in the list.
Basic element type for a double-linked H_list.
Definition hlist:23
General double-linked list of unspecified cxx::H_list_item elements.
Definition hlist:70
static Iterator erase(Iterator const &e)
Remove the element at the given iterator position.
Definition hlist:236
static void insert_before(T *e, Iterator const &succ)
Insert an element before the iterator position.
Definition hlist:180
static void remove(T *e)
Remove the given element from its list.
Definition hlist:220
Reply_mode
Reply mode for server loop.
@ Reply_separate
Server shall call reply and wait separately.
@ Reply_compound
Server shall use a compound reply and wait (fast).
l4_uint64_t l4_kernel_clock_t
Kernel clock type.
Definition l4int.h:53
#define L4_IPC_TIMEOUT_0
Timeout constants.
Definition __timeout.h:73
#define L4_IPC_SEND_TIMEOUT_0
0 send timeout
Definition __timeout.h:78
L4_CONSTEXPR l4_timeout_t l4_timeout(l4_timeout_s snd, l4_timeout_s rcv) L4_NOTHROW
Combine send and receive timeout in a timeout.
Definition __timeout.h:213
l4_timeout_s l4_timeout_abs(l4_kernel_clock_t pint, int br) L4_NOTHROW
Set an absolute timeout.
Definition utcb.h:389
struct l4_utcb_t l4_utcb_t
Opaque type for the UTCB.
Definition utcb.h:56
L4 low-level kernel interface.
Message tag data structure.
Definition types.h:153
Timeout pair.
Definition __timeout.h:53