L4Re Operating System Framework
Interface and Usage Documentation
Loading...
Searching...
No Matches
L4Re::Util::Counter_atomic< COUNTER > Struct Template Reference

Thread safe version of counter for Counting_cap_alloc. More...

#include <counting_cap_alloc>

+ Collaboration diagram for L4Re::Util::Counter_atomic< COUNTER >:

Public Member Functions

bool inc ()
 Increment counter if not yet saturated.
 
Type dec ()
 Decrement counter if not saturated.
 

Detailed Description

template<typename COUNTER = unsigned char>
struct L4Re::Util::Counter_atomic< COUNTER >

Thread safe version of counter for Counting_cap_alloc.

Despite using atomic instructions, this version has to make sure that capability slots are not reused too early. If the last reference is gone, the capability slot has to be unmapped. The slot must only be allocated again when the unmap has completed. This is accomplished by starting with an initial count of 2. The last reference will decrease the counter to 1. Only then, after the slot was unmapped, will the counter be set to 0. This will allow other threads to reallocate the slot.

Definition at line 109 of file counting_cap_alloc.

Member Function Documentation

◆ dec()

template<typename COUNTER = unsigned char>
Type L4Re::Util::Counter_atomic< COUNTER >::dec ( )
inline

Decrement counter if not saturated.

Once the counter reached the saturated state, the counter value isn't changed.

Definition at line 153 of file counting_cap_alloc.

◆ inc()

template<typename COUNTER = unsigned char>
bool L4Re::Util::Counter_atomic< COUNTER >::inc ( )
inline

Increment counter if not yet saturated.

Once the counter reached the saturated state, the counter value isn't changed.

Return values
falseThe counter just went saturated after it was increased.
trueEither the counter was already saturated – in that case the counter value was not changed, or the counter was not saturated – in that case the counter was increased.

Definition at line 132 of file counting_cap_alloc.


The documentation for this struct was generated from the following file: