0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-11-25 16:22:35 +01:00

ircd::ctx: Use context pointer for mutex/shared_mutex acquisition state.

This commit is contained in:
Jason Volk 2020-05-01 13:32:49 -07:00
parent d72124f7c6
commit 926795f01a
2 changed files with 25 additions and 25 deletions

View file

@ -24,7 +24,7 @@ namespace ircd::ctx
struct ircd::ctx::mutex
{
dock q;
bool m;
ctx *m;
void deadlock_assertion() const noexcept;
@ -51,7 +51,7 @@ struct ircd::ctx::mutex
inline
ircd::ctx::mutex::mutex()
noexcept
:m{false}
:m{nullptr}
{
}
@ -61,7 +61,7 @@ noexcept
:q{std::move(o.q)}
,m{std::move(o.m)}
{
o.m = false;
o.m = nullptr;
}
inline
@ -72,7 +72,7 @@ noexcept
this->~mutex();
q = std::move(o.q);
m = std::move(o.m);
o.m = false;
o.m = nullptr;
return *this;
}
@ -86,8 +86,8 @@ noexcept
inline void
ircd::ctx::mutex::unlock()
{
assert(m);
m = false;
assert(m == current);
m = nullptr;
q.notify_one();
}
@ -101,7 +101,7 @@ ircd::ctx::mutex::lock()
return !locked();
});
m = true;
m = current;
}
template<class duration>
@ -126,7 +126,7 @@ ircd::ctx::mutex::try_lock_until(const time_point &tp)
};
if(likely(success))
m = true;
m = current;
return success;
}
@ -140,7 +140,7 @@ noexcept
if(locked())
return false;
m = true;
m = current;
return true;
}
@ -170,5 +170,5 @@ __attribute__((always_inline, artificial))
ircd::ctx::mutex::deadlock_assertion()
const noexcept
{
assert(!locked() || !waiting(cur()));
assert(!locked() || m != current);
}

View file

@ -19,8 +19,8 @@ namespace ircd::ctx
struct ircd::ctx::shared_mutex
{
dock q;
ctx *u;
ssize_t s;
bool u;
public:
bool unique() const;
@ -78,8 +78,8 @@ struct ircd::ctx::shared_mutex
inline
ircd::ctx::shared_mutex::shared_mutex()
:s{0}
,u{false}
:u{nullptr}
,s{0}
{
}
@ -87,11 +87,11 @@ inline
ircd::ctx::shared_mutex::shared_mutex(shared_mutex &&o)
noexcept
:q{std::move(o.q)}
,s{std::move(o.s)}
,u{std::move(o.u)}
,s{std::move(o.s)}
{
o.s = 0;
o.u = false;
o.u = nullptr;
}
inline
@ -101,10 +101,10 @@ noexcept
{
this->~shared_mutex();
q = std::move(o.q);
s = std::move(o.s);
u = std::move(o.u);
s = std::move(o.s);
o.s = 0;
o.u = false;
o.u = nullptr;
return *this;
}
@ -121,7 +121,7 @@ inline void
ircd::ctx::shared_mutex::unlock_upgrade_and_lock_shared()
{
++s;
u = false;
u = nullptr;
q.notify_one();
}
@ -129,14 +129,14 @@ inline void
ircd::ctx::shared_mutex::unlock_upgrade_and_lock()
{
s = std::numeric_limits<decltype(s)>::min();
u = false;
u = nullptr;
}
inline void
ircd::ctx::shared_mutex::unlock_and_lock_upgrade()
{
s = 0;
u = true;
u = current;
}
inline void
@ -149,7 +149,7 @@ ircd::ctx::shared_mutex::unlock_and_lock_shared()
inline void
ircd::ctx::shared_mutex::unlock_upgrade()
{
u = false;
u = nullptr;
q.notify_one();
}
@ -218,7 +218,7 @@ ircd::ctx::shared_mutex::try_unlock_upgrade_and_lock()
if(!try_lock())
return false;
u = false;
u = nullptr;
return true;
}
@ -250,7 +250,7 @@ ircd::ctx::shared_mutex::lock_upgrade()
return can_lock_upgrade();
});
u = true;
u = current;
}
inline void
@ -309,7 +309,7 @@ ircd::ctx::shared_mutex::try_lock_upgrade_until(time_point&& tp)
};
if(can_lock_upgrade)
u = true;
u = current;
return can_lock_upgrade;
}
@ -355,7 +355,7 @@ ircd::ctx::shared_mutex::try_lock_upgrade()
{
if(can_lock_upgrade())
{
u = true;
u = current;
return true;
}
else return false;