| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | // ====================================================================== | ||
| 2 | // \title Os/Stub/Mutex.hpp | ||
| 3 | // \brief stub definitions for Os::Mutex | ||
| 4 | // ====================================================================== | ||
| 5 | #include "Os/Mutex.hpp" | ||
| 6 | |||
| 7 | #include <atomic> | ||
| 8 | |||
| 9 | #ifndef OS_STUB_MUTEX_HPP | ||
| 10 | #define OS_STUB_MUTEX_HPP | ||
| 11 | namespace Os { | ||
| 12 | namespace Stub { | ||
| 13 | namespace Mutex { | ||
| 14 | |||
| 15 | struct StubMutexHandle : public MutexHandle { | ||
| 16 | //! True if the mutex has been acquired without being released. | ||
| 17 | std::atomic<bool> m_mutex_taken = {false}; | ||
| 18 | }; | ||
| 19 | |||
| 20 | //! \brief Nonblocking stub implementation of Os::Mutex | ||
| 21 | //! | ||
| 22 | //! Stub implementation of `MutexInterface` for use as a delegate class. | ||
| 23 | //! | ||
| 24 | //! This mutex will never block, which allows it to be used on any platform without OS dependencies. | ||
| 25 | //! It is unsuitable for use in environments where threads need to contend over mutexes. | ||
| 26 | //! However, it is appropriate for use in environments with multiple threads that are not intended to | ||
| 27 | //! contend over mutexes, and where contention would indicate a coding defect worthy of an assertion. | ||
| 28 | //! | ||
| 29 | class StubMutex : public MutexInterface { | ||
| 30 | public: | ||
| 31 | //! \brief constructor | ||
| 32 | //! | ||
| 33 | 4 | StubMutex() = default; | |
| 34 | |||
| 35 | //! \brief destructor | ||
| 36 | //! | ||
| 37 | 8 | ~StubMutex() override = default; | |
| 38 | |||
| 39 | //! \brief return the underlying mutex handle (implementation specific) | ||
| 40 | //! \return internal mutex handle representation | ||
| 41 | MutexHandle* getHandle() override; | ||
| 42 | |||
| 43 | Status take() override; //!< lock the mutex and get return status | ||
| 44 | Status release() override; //!< unlock the mutex and get return status | ||
| 45 | |||
| 46 | private: | ||
| 47 | //! Handle for StubMutex | ||
| 48 | StubMutexHandle m_handle; | ||
| 49 | }; | ||
| 50 | |||
| 51 | } // namespace Mutex | ||
| 52 | } // namespace Stub | ||
| 53 | } // namespace Os | ||
| 54 | #endif // OS_STUB_MUTEX_HPP | ||
| 55 |