mirror of
https://github.com/matrix-construct/construct
synced 2024-09-29 20:28:52 +02: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;
|
dock q;
|
||||||
bool m;
|
bool m;
|
||||||
|
|
||||||
|
void deadlock_assertion() const noexcept;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
bool locked() const noexcept;
|
bool locked() const noexcept;
|
||||||
size_t waiting() const noexcept;
|
size_t waiting() const noexcept;
|
||||||
|
@ -92,6 +94,8 @@ ircd::ctx::mutex::unlock()
|
||||||
inline void
|
inline void
|
||||||
ircd::ctx::mutex::lock()
|
ircd::ctx::mutex::lock()
|
||||||
{
|
{
|
||||||
|
deadlock_assertion();
|
||||||
|
|
||||||
q.wait([this]
|
q.wait([this]
|
||||||
{
|
{
|
||||||
return !locked();
|
return !locked();
|
||||||
|
@ -111,6 +115,8 @@ template<class time_point>
|
||||||
bool
|
bool
|
||||||
ircd::ctx::mutex::try_lock_until(const time_point &tp)
|
ircd::ctx::mutex::try_lock_until(const time_point &tp)
|
||||||
{
|
{
|
||||||
|
deadlock_assertion();
|
||||||
|
|
||||||
const bool success
|
const bool success
|
||||||
{
|
{
|
||||||
q.wait_until(tp, [this]
|
q.wait_until(tp, [this]
|
||||||
|
@ -129,6 +135,8 @@ inline bool
|
||||||
ircd::ctx::mutex::try_lock()
|
ircd::ctx::mutex::try_lock()
|
||||||
noexcept
|
noexcept
|
||||||
{
|
{
|
||||||
|
deadlock_assertion();
|
||||||
|
|
||||||
if(locked())
|
if(locked())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
@ -156,3 +164,11 @@ const noexcept
|
||||||
{
|
{
|
||||||
return m;
|
return m;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline void
|
||||||
|
__attribute__((always_inline, artificial))
|
||||||
|
ircd::ctx::mutex::deadlock_assertion()
|
||||||
|
const noexcept
|
||||||
|
{
|
||||||
|
assert(!locked() || !waiting(cur()));
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue