|
Embedded Artistry Framework
Embedded Systems C++ Framework
|
Virtual OS implementation for POSIX systems. More...
|
Classes | |
| class | os::posix::posixOSFactory_impl |
| Implementation of the POSIX OS Factory For API documentation, see embvm::embvm::VirtualOSFactory. More... | |
| class | os::posix::EventFlag |
| POSIX Event Flag Implementation. More... | |
| class | os::posix::Mutex |
| POSIX Mutex Implementation. More... | |
| class | os::posix::Semaphore |
| Create a POSIX semaphore (OSX variant) More... | |
| class | os::posix::Thread |
| Create a POSIX thread. More... | |
Enumerations | |
| enum | os::posix::pthread_priority : uint8_t { os::posix::pthread_priority::panic = 99, os::posix::pthread_priority::interrupt = 99, os::posix::pthread_priority::realtime = 99, os::posix::pthread_priority::veryHigh = 50, os::posix::pthread_priority::high = 40, os::posix::pthread_priority::aboveNormal = 30, os::posix::pthread_priority::normal = 20, os::posix::pthread_priority::belowNormal = 10, os::posix::pthread_priority::low = 5, os::posix::pthread_priority::lowest = 1, os::posix::pthread_priority::idle = 0 } |
| PThread priority values. More... | |
Functions | |
| constexpr posix::pthread_priority | os::posix::convert_to_pthread_priority (embvm::thread::priority p) noexcept |
| Convert between framework thread priorities and PThread priorities. More... | |
Virtual OS implementation for POSIX systems.
| class os::posix::posixOSFactory_impl |
Implementation of the POSIX OS Factory For API documentation, see embvm::embvm::VirtualOSFactory.
|
default |
|
default |
|
inlinestaticnoexcept |
|
inlinestaticnoexcept |
|
inlinestaticnoexcept |
|
inlinestaticnoexcept |
References type.
|
inlinestaticnoexcept |
|
inlinestaticnoexcept |
References p.
|
inlinestaticnoexcept |
|
inlinestaticnoexcept |
|
inlinestaticnoexcept |
|
inlinestaticnoexcept |
|
inlinestaticnoexcept |
| class os::posix::EventFlag |
POSIX Event Flag Implementation.

