L4Re Operating System Framework
Interface and Usage Documentation
Loading...
Searching...
No Matches
event_buffer
1// vi:set ft=cpp: -*- Mode: C++ -*-
2/*
3 * (c) 2008-2009 Adam Lackorzynski <adam@os.inf.tu-dresden.de>,
4 * Alexander Warg <warg@os.inf.tu-dresden.de>
5 * economic rights: Technische Universität Dresden (Germany)
6 *
7 * License: see LICENSE.spdx (in this directory or the directories above)
8 */
9
10#pragma once
11
12#include <l4/re/event>
13#include <l4/re/rm>
14
15#include <string.h>
16
17namespace L4Re { namespace Util {
18
23template< typename PAYLOAD >
24class Event_buffer_t : public L4Re::Event_buffer_t<PAYLOAD>
25{
26private:
27 void *_buf;
28public:
34 void *buf() const noexcept { return _buf; }
35
45 {
46 l4_addr_t sz = ds->size();
47 _buf = 0;
48
49 long r = rm->attach(&_buf, sz,
52 if (r < 0)
53 return r;
54
55 *static_cast<L4Re::Event_buffer_t<PAYLOAD> *>(this)
57 return 0;
58 }
59
67 long detach(L4::Cap<L4Re::Rm> rm) noexcept
68 {
70 if (_buf)
71 return rm->detach(_buf, &ds);
72 return 0;
73 }
74
75};
76
81template< typename PAYLOAD >
83{
84public:
85
92 template< typename CB, typename D >
93 void foreach_available_event(CB const &cb, D data = D())
94 {
95 typename Event_buffer_t<PAYLOAD>::Event *e;
96 while ((e = Event_buffer_t<PAYLOAD>::next()))
97 {
98 cb(e, data);
99 e->free();
100 }
101 }
102
113 template< typename CB, typename D >
115 L4::Cap<L4::Thread> thread,
116 CB const &cb, D data = D())
117 {
118
119 if (l4_error(irq->bind_thread(thread, 0)))
120 return;
121
122 while (1)
123 {
124 long r;
126 l4_utcb());
127 if (r)
128 continue;
129
130 foreach_available_event(cb, data);
131 }
132 }
133};
134
135typedef Event_buffer_t<Default_event_payload> Event_buffer;
136typedef Event_buffer_consumer_t<Default_event_payload> Event_buffer_consumer;
137
138}}
Event buffer class.
Definition event:249
Event * next() noexcept
Definition event:305
An event buffer consumer.
Definition event_buffer:83
void process(L4::Cap< L4::Irq > irq, L4::Cap< L4::Thread > thread, CB const &cb, D data=D())
Continuously wait for events and process them.
Definition event_buffer:114
void foreach_available_event(CB const &cb, D data=D())
Call function on every available event.
Definition event_buffer:93
Event_buffer utility class.
Definition event_buffer:25
long detach(L4::Cap< L4Re::Rm > rm) noexcept
Detach event buffer from address space.
Definition event_buffer:67
long attach(L4::Cap< L4Re::Dataspace > ds, L4::Cap< L4Re::Rm > rm) noexcept
Attach event buffer from address space.
Definition event_buffer:44
void * buf() const noexcept
Return the buffer.
Definition event_buffer:34
l4_cap_idx_t cap() const noexcept
Return capability selector.
Definition capability.h:49
C++ interface for capabilities.
Definition capability.h:249
unsigned long l4_addr_t
Address type.
Definition l4int.h:34
l4_ret_t l4_error(l4_msgtag_t tag) L4_NOTHROW
Get IPC error code if any or message tag label otherwise for an IPC call.
Definition ipc.h:730
l4_umword_t l4_ipc_error(l4_msgtag_t tag, l4_utcb_t *utcb) L4_NOTHROW
Get the IPC error code for an IPC operation.
Definition ipc.h:713
l4_msgtag_t l4_irq_receive(l4_cap_idx_t irq, l4_timeout_t to) L4_NOTHROW
Unmask and wait for specified IRQ.
Definition irq.h:313
#define L4_IPC_NEVER
never timeout
Definition __timeout.h:76
l4_utcb_t * l4_utcb(void) L4_NOTHROW L4_PURE
Get the UTCB address.
Definition utcb.h:369
Documentation of the L4 Runtime Environment utility functionality in C++.
Definition l4re.dox:21
L4Re C++ Interfaces.
Definition cmd_control:14
Cap< T > make_cap_rw(L4::Cap< T > cap) noexcept
Make an L4::Ipc::Cap<T> for the given capability with L4_CAP_FPAGE_RW rights.
Definition ipc_types:855
Region mapper interface.
String.
@ RW
Readable and writable region.
Definition rm:141
@ Search_addr
Search for a suitable address range.
Definition rm:115