30 namespace L4Re {
namespace Util {
35 template<
typename COUNTER =
unsigned char >
41 static Type nil() {
return 0; }
43 void free() { _cnt = 0; }
44 bool is_free()
const {
return _cnt == 0; }
45 void inc() { ++_cnt; }
46 Type dec() {
return --_cnt; }
47 void alloc() { _cnt = 1; }
74 template <
typename COUNTERTYPE = L4Re::Util::Counter<
unsigned char> >
79 typedef COUNTERTYPE Counter;
89 template <
unsigned COUNT>
90 struct Counter_storage
92 COUNTERTYPE _buf[COUNT];
93 typedef COUNTERTYPE Buf_type[COUNT];
94 enum { Size = COUNT };
105 : _items(0), _free_hint(0), _bias(0), _capacity(0)
121 void setup(
void *m,
long capacity,
long bias) noexcept
123 _items = (Counter*)m;
124 _capacity = capacity;
137 for (
long i = _free_hint; i < _capacity; ++i)
139 if (_items[i].is_free())
152 template <
typename T>
155 return L4::cap_cast<T>(
alloc());
252 if (_items[c].
dec() == Counter::nil())
271 return _capacity + _bias - 1;
Internal reference-counting cap allocator.
void take(L4::Cap< void > cap) noexcept
Increase the reference counter for the capability.
L4::Cap< void > alloc() noexcept
Allocate a new capability slot.
bool free(L4::Cap< void > cap, l4_cap_idx_t task=L4_INVALID_CAP, unsigned unmap_flags=L4_FP_ALL_SPACES) noexcept
Free the capability.
L4::Cap< T > alloc() noexcept
Allocate a new capability slot.
void setup(void *m, long capacity, long bias) noexcept
Set up the backing memory for the allocator and the area of managed capability slots.
Counting_cap_alloc() noexcept
Create a new, empty allocator.
long last() noexcept
Return highest capability id managed by this allocator.
bool release(L4::Cap< void > cap, l4_cap_idx_t task=L4_INVALID_CAP, unsigned unmap_flags=L4_FP_ALL_SPACES) noexcept
Decrease the reference counter for a capability.
C++ interface for capabilities.
unsigned long l4_cap_idx_t
L4 Capability selector Type.
unsigned l4_is_valid_cap(l4_cap_idx_t c) L4_NOTHROW
Test if a capability selector is a valid selector.
@ L4_CAP_SHIFT
Capability index shift.
@ L4_INVALID_CAP
Invalid capability selector.
l4_msgtag_t l4_task_unmap(l4_cap_idx_t task, l4_fpage_t fpage, l4_umword_t map_mask) L4_NOTHROW
Revoke rights from the task.
@ L4_FP_ALL_SPACES
Flag to tell the unmap operation to unmap all child mappings including the mapping in the invoked tas...
IOModifier const dec
Modifies the stream to print numbers as decimal values.
Counter for Counting_cap_alloc with variable data width.
Low-level assert implementation.
#define l4_assert(expr)
Low-level assert.
Common task related definitions.