Public Member Functions | |
| EventFlag ()=default | |
| ~EventFlag () noexcept | |
| Default destructor which cleans up the event flag group. More... | |
| embvm::eventflag::flag_t | get (embvm::eventflag::flag_t bits_wait, embvm::eventflag::option opt=embvm::eventflag::option::OR, bool clearOnExit=true, const embvm::os_timeout_t &timeout=embvm::OS_WAIT_FOREVER) noexcept final |
| Get (or wait for) event flags. More... | |
| void | set (embvm::eventflag::flag_t bits) noexcept final |
| Set event flags. More... | |
| void | setFromISR (embvm::eventflag::flag_t bits) noexcept final |
| Set event flags from an ISR. More... | |
| void | clear () noexcept final |
| Clear all event flag bits. More... | |
| embvm::eventflag::handle_t | native_handle () const noexcept final |
| Get the native handle for the event flags group object. More... | |
Private Member Functions | |
| embvm::eventflag::flag_t | checkAndClearFlags (embvm::eventflag::flag_t bits_wait, embvm::eventflag::option opt, bool clearOnExit) noexcept |
| Helper function which evaluates flags and returns the matching value. More... | |
Private Attributes | |
| std::atomic< embvm::eventflag::flag_t > | flags_ = 0 |
| The storage type for the event flag group's flags. More... | |
| posix::ConditionVariable | cv_ |
| Condition variable which is used to wake threads waiting on this group. More... | |
| posix::Mutex | mutex_ |
| Mutex which protects the flags. More... | |
|
default |
|
noexcept |
Default destructor which cleans up the event flag group.
|
inlineprivatenoexcept |
Helper function which evaluates flags and returns the matching value.
| bits_wait | The bits the caller is waiting for, specified as a bitmask |
| opt | The comparison option (AND or OR) |
| clearOnExit | If true, matching flags will be cleared from flag_ when the function exits |
References flags_, and embvm::eventflag::OR.
Referenced by get().
|
inlinefinalvirtualnoexcept |
Clear all event flag bits.
Implements embvm::VirtualEventFlag.
References flags_, os::posix::Mutex::lock(), mutex_, and os::posix::Mutex::unlock().
|
inlinefinalvirtualnoexcept |
Get (or wait for) event flags.
Get the event flag bits. If the required event flags are not set, this function will block the calling thread until the flags are set or the timeout expires.
To see all bits currently set, set bits_wait to ~0 and timeout_t to the minimal value (timeout_t(1)).
| bits_wait | A bitmask of bits to wait for in the event flags group. |
| opt | The wait option, which is combined with bits_wait to control the behavior of get(). embvm::eventflag::option::OR will return once any of the bits specified in bits_wait are set in the event flag group. embvm::eventflag::option::AND will only return once ALL of the bits specified in bits_wait are set in the event flag group. |
| clearOnExit | If true, all event flags that were specified in bits_wait and set in the event flag group will be set to 0. If false, event flag bits will not be modified. |
| timeout | Specify a timeout for the get operation. If OS_WAIT_FOREVER is supplied, this call will block until the event flags are set. Otherwise, the function will timeout after the elapsed time if flags are not set. |
Implements embvm::VirtualEventFlag.
References checkAndClearFlags(), cv_, os::posix::Mutex::lock(), mutex_, os::posix::Mutex::unlock(), and os::posix::ConditionVariable::wait().
|
inlinefinalvirtualnoexcept |
Get the native handle for the event flags group object.
Implements embvm::VirtualEventFlag.
|
inlinefinalvirtualnoexcept |
Set event flags.
Set event flags from a threaded context. Threads waiting on event flags (via get()) will be notified.
| bits | A bitmask representing the bits to set in the event flag group. |
Implements embvm::VirtualEventFlag.
References os::posix::ConditionVariable::broadcast(), cv_, flags_, os::posix::Mutex::lock(), mutex_, and os::posix::Mutex::unlock().
|
inlinefinalvirtualnoexcept |
Set event flags from an ISR.
Set event flags from an interrupt context. This call must not use a lock. Threads waiting on event flags (via get()) will be notified.
| bits | A bitmask representing the bits to set in the event flag group. |
Implements embvm::VirtualEventFlag.
References os::posix::ConditionVariable::broadcast(), cv_, flags_, os::posix::Mutex::lock(), mutex_, and os::posix::Mutex::unlock().
|
private |
Condition variable which is used to wake threads waiting on this group.
Referenced by get(), set(), and setFromISR().
|
private |
The storage type for the event flag group's flags.
Referenced by checkAndClearFlags(), clear(), set(), and setFromISR().
|
private |
Mutex which protects the flags.
Referenced by clear(), get(), set(), and setFromISR().
| class os::posix::MessageQueue |
Posix Message Queue implementation for Linux.
| TType | The type of data to be stored in the message queue |

