| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | // ====================================================================== | ||
| 2 | // \title Os/Mutex.cpp | ||
| 3 | // \brief common function implementation for Os::Mutex | ||
| 4 | // ====================================================================== | ||
| 5 | #include <Fw/Types/Assert.hpp> | ||
| 6 | #include <Os/Mutex.hpp> | ||
| 7 | |||
| 8 | namespace Os { | ||
| 9 | |||
| 10 |
3/3✓ Branch 10 taken 618552 times.
✓ Branch 11 taken 8591 times.
✓ Branch 17 taken 8591 times.
|
627143 | Mutex::Mutex() : m_handle_storage(), m_delegate(*MutexInterface::getDelegate(m_handle_storage)) { |
| 11 | 8591 | FW_ASSERT(&this->m_delegate == reinterpret_cast<MutexInterface*>(&this->m_handle_storage[0])); | |
| 12 | 8591 | } | |
| 13 | |||
| 14 | 17184 | Mutex::~Mutex() { | |
| 15 | 17182 | FW_ASSERT(&this->m_delegate == reinterpret_cast<MutexInterface*>(&this->m_handle_storage[0])); | |
| 16 | 17182 | m_delegate.~MutexInterface(); | |
| 17 | 17184 | } | |
| 18 | |||
| 19 | 13 | MutexHandle* Mutex::getHandle() { | |
| 20 | 13 | FW_ASSERT(&this->m_delegate == reinterpret_cast<MutexInterface*>(&this->m_handle_storage[0])); | |
| 21 | 13 | return this->m_delegate.getHandle(); | |
| 22 | } | ||
| 23 | |||
| 24 | 14561375 | Mutex::Status Mutex::take() { | |
| 25 | 14561375 | FW_ASSERT(&this->m_delegate == reinterpret_cast<MutexInterface*>(&this->m_handle_storage[0])); | |
| 26 | 20496739 | return this->m_delegate.take(); | |
| 27 | } | ||
| 28 | |||
| 29 | 17253973 | Mutex::Status Mutex::release() { | |
| 30 | 17253973 | FW_ASSERT(&this->m_delegate == reinterpret_cast<MutexInterface*>(&this->m_handle_storage[0])); | |
| 31 | 20095171 | return this->m_delegate.release(); | |
| 32 | } | ||
| 33 | |||
| 34 | 13643590 | void Mutex::lock() { | |
| 35 | 13643590 | FW_ASSERT(&this->m_delegate == reinterpret_cast<MutexInterface*>(&this->m_handle_storage[0])); | |
| 36 | 19094346 | Mutex::Status status = this->take(); | |
| 37 | 13916568 | FW_ASSERT(status == Mutex::Status::OP_OK, | |
| 38 | static_cast<FwAssertArgType>(reinterpret_cast<PlatformPointerCastType>(this)), status); | ||
| 39 | 13916568 | } | |
| 40 | |||
| 41 | 16790101 | void Mutex::unLock() { | |
| 42 | 16790101 | FW_ASSERT(&this->m_delegate == reinterpret_cast<MutexInterface*>(&this->m_handle_storage[0])); | |
| 43 | 19330426 | Mutex::Status status = this->release(); | |
| 44 | 14222868 | FW_ASSERT(status == Mutex::Status::OP_OK, | |
| 45 | static_cast<FwAssertArgType>(reinterpret_cast<PlatformPointerCastType>(this)), status); | ||
| 46 | 14222868 | } | |
| 47 | |||
| 48 | 580232 | ScopeLock::ScopeLock(Mutex& mutex) : m_mutex(mutex) { | |
| 49 | 580232 | this->m_mutex.lock(); | |
| 50 | 580230 | } | |
| 51 | |||
| 52 | 580232 | ScopeLock::~ScopeLock() { | |
| 53 | 580232 | this->m_mutex.unLock(); | |
| 54 | 580230 | } | |
| 55 | |||
| 56 | } // namespace Os | ||
| 57 |