mirror of
https://github.com/matrix-construct/construct
synced 2025-02-18 01:30:12 +01:00
ircd::ctx::mutex: Add deadlock assertion on lock.
This commit is contained in:
parent
fcb4f6c5f4
commit
87fd0f04ea
1 changed files with 16 additions and 0 deletions
|
@ -26,6 +26,8 @@ class ircd::ctx::mutex
|
|||
dock q;
|
||||
bool m;
|
||||
|
||||
void deadlock_assertion() const noexcept;
|
||||
|
||||
public:
|
||||
bool locked() const noexcept;
|
||||
size_t waiting() const noexcept;
|
||||
|
@ -92,6 +94,8 @@ ircd::ctx::mutex::unlock()
|
|||
inline void
|
||||
ircd::ctx::mutex::lock()
|
||||
{
|
||||
deadlock_assertion();
|
||||
|
||||
q.wait([this]
|
||||
{
|
||||
return !locked();
|
||||
|
@ -111,6 +115,8 @@ template<class time_point>
|
|||
bool
|
||||
ircd::ctx::mutex::try_lock_until(const time_point &tp)
|
||||
{
|
||||
deadlock_assertion();
|
||||
|
||||
const bool success
|
||||
{
|
||||
q.wait_until(tp, [this]
|
||||
|
@ -129,6 +135,8 @@ inline bool
|
|||
ircd::ctx::mutex::try_lock()
|
||||
noexcept
|
||||
{
|
||||
deadlock_assertion();
|
||||
|
||||
if(locked())
|
||||
return false;
|
||||
|
||||
|
@ -156,3 +164,11 @@ const noexcept
|
|||
{
|
||||
return m;
|
||||
}
|
||||
|
||||
inline void
|
||||
__attribute__((always_inline, artificial))
|
||||
ircd::ctx::mutex::deadlock_assertion()
|
||||
const noexcept
|
||||
{
|
||||
assert(!locked() || !waiting(cur()));
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue