mirror of
https://github.com/matrix-construct/construct
synced 2025-03-14 05:20:17 +01:00
ircd::ctx: Enforce semantics in mutex / shared_mutex; assertion related.
This commit is contained in:
parent
b93b294d7b
commit
6fc8de8587
4 changed files with 51 additions and 14 deletions
|
@ -53,9 +53,6 @@ class ircd::ctx::dock
|
|||
void notify_all() noexcept;
|
||||
void notify_one() noexcept;
|
||||
void notify() noexcept;
|
||||
|
||||
dock() = default;
|
||||
~dock() noexcept;
|
||||
};
|
||||
|
||||
enum class ircd::ctx::cv_status
|
||||
|
@ -63,13 +60,6 @@ enum class ircd::ctx::cv_status
|
|||
no_timeout, timeout
|
||||
};
|
||||
|
||||
inline
|
||||
ircd::ctx::dock::~dock()
|
||||
noexcept
|
||||
{
|
||||
assert(q.empty());
|
||||
}
|
||||
|
||||
/// Wake up the next context waiting on the dock
|
||||
///
|
||||
/// Unlike notify_one(), the next context in the queue is repositioned in the
|
||||
|
|
|
@ -116,7 +116,7 @@ inline
|
|||
ircd::ctx::list::~list()
|
||||
noexcept
|
||||
{
|
||||
assert(!head && !tail);
|
||||
assert(empty());
|
||||
}
|
||||
|
||||
inline ircd::ctx::ctx *
|
||||
|
@ -148,6 +148,7 @@ inline bool
|
|||
ircd::ctx::list::empty()
|
||||
const
|
||||
{
|
||||
assert((!head && !tail) || (head && tail));
|
||||
return !head;
|
||||
}
|
||||
|
||||
|
|
|
@ -48,21 +48,42 @@ class ircd::ctx::mutex
|
|||
void unlock();
|
||||
|
||||
mutex();
|
||||
mutex(mutex &&) noexcept;
|
||||
mutex(const mutex &) = delete;
|
||||
mutex &operator=(mutex &&) noexcept;
|
||||
mutex &operator=(const mutex &) = delete;
|
||||
~mutex() noexcept;
|
||||
};
|
||||
|
||||
inline
|
||||
ircd::ctx::mutex::mutex():
|
||||
m(false)
|
||||
ircd::ctx::mutex::mutex()
|
||||
:m{false}
|
||||
{
|
||||
}
|
||||
|
||||
inline
|
||||
ircd::ctx::mutex::mutex(mutex &&o)
|
||||
noexcept
|
||||
:m{std::move(o.m)}
|
||||
{
|
||||
o.m = false;
|
||||
}
|
||||
|
||||
inline
|
||||
ircd::ctx::mutex &
|
||||
ircd::ctx::mutex::operator=(mutex &&o)
|
||||
noexcept
|
||||
{
|
||||
this->~mutex();
|
||||
std::swap(m, o.m);
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline
|
||||
ircd::ctx::mutex::~mutex()
|
||||
noexcept
|
||||
{
|
||||
assert(!m);
|
||||
assert(q.empty());
|
||||
}
|
||||
|
||||
inline void
|
||||
|
|
|
@ -73,6 +73,10 @@ class ircd::ctx::shared_mutex
|
|||
void unlock_upgrade_and_lock_shared();
|
||||
|
||||
shared_mutex();
|
||||
shared_mutex(shared_mutex &&) noexcept;
|
||||
shared_mutex(const shared_mutex &) = delete;
|
||||
shared_mutex &operator=(shared_mutex &&) noexcept;
|
||||
shared_mutex &operator=(const shared_mutex &) = delete;
|
||||
~shared_mutex() noexcept;
|
||||
};
|
||||
|
||||
|
@ -83,6 +87,27 @@ ircd::ctx::shared_mutex::shared_mutex()
|
|||
{
|
||||
}
|
||||
|
||||
inline
|
||||
ircd::ctx::shared_mutex::shared_mutex(shared_mutex &&o)
|
||||
noexcept
|
||||
:u{std::move(o.u)}
|
||||
,s{std::move(o.s)}
|
||||
{
|
||||
o.u = false;
|
||||
o.s = 0;
|
||||
}
|
||||
|
||||
inline
|
||||
ircd::ctx::shared_mutex &
|
||||
ircd::ctx::shared_mutex::operator=(shared_mutex &&o)
|
||||
noexcept
|
||||
{
|
||||
this->~shared_mutex();
|
||||
std::swap(u, o.u);
|
||||
std::swap(s, o.s);
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline
|
||||
ircd::ctx::shared_mutex::~shared_mutex()
|
||||
noexcept
|
||||
|
|
Loading…
Add table
Reference in a new issue