L4Re - L4 Runtime Environment
__timeout.h
1 
6 /*
7  * (c) 2008-2009 Adam Lackorzynski <adam@os.inf.tu-dresden.de>,
8  * Alexander Warg <warg@os.inf.tu-dresden.de>,
9  * Torsten Frenzel <frenzel@os.inf.tu-dresden.de>
10  * economic rights: Technische Universit├Ąt Dresden (Germany)
11  *
12  * This file is part of TUD:OS and distributed under the terms of the
13  * GNU General Public License 2.
14  * Please see the COPYING-GPL-2 file for details.
15  *
16  * As a special exception, you may use this file as part of a free software
17  * library without restriction. Specifically, if other files instantiate
18  * templates or use macros or inline functions from this file, or you compile
19  * this file and link it with other files to produce an executable, this
20  * file does not by itself cause the resulting executable to be covered by
21  * the GNU General Public License. This exception does not however
22  * invalidate any other reasons why the executable file might be covered by
23  * the GNU General Public License.
24  */
25 #ifndef L4_SYS_TIMEOUT_H__
26 #define L4_SYS_TIMEOUT_H__
27 
28 #include <l4/sys/l4int.h>
29 
45 typedef struct l4_timeout_s {
47 } __attribute__((packed)) l4_timeout_s;
48 
49 
57 typedef union l4_timeout_t {
59  struct
60  {
61 #ifdef __BIG_ENDIAN__
62  l4_timeout_s snd;
63  l4_timeout_s rcv;
64 #else
67 #endif
68  } p;
69 } l4_timeout_t;
70 
71 
77 #define L4_IPC_TIMEOUT_0 ((l4_timeout_s){0x0400})
78 #define L4_IPC_TIMEOUT_NEVER ((l4_timeout_s){0})
79 #define L4_IPC_NEVER_INITIALIZER {0}
80 #define L4_IPC_NEVER ((l4_timeout_t){0})
81 #define L4_IPC_RECV_TIMEOUT_0 ((l4_timeout_t){0x00000400})
82 #define L4_IPC_SEND_TIMEOUT_0 ((l4_timeout_t){0x04000000})
83 #define L4_IPC_BOTH_TIMEOUT_0 ((l4_timeout_t){0x04000400})
85 
86 
93  L4_TIMEOUT_ABS_V1_ms = 0,
94  L4_TIMEOUT_ABS_V2_ms,
95  L4_TIMEOUT_ABS_V4_ms,
96  L4_TIMEOUT_ABS_V8_ms, /* 5 */
97  L4_TIMEOUT_ABS_V16_ms,
98  L4_TIMEOUT_ABS_V32_ms,
99  L4_TIMEOUT_ABS_V64_ms,
100  L4_TIMEOUT_ABS_V128_ms,
101  L4_TIMEOUT_ABS_V256_ms, /* 10 */
102  L4_TIMEOUT_ABS_V512_ms,
103  L4_TIMEOUT_ABS_V1_s,
104  L4_TIMEOUT_ABS_V2_s,
105  L4_TIMEOUT_ABS_V4_s,
106  L4_TIMEOUT_ABS_V8_s,
107  L4_TIMEOUT_ABS_V16_s,
108  L4_TIMEOUT_ABS_V32_s,
109 };
110 
120 L4_INLINE
121 l4_timeout_s l4_timeout_rel(unsigned man, unsigned exp) L4_NOTHROW;
122 
123 
133 L4_INLINE
134 l4_timeout_t l4_ipc_timeout(unsigned snd_man, unsigned snd_exp,
135  unsigned rcv_man, unsigned rcv_exp) L4_NOTHROW;
136 
146 L4_INLINE
148 
156 L4_INLINE
158 
166 L4_INLINE
168 
177 L4_INLINE
179 
180 
189 L4_INLINE
191 
201 L4_INLINE
203 
204 
205 /*
206  * Implementation
207  */
208 
209 L4_INLINE
210 l4_timeout_t l4_ipc_timeout(unsigned snd_man, unsigned snd_exp,
211  unsigned rcv_man, unsigned rcv_exp) L4_NOTHROW
212 {
213  l4_timeout_t t;
214  t.p.snd.t = (snd_man & 0x3ff) | ((snd_exp << 10) & 0x7c00);
215  t.p.rcv.t = (rcv_man & 0x3ff) | ((rcv_exp << 10) & 0x7c00);
216  return t;
217 }
218 
219 
220 L4_INLINE
222 {
223  l4_timeout_t t;
224  t.p.snd = snd;
225  t.p.rcv = rcv;
226  return t;
227 }
228 
229 
230 L4_INLINE
231 void l4_snd_timeout(l4_timeout_s snd, l4_timeout_t *to) L4_NOTHROW
232 {
233  to->p.snd = snd;
234 }
235 
236 
237 L4_INLINE
238 void l4_rcv_timeout(l4_timeout_s rcv, l4_timeout_t *to) L4_NOTHROW
239 {
240  to->p.rcv = rcv;
241 }
242 
243 
244 L4_INLINE
245 l4_timeout_s l4_timeout_rel(unsigned man, unsigned exp) L4_NOTHROW
246 {
247  return (l4_timeout_s){(l4_uint16_t)((man & 0x3ff) | ((exp << 10) & 0x7c00))};
248 }
249 
250 
251 L4_INLINE
253 {
254  if (to.t == 0)
255  return ~0ULL;
256  return (l4_kernel_clock_t)(to.t & 0x3ff) << ((to.t >> 10) & 0x1f);
257 }
258 
259 
260 L4_INLINE
261 unsigned l4_timeout_is_absolute(l4_timeout_s to) L4_NOTHROW
262 {
263  return to.t & 0x8000;
264 }
265 
266 
267 L4_INLINE
269 {
270  if (l4_timeout_is_absolute(to))
271  return 0; /* We cannot retrieve the value ... */
272  else
273  return cur + l4_timeout_rel_get(to);
274 }
275 
276 
277 #endif
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:221
union l4_timeout_t l4_timeout_t
Timeout pair.
unsigned short int l4_uint16_t
Unsigned 16bit value.
Definition: l4int.h:38
void l4_snd_timeout(l4_timeout_s snd, l4_timeout_t *to) L4_NOTHROW
Set send timeout in given to timeout.
Definition: __timeout.h:231
l4_timeout_abs_validity
Intervals of validity for absolute timeoutsTimes are actually 2^x values (e.g.
Definition: __timeout.h:92
l4_uint32_t raw
raw value
Definition: __timeout.h:58
l4_timeout_s snd
send timeout
Definition: __timeout.h:66
Timeout pair.
Definition: __timeout.h:57
l4_kernel_clock_t l4_timeout_get(l4_kernel_clock_t cur, l4_timeout_s to) L4_NOTHROW
Get clock value for a clock + a timeout.
Definition: __timeout.h:268
Basic timeout specification.
Definition: __timeout.h:45
struct l4_timeout_t::@16 p
combined timeout
l4_uint64_t l4_kernel_clock_t
Kernel clock type.
Definition: l4int.h:65
l4_timeout_t l4_ipc_timeout(unsigned snd_man, unsigned snd_exp, unsigned rcv_man, unsigned rcv_exp) L4_NOTHROW
Convert explicit timeout values to l4_timeout_t type.
Definition: __timeout.h:210
l4_uint16_t t
timeout value
Definition: __timeout.h:46
void l4_rcv_timeout(l4_timeout_s rcv, l4_timeout_t *to) L4_NOTHROW
Set receive timeout in given to timeout.
Definition: __timeout.h:238
l4_kernel_clock_t l4_timeout_rel_get(l4_timeout_s to) L4_NOTHROW
Get clock value of out timeout.
Definition: __timeout.h:252
struct l4_timeout_s l4_timeout_s
Basic timeout specification.
l4_timeout_s rcv
receive timeout
Definition: __timeout.h:65
l4_timeout_s l4_timeout_rel(unsigned man, unsigned exp) L4_NOTHROW
Get relative timeout consisting of mantissa and exponent.
Definition: __timeout.h:245
unsigned l4_timeout_is_absolute(l4_timeout_s to) L4_NOTHROW
Return whether the given timeout is absolute or not.
Definition: __timeout.h:261
unsigned int l4_uint32_t
Unsigned 32bit value.
Definition: l4int.h:40
#define L4_NOTHROW
Mark a function declaration and definition as never throwing an exception.
Definition: compiler.h:185