L4Re - L4 Runtime Environment
poll_timeout_kipclock
1 /*
2  * (c) 2012 Adam Lackorzynski <adam@os.inf.tu-dresden.de>,
3  * economic rights: Technische Universität Dresden (Germany)
4  * This file is part of TUD:OS and distributed under the terms of the
5  * GNU Lesser General Public License 2.1.
6  * Please see the COPYING-LGPL-2.1 file for details.
7  */
8 #pragma once
9 
10 #include <cassert>
11 #include <l4/sys/kip.h>
12 #include <l4/re/env.h>
13 
14 namespace L4 {
15 
38 {
39 public:
44  Poll_timeout_kipclock(unsigned poll_time_us)
45  {
46  set(poll_time_us);
47  }
48 
53  void set(unsigned poll_time_us)
54  {
55  _timeout = l4_kip_clock(l4re_kip()) + poll_time_us;
56  _last_check = true;
57  }
58 
67  bool test(bool expression = true)
68  {
69  if (!expression)
70  return false;
71 
72  return _last_check = l4_kip_clock(l4re_kip()) < _timeout;
73  }
74 
79  bool timed_out() const { return !_last_check; }
80 
81 private:
82  l4_cpu_time_t _timeout;
83  bool _last_check;
84 };
85 }
A polling timeout based on the L4Re clock.
bool test(bool expression=true)
Test whether timeout has expired.
L4 low-level kernel interface.
l4_kernel_info_t * l4re_kip(void) L4_NOTHROW
Get Kernel Info Page.
Definition: env.h:188
Poll_timeout_kipclock(unsigned poll_time_us)
Initialise relative timeout in microseconds.
Environment interface.
bool timed_out() const
Query whether timeout has expired.
l4_uint64_t l4_cpu_time_t
CPU clock type.
Definition: l4int.h:59
Kernel Info Page access functions.
l4_cpu_time_t l4_kip_clock(l4_kernel_info_t *kip) L4_NOTHROW
Return clock value from the KIP.
Definition: kip.h:138