Public Member Functions | |
| MessageQueue (std::string_view name, size_t queue_length) noexcept | |
| Construct a message queue with name and length. More... | |
| ~MessageQueue () noexcept | |
| Default destructor. More... | |
| bool | push (TType val, embvm::os_timeout_t timeout=embvm::OS_WAIT_FOREVER) noexcept final |
| Post a message to the queue. More... | |
| TType | pop (embvm::os_timeout_t timeout=embvm::OS_WAIT_FOREVER) noexcept final |
| Retrieve a message from the queue. More... | |
| size_t | size () const noexcept final |
| Get the current size of the message queue. More... | |
| void | reset () noexcept final |
| Reset the message queue to an empty state. More... | |
| bool | empty () const noexcept final |
| Check if the message queue is empty. More... | |
| bool | full () const noexcept final |
| Check if the message queue is full. More... | |
| virtual embvm::msgqueue::handle_t | native_handle () const noexcept=0 |
| Get the native handle for the message queue object. More... | |
Private Attributes | |
| std::string_view | name_ |
| The name of this message queue instance. More... | |
| mqd_t | handle_ |
| The message queue instance handle. More... | |
|
inlineexplicitnoexcept |
Construct a message queue with name and length.
| name | The name associated with the message queue. |
| queue_length | The maximum size of the message queue. |
References assert, os::posix::MessageQueue< TType >::handle_, and os::posix::MessageQueue< TType >::name_.
|
inlinenoexcept |
Default destructor.
References os::posix::MessageQueue< TType >::handle_.
|
inlinefinalvirtualnoexcept |
Check if the message queue is empty.
Implements embvm::VirtualMessageQueue< TType >.
References assert, os::posix::MessageQueue< TType >::handle_, and r.
|
inlinefinalvirtualnoexcept |
Check if the message queue is full.
Implements embvm::VirtualMessageQueue< TType >.
References assert, os::posix::MessageQueue< TType >::handle_, and r.
|
pure virtualnoexceptinherited |
Get the native handle for the message queue object.
Implemented in os::freertos::MessageQueue< TType >.
|
inlinefinalvirtualnoexcept |
Retrieve a message from the queue.
Retrieve a message from the queue. This function blocks the calling thread until a message is received (if OS_WAIT_FOREVER is specified as a timeout), or until the timeout expires.
| timeout | The time to wait for a new message. A value of OS_WAIT_FOREVER indicates that the thread should block until a new message is posted. |
has_value() member function to determine if the value is valid. A valid value is only returned on success. Implements embvm::VirtualMessageQueue< TType >.
References assert, and os::posix::MessageQueue< TType >::handle_.
|
inlinefinalvirtualnoexcept |
Post a message to the queue.
Post a message to the queue. This function blocks the calling thread until there is an available slot (if OS_WAIT_FOREVER is specified as a timeout), or until the timeout expires.
Posting a message to the queue will notify all threads waiting on a new message (via pop()).
| val | The data value to post to the queue. |
| timeout | The time to wait for a new message. A value of OS_WAIT_FOREVER indicates that the thread should block until a new message is posted. |
Implements embvm::VirtualMessageQueue< TType >.
|
inlinefinalvirtualnoexcept |
Reset the message queue to an empty state.
Implements embvm::VirtualMessageQueue< TType >.
References os::posix::MessageQueue< TType >::handle_.
|
inlinefinalvirtualnoexcept |
Get the current size of the message queue.
Size represents the number of elements stored, rather than the maximum size (aka capacity).
Implements embvm::VirtualMessageQueue< TType >.
References assert, os::posix::MessageQueue< TType >::handle_, and r.
|
private |
The message queue instance handle.
Referenced by os::posix::MessageQueue< TType >::empty(), os::posix::MessageQueue< TType >::full(), os::posix::MessageQueue< TType >::MessageQueue(), os::posix::MessageQueue< TType >::pop(), os::posix::MessageQueue< TType >::reset(), os::posix::MessageQueue< TType >::size(), and os::posix::MessageQueue< TType >::~MessageQueue().
|
private |
The name of this message queue instance.
Referenced by os::posix::MessageQueue< TType >::MessageQueue().
| class os::posix::Mutex |
POSIX Mutex Implementation.
Useful reference documentation:

Public Member Functions | |
| Mutex (embvm::mutex::type type=embvm::mutex::type::defaultType, embvm::mutex::mode mode=embvm::mutex::mode::defaultMode) noexcept | |
| Construct a POSIX mutex. More... | |
| ~Mutex () noexcept | |
| Default destructor. More... | |
| void | lock () noexcept final |
| Lock the mutex. More... | |
| void | unlock () noexcept final |
| Unlock the mutex. More... | |
| bool | trylock () noexcept final |
| Try to lock the mutex. More... | |
| embvm::mutex::handle_t | native_handle () const noexcept final |
Private Attributes | |
| pthread_mutex_t | handle_ |
| The pthread handle associated with this mutex;. More... | |
|
inlineexplicitnoexcept |
Construct a POSIX mutex.
| type | The mutex type to create (normal, recursive) |
| mode | The mutex poperating mode, which controls priority inheritance behaviors. |
References assert, handle_, embvm::mutex::none, embvm::mutex::normal, embvm::mutex::priorityInherit, embvm::mutex::protect, r, embvm::mutex::recursive, and type.
|
inlinefinalvirtualnoexcept |
Lock the mutex.
Attempts to lock the mutex. If successful, the function returns with the calling thread owning the lock. If the lock is already owned, the calling thread will block until the lock is available.
Implements embvm::VirtualMutex.
References assert, handle_, and r.
Referenced by os::posix::EventFlag::clear(), os::posix::EventFlag::get(), os::posix::EventFlag::set(), and os::posix::EventFlag::setFromISR().
|
inlinefinalvirtualnoexcept |
Implements embvm::VirtualMutex.
References handle_.
|
inlinefinalvirtualnoexcept |
Try to lock the mutex.
Try to lock the mutex, but don't block the thread if the mutex is already owned.
Implements embvm::VirtualMutex.
|
inlinefinalvirtualnoexcept |
Unlock the mutex.
Implements embvm::VirtualMutex.
References assert, handle_, and r.
Referenced by os::posix::EventFlag::clear(), os::posix::EventFlag::get(), os::posix::EventFlag::set(), and os::posix::EventFlag::setFromISR().
| class os::posix::Semaphore |
Create a POSIX semaphore (OSX variant)
Useful reference documenation:

