F´ Flight Software - C/C++ Documentation
devel
A framework for building embedded system applications to NASA flight quality standards.
|
LockGuard
is a RAII-wrapper around Os::Mutex, essentially allowing scoped lock and unlock. It works the same way as C++11 std::lock_guard
.
If a section of code has only basic lock/unlock requirements, LockGuard
ensures that early exits from that section will always release the lock.
LockGuard is a class that can be included and instantiated with an associated Os::Mutex reference.
The moment LockGuard is instantiated, it will attempt to lock the mutex that's given to it.
LockGuard is meant for scoped use, i.e. it should always live on a function call stack. It allows a sometimes more convenient way of using mutex, e.g. you want this entire function locked from this point forward, and early returns should be guaranteed to release the lock.
It can also be used for a smaller scope
```cpp if (xyz) { LockGuard _lock(mutex); ... } // will unlock mutex