A lock implementation for Valdi::RecursiveMutex which uses a thread local storage to track all the locks acquired so that it can unlock them. */
| 11 | /** |
| 12 | A lock implementation for Valdi::RecursiveMutex which uses a thread local storage |
| 13 | to track all the locks acquired so that it can unlock them. |
| 14 | */ |
| 15 | class TrackedLock { |
| 16 | public: |
| 17 | TrackedLock(); |
| 18 | TrackedLock(RecursiveMutex& mutex); |
| 19 | /** |
| 20 | Try to acquire the mutex until the deadline, polling instead of blocking, so the calling |
| 21 | thread can never park on the mutex indefinitely. A deadline in the past attempts exactly |
| 22 | once. Check owns() for the outcome. |
| 23 | */ |
| 24 | TrackedLock(RecursiveMutex& mutex, const std::chrono::steady_clock::time_point& deadline); |
| 25 | TrackedLock(TrackedLock&& other) noexcept; |
| 26 | |
| 27 | ~TrackedLock(); |
| 28 | |
| 29 | void lock(); |
| 30 | void unlock(); |
| 31 | |
| 32 | bool owns() const; |
| 33 | |
| 34 | TrackedLock& operator=(TrackedLock&& other) noexcept; |
| 35 | |
| 36 | private: |
| 37 | friend DropAllTrackedLocks; |
| 38 | |
| 39 | TrackedLock* _parent = nullptr; |
| 40 | RecursiveMutex* _mutex = nullptr; |
| 41 | bool _owns = false; |
no outgoing calls
no test coverage detected