Public Member Functions | |
| Semaphore (embvm::semaphore::mode mode=embvm::semaphore::mode::counting, embvm::semaphore::count_t ceiling=1, embvm::semaphore::count_t initial_count=-1) noexcept | |
| ~Semaphore () | |
| void | give () noexcept final |
| Increment count Return a resource to the semaphore, incrementing the count. More... | |
| void | giveFromISR () noexcept final |
| Increment count from an ISR Return a resource to the semaphore, incrementing the count. More... | |
| bool | take (embvm::os_timeout_t timeout=embvm::OS_WAIT_FOREVER) noexcept final |
| embvm::semaphore::count_t | count () noexcept final |
| embvm::semaphore::handle_t | native_handle () const noexcept final |
| virtual bool | take (const embvm::os_timeout_t &timeout=embvm::OS_WAIT_FOREVER) noexcept=0 |
| Decrement count Take a resource from the semaphore, decrementing the count. More... | |
| virtual embvm::semaphore::count_t | count () const noexcept=0 |
| Check the count of the semaphore. More... | |
Private Attributes | |
| sem_t | handle_ |
|
inlineexplicitnoexcept |
References assert, embvm::semaphore::binary, handle_, r, and take().
|
pure virtualnoexceptinherited |
Check the count of the semaphore.
Implemented in os::freertos::Semaphore.
|
inlinefinalnoexcept |
|
inlinefinalvirtualnoexcept |
Increment count Return a resource to the semaphore, incrementing the count.
Implements embvm::VirtualSemaphore.
|
inlinefinalvirtualnoexcept |
Increment count from an ISR Return a resource to the semaphore, incrementing the count.
This function variant is safe to call from an interrupt routine. No locking can be used inside this variant.
Implements embvm::VirtualSemaphore.
|
inlinefinalvirtualnoexcept |
Implements embvm::VirtualSemaphore.
References handle_.
|
pure virtualnoexceptinherited |
Decrement count Take a resource from the semaphore, decrementing the count.
| timeout | The time to wait for a semaphore resource. A value of WAIT_FOREVER indicates that the thread should block until the semaphore can be acquired. |
Implemented in os::freertos::Semaphore.
|
inlinefinalnoexcept |
References assert, handle_, and r.
Referenced by Semaphore().
|
private |
Referenced by count(), give(), giveFromISR(), native_handle(), Semaphore(), take(), and ~Semaphore().
| class os::posix::Thread |
Create a POSIX thread.

