| 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 1 taken 5400 times.
✓ Branch 2 taken 75 times.
✓ Branch 4 taken 75 times.
|
5475 | Mutex::Mutex() : m_handle_storage(), m_delegate(*MutexInterface::getDelegate(m_handle_storage)) { |
| 11 | 75 | FW_ASSERT(&this->m_delegate == reinterpret_cast<MutexInterface*>(&this->m_handle_storage[0])); | |
| 12 | 75 | } | |
| 13 | |||
| 14 | 150 | Mutex::~Mutex() { | |
| 15 | 150 | FW_ASSERT(&this->m_delegate == reinterpret_cast<MutexInterface*>(&this->m_handle_storage[0])); | |
| 16 | 150 | m_delegate.~MutexInterface(); | |
| 17 | 150 | } | |
| 18 | |||
| 19 | 4766 | MutexHandle* Mutex::getHandle() { | |
| 20 | 4766 | FW_ASSERT(&this->m_delegate == reinterpret_cast<MutexInterface*>(&this->m_handle_storage[0])); | |
| 21 | 4766 | return this->m_delegate.getHandle(); | |
| 22 | } | ||
| 23 | |||
| 24 | 41099 | Mutex::Status Mutex::take() { | |
| 25 | 41099 | FW_ASSERT(&this->m_delegate == reinterpret_cast<MutexInterface*>(&this->m_handle_storage[0])); | |
| 26 | 41099 | return this->m_delegate.take(); | |
| 27 | } | ||
| 28 | |||
| 29 | 41013 | Mutex::Status Mutex::release() { | |
| 30 | 41013 | FW_ASSERT(&this->m_delegate == reinterpret_cast<MutexInterface*>(&this->m_handle_storage[0])); | |
| 31 | 41013 | return this->m_delegate.release(); | |
| 32 | } | ||
| 33 | |||
| 34 | 41108 | void Mutex::lock() { | |
| 35 | 41108 | FW_ASSERT(&this->m_delegate == reinterpret_cast<MutexInterface*>(&this->m_handle_storage[0])); | |
| 36 | 41108 | Mutex::Status status = this->take(); | |
| 37 | 41163 | FW_ASSERT(status == Mutex::Status::OP_OK, | |
| 38 | static_cast<FwAssertArgType>(reinterpret_cast<PlatformPointerCastType>(this)), status); | ||
| 39 | 41163 | } | |
| 40 | |||
| 41 | 41016 | void Mutex::unLock() { | |
| 42 | 41016 | FW_ASSERT(&this->m_delegate == reinterpret_cast<MutexInterface*>(&this->m_handle_storage[0])); | |
| 43 | 41016 | Mutex::Status status = this->release(); | |
| 44 | 41156 | FW_ASSERT(status == Mutex::Status::OP_OK, | |
| 45 | static_cast<FwAssertArgType>(reinterpret_cast<PlatformPointerCastType>(this)), status); | ||
| 46 | 41156 | } | |
| 47 | |||
| 48 | 26992 | ScopeLock::ScopeLock(Mutex& mutex) : m_mutex(mutex) { | |
| 49 | 26992 | this->m_mutex.lock(); | |
| 50 | 27021 | } | |
| 51 | |||
| 52 | 26924 | ScopeLock::~ScopeLock() { | |
| 53 | 26924 | this->m_mutex.unLock(); | |
| 54 | 27057 | } | |
| 55 | |||
| 56 | } // namespace Os | ||
| 57 |