Public Member Functions | |
| Thread (std::string_view name, embvm::thread::func_t func, embvm::thread::input_t arg, embvm::thread::priority p=embvm::thread::priority::normal, size_t stack_size=PTHREAD_STACK_MIN, void *stack_ptr=nullptr) noexcept | |
| Construct a POSIX thread. More... | |
| ~Thread () noexcept | |
| Default destructor, cleans up thread on deletion. More... | |
| void | start () noexcept final |
| Start the thread, if it is not auto-started. More... | |
| void | terminate () noexcept final |
| Terminate a running thread. More... | |
| void | join () noexcept final |
| Join a running thread. More... | |
| int | detach () noexcept |
| std::string_view | name () const noexcept final |
| View the thread's name. More... | |
| embvm::thread::state | state () const noexcept final |
| Get the thread state. More... | |
| embvm::thread::handle_t | native_handle () const noexcept final |
| Get the native handle for the thread. More... | |
Private Member Functions | |
| void * | thread_func () noexcept |
| Thread handling wrapper to support thread canceling. More... | |
Private Attributes | |
| std::string_view | name_ |
| THe name of this thread instance. More... | |
| pthread_t | handle_ |
| The pthread handle corresponding to this thread instance. More... | |
| embvm::thread::input_t | arg_ |
| Thread input arguments. More... | |
| embvm::thread::func_t | func_ |
| The functor which will be invokd by the thread. More... | |
| std::atomic< embvm::thread::state > | state_ = embvm::thread::state::ready |
|
inlineexplicitnoexcept |
Construct a POSIX thread.
| name | The name associated with the mutex. |
| func | The thread function to execute; can be any functor type. |
| arg | The thread's optional input argument. This value is passed to the thread when it is created. |
| p | The thread priority setting. |
| stack_size | The thread stack size. |
| stack_ptr | The thread stack pointer. If stack_ptr is nullptr, then memory will be allocated by the pthread library. |
References assert, BOUNCE, os::posix::convert_to_pthread_priority(), handle_, embutil::is_aligned(), NULL, p, PTHREAD_STACK_MIN, r, embvm::thread::ready, state_, and thread_func().
|
noexcept |
Default destructor, cleans up thread on deletion.
References embvm::thread::completed, join(), state_, terminate(), and embvm::thread::terminated.
|
inlinenoexcept |
References handle_.
|
inlinefinalvirtualnoexcept |
|
inlinefinalvirtualnoexcept |
View the thread's name.
Storage for the thread name is implementation defined. For example, the name may be stored in the RTOS memory, or it may require internal object storage.
Implements embvm::VirtualThread.
References name_.
|
inlinefinalvirtualnoexcept |
Get the native handle for the thread.
If custom extensions or behaviors are needed, the thread handle can be retrieved and manipulated directly.
void*. The user must cast appropriately. Implements embvm::VirtualThread.
References handle_.
|
inlinefinalvirtualnoexcept |
Start the thread, if it is not auto-started.
Implements embvm::VirtualThread.
|
inlinefinalvirtualnoexcept |
Get the thread state.
Implements embvm::VirtualThread.
References state_.
|
inlinefinalvirtualnoexcept |
Terminate a running thread.
Implements embvm::VirtualThread.
References assert, handle_, r, state_, and embvm::thread::terminated.
Referenced by ~Thread().
|
inlineprivatenoexcept |
Thread handling wrapper to support thread canceling.
We wrap the thread to enable canceling, and so we can gracefully tell if the thread has completed successfully
References arg_, assert, embvm::thread::completed, embvm::thread::executing, func_, r, and state_.
Referenced by Thread().
|
private |
Thread input arguments.
Referenced by thread_func().
|
private |
The functor which will be invokd by the thread.
Referenced by thread_func().
|
private |
The pthread handle corresponding to this thread instance.
Referenced by detach(), join(), native_handle(), terminate(), and Thread().
|
private |
THe name of this thread instance.
Referenced by name().
|
private |
Referenced by state(), terminate(), Thread(), thread_func(), and ~Thread().
|
strong |
|
noexcept |
Convert between framework thread priorities and PThread priorities.
References os::posix::aboveNormal, embvm::thread::aboveNormal, assert, os::posix::belowNormal, embvm::thread::belowNormal, os::posix::high, embvm::thread::high, os::posix::idle, embvm::thread::idle, os::posix::interrupt, embvm::thread::interrupt, os::posix::low, embvm::thread::low, os::posix::lowest, embvm::thread::lowest, os::posix::normal, embvm::thread::normal, p, os::posix::panic, embvm::thread::panic, os::posix::realtime, embvm::thread::realtime, os::posix::veryHigh, and embvm::thread::veryHigh.
Referenced by os::posix::Thread::Thread().
1.8.15