2018-02-04 03:22:01 +01:00
|
|
|
// Matrix Construct
|
|
|
|
//
|
|
|
|
// Copyright (C) Matrix Construct Developers, Authors & Contributors
|
|
|
|
// Copyright (C) 2016-2018 Jason Volk <jason@zemos.net>
|
|
|
|
//
|
|
|
|
// Permission to use, copy, modify, and/or distribute this software for any
|
|
|
|
// purpose with or without fee is hereby granted, provided that the above
|
|
|
|
// copyright notice and this permission notice is present in all copies. The
|
|
|
|
// full license for this software is available in the LICENSE file.
|
2017-09-28 09:06:00 +02:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
#define HAVE_IRCD_CTX_SHARED_MUTEX_H
|
|
|
|
|
|
|
|
namespace ircd::ctx
|
|
|
|
{
|
|
|
|
class shared_mutex;
|
|
|
|
}
|
|
|
|
|
2020-02-25 01:44:15 +01:00
|
|
|
struct ircd::ctx::shared_mutex
|
2017-09-28 09:06:00 +02:00
|
|
|
{
|
2018-11-14 03:18:38 +01:00
|
|
|
dock q;
|
2020-05-01 22:32:49 +02:00
|
|
|
ctx *u;
|
2018-11-16 03:44:54 +01:00
|
|
|
ssize_t s;
|
2017-09-28 09:06:00 +02:00
|
|
|
|
|
|
|
public:
|
2018-08-27 03:01:12 +02:00
|
|
|
bool unique() const;
|
|
|
|
bool upgrade() const;
|
2018-03-27 03:47:29 +02:00
|
|
|
size_t shares() const;
|
2018-03-06 10:09:37 +01:00
|
|
|
size_t waiting() const;
|
|
|
|
|
2018-11-14 03:18:38 +01:00
|
|
|
bool can_lock() const;
|
|
|
|
bool can_lock_shared() const;
|
|
|
|
bool can_lock_upgrade() const;
|
|
|
|
|
2017-09-28 09:06:00 +02:00
|
|
|
bool try_lock();
|
|
|
|
bool try_lock_shared();
|
|
|
|
bool try_lock_upgrade();
|
|
|
|
|
|
|
|
template<class time_point> bool try_lock_until(time_point&&);
|
|
|
|
template<class time_point> bool try_lock_shared_until(time_point&&);
|
|
|
|
template<class time_point> bool try_lock_upgrade_until(time_point&&);
|
|
|
|
|
|
|
|
template<class duration> bool try_lock_for(duration&&);
|
|
|
|
template<class duration> bool try_lock_shared_for(duration&&);
|
|
|
|
template<class duration> bool try_lock_upgrade_for(duration&&);
|
|
|
|
|
|
|
|
void lock();
|
|
|
|
void lock_shared();
|
|
|
|
void lock_upgrade();
|
|
|
|
|
|
|
|
bool try_unlock_shared_and_lock();
|
|
|
|
bool try_unlock_shared_and_lock_upgrade();
|
|
|
|
bool try_unlock_upgrade_and_lock();
|
|
|
|
|
|
|
|
template<class time_point> bool try_unlock_shared_and_lock_until(time_point&&);
|
|
|
|
template<class time_point> bool try_unlock_shared_and_lock_upgrade_until(time_point&&);
|
|
|
|
template<class time_point> bool try_unlock_upgrade_and_lock_until(time_point&&);
|
|
|
|
|
|
|
|
template<class duration> bool try_unlock_shared_and_lock_for(duration&&);
|
|
|
|
template<class duration> bool try_unlock_shared_and_lock_upgrade_for(duration&&);
|
|
|
|
template<class duration> bool try_unlock_upgrade_and_lock_for(duration&&);
|
|
|
|
|
|
|
|
void unlock();
|
|
|
|
void unlock_shared();
|
|
|
|
void unlock_upgrade();
|
|
|
|
void unlock_and_lock_shared();
|
|
|
|
void unlock_and_lock_upgrade();
|
|
|
|
void unlock_upgrade_and_lock();
|
|
|
|
void unlock_upgrade_and_lock_shared();
|
|
|
|
|
|
|
|
shared_mutex();
|
2018-01-17 11:58:57 +01:00
|
|
|
shared_mutex(shared_mutex &&) noexcept;
|
|
|
|
shared_mutex(const shared_mutex &) = delete;
|
|
|
|
shared_mutex &operator=(shared_mutex &&) noexcept;
|
|
|
|
shared_mutex &operator=(const shared_mutex &) = delete;
|
2017-09-28 09:06:00 +02:00
|
|
|
~shared_mutex() noexcept;
|
|
|
|
};
|
|
|
|
|
|
|
|
inline
|
|
|
|
ircd::ctx::shared_mutex::shared_mutex()
|
2020-05-01 22:32:49 +02:00
|
|
|
:u{nullptr}
|
|
|
|
,s{0}
|
2017-09-28 09:06:00 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2018-01-17 11:58:57 +01:00
|
|
|
inline
|
|
|
|
ircd::ctx::shared_mutex::shared_mutex(shared_mutex &&o)
|
|
|
|
noexcept
|
2018-11-16 03:44:54 +01:00
|
|
|
:q{std::move(o.q)}
|
|
|
|
,u{std::move(o.u)}
|
2020-05-01 22:32:49 +02:00
|
|
|
,s{std::move(o.s)}
|
2018-01-17 11:58:57 +01:00
|
|
|
{
|
|
|
|
o.s = 0;
|
2020-05-01 22:32:49 +02:00
|
|
|
o.u = nullptr;
|
2018-01-17 11:58:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
inline
|
|
|
|
ircd::ctx::shared_mutex &
|
|
|
|
ircd::ctx::shared_mutex::operator=(shared_mutex &&o)
|
|
|
|
noexcept
|
|
|
|
{
|
|
|
|
this->~shared_mutex();
|
2018-11-14 03:18:38 +01:00
|
|
|
q = std::move(o.q);
|
2018-11-16 03:44:54 +01:00
|
|
|
u = std::move(o.u);
|
2020-05-01 22:32:49 +02:00
|
|
|
s = std::move(o.s);
|
2018-11-14 02:45:08 +01:00
|
|
|
o.s = 0;
|
2020-05-01 22:32:49 +02:00
|
|
|
o.u = nullptr;
|
2018-01-17 11:58:57 +01:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2017-09-28 09:06:00 +02:00
|
|
|
inline
|
|
|
|
ircd::ctx::shared_mutex::~shared_mutex()
|
|
|
|
noexcept
|
|
|
|
{
|
|
|
|
assert(!u);
|
|
|
|
assert(s == 0);
|
|
|
|
assert(q.empty());
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void
|
|
|
|
ircd::ctx::shared_mutex::unlock_upgrade_and_lock_shared()
|
|
|
|
{
|
2020-05-01 23:08:29 +02:00
|
|
|
assert(u == current);
|
|
|
|
assert(s >= 0);
|
|
|
|
|
2020-05-01 22:32:49 +02:00
|
|
|
u = nullptr;
|
2020-05-01 23:08:29 +02:00
|
|
|
++s;
|
2018-11-14 03:18:38 +01:00
|
|
|
q.notify_one();
|
2017-09-28 09:06:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
inline void
|
|
|
|
ircd::ctx::shared_mutex::unlock_upgrade_and_lock()
|
|
|
|
{
|
2020-05-02 00:16:37 +02:00
|
|
|
assert(current);
|
2020-05-01 23:08:29 +02:00
|
|
|
assert(u == current);
|
|
|
|
|
|
|
|
q.wait([this]
|
|
|
|
{
|
|
|
|
return can_lock();
|
|
|
|
});
|
|
|
|
|
2017-09-28 09:06:00 +02:00
|
|
|
s = std::numeric_limits<decltype(s)>::min();
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void
|
|
|
|
ircd::ctx::shared_mutex::unlock_and_lock_upgrade()
|
|
|
|
{
|
2020-05-02 00:16:37 +02:00
|
|
|
assert(current);
|
2020-05-01 23:08:29 +02:00
|
|
|
assert(u == current);
|
|
|
|
assert(s == std::numeric_limits<decltype(s)>::min());
|
|
|
|
|
2017-09-28 09:06:00 +02:00
|
|
|
s = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void
|
|
|
|
ircd::ctx::shared_mutex::unlock_and_lock_shared()
|
|
|
|
{
|
2020-05-02 00:16:37 +02:00
|
|
|
assert(current);
|
2020-05-01 23:08:29 +02:00
|
|
|
assert(u == current);
|
|
|
|
assert(s == std::numeric_limits<decltype(s)>::min());
|
|
|
|
|
2017-09-28 09:06:00 +02:00
|
|
|
s = 1;
|
2018-11-14 03:18:38 +01:00
|
|
|
q.notify_one();
|
2017-09-28 09:06:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
inline void
|
|
|
|
ircd::ctx::shared_mutex::unlock_upgrade()
|
|
|
|
{
|
2020-05-02 00:16:37 +02:00
|
|
|
assert(current);
|
2020-05-01 23:08:29 +02:00
|
|
|
assert(u == current);
|
|
|
|
|
2020-05-01 22:32:49 +02:00
|
|
|
u = nullptr;
|
2018-11-14 03:18:38 +01:00
|
|
|
q.notify_one();
|
2017-09-28 09:06:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
inline void
|
|
|
|
ircd::ctx::shared_mutex::unlock_shared()
|
|
|
|
{
|
2020-05-01 23:08:29 +02:00
|
|
|
assert(s > 0);
|
|
|
|
|
2017-09-28 09:06:00 +02:00
|
|
|
--s;
|
2018-11-14 03:18:38 +01:00
|
|
|
q.notify_one();
|
2017-09-28 09:06:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
inline void
|
|
|
|
ircd::ctx::shared_mutex::unlock()
|
|
|
|
{
|
2020-05-02 00:16:37 +02:00
|
|
|
assert(current);
|
2020-05-01 23:08:29 +02:00
|
|
|
assert(u == current);
|
|
|
|
assert(s == std::numeric_limits<decltype(s)>::min());
|
|
|
|
|
2017-09-28 09:06:00 +02:00
|
|
|
s = 0;
|
2018-11-14 03:18:38 +01:00
|
|
|
q.notify_all();
|
2017-09-28 09:06:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
template<class duration>
|
2020-10-29 08:08:06 +01:00
|
|
|
inline bool
|
2017-09-28 09:06:00 +02:00
|
|
|
ircd::ctx::shared_mutex::try_unlock_upgrade_and_lock_for(duration&& d)
|
|
|
|
{
|
2019-09-23 05:02:23 +02:00
|
|
|
return try_unlock_upgrade_and_lock_until(system_clock::now() + d);
|
2017-09-28 09:06:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
template<class duration>
|
2020-10-29 08:08:06 +01:00
|
|
|
inline bool
|
2017-09-28 09:06:00 +02:00
|
|
|
ircd::ctx::shared_mutex::try_unlock_shared_and_lock_upgrade_for(duration&& d)
|
|
|
|
{
|
2019-09-23 05:02:23 +02:00
|
|
|
return try_unlock_shared_and_lock_upgrade_until(system_clock::now() + d);
|
2017-09-28 09:06:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
template<class duration>
|
2020-10-29 08:08:06 +01:00
|
|
|
inline bool
|
2017-09-28 09:06:00 +02:00
|
|
|
ircd::ctx::shared_mutex::try_unlock_shared_and_lock_for(duration&& d)
|
|
|
|
{
|
2019-09-23 05:02:23 +02:00
|
|
|
return try_unlock_shared_and_lock_until(system_clock::now() + d);
|
2017-09-28 09:06:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
template<class time_point>
|
2020-10-29 08:08:06 +01:00
|
|
|
inline bool
|
2017-09-28 09:06:00 +02:00
|
|
|
ircd::ctx::shared_mutex::try_unlock_upgrade_and_lock_until(time_point&& tp)
|
|
|
|
{
|
|
|
|
assert(0);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
template<class time_point>
|
2020-10-29 08:08:06 +01:00
|
|
|
inline bool
|
2017-09-28 09:06:00 +02:00
|
|
|
ircd::ctx::shared_mutex::try_unlock_shared_and_lock_upgrade_until(time_point&& tp)
|
|
|
|
{
|
|
|
|
assert(0);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
template<class time_point>
|
2020-10-29 08:08:06 +01:00
|
|
|
inline bool
|
2017-09-28 09:06:00 +02:00
|
|
|
ircd::ctx::shared_mutex::try_unlock_shared_and_lock_until(time_point&& tp)
|
|
|
|
{
|
|
|
|
assert(0);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool
|
|
|
|
ircd::ctx::shared_mutex::try_unlock_upgrade_and_lock()
|
|
|
|
{
|
|
|
|
if(!try_lock())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool
|
|
|
|
ircd::ctx::shared_mutex::try_unlock_shared_and_lock_upgrade()
|
|
|
|
{
|
|
|
|
if(!try_lock_upgrade())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
--s;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool
|
|
|
|
ircd::ctx::shared_mutex::try_unlock_shared_and_lock()
|
|
|
|
{
|
2020-05-02 00:16:37 +02:00
|
|
|
assert(current);
|
2017-09-28 09:06:00 +02:00
|
|
|
if(s != 1)
|
|
|
|
return false;
|
|
|
|
|
2020-05-01 23:08:29 +02:00
|
|
|
assert(!u);
|
|
|
|
u = current;
|
|
|
|
s = std::numeric_limits<decltype(s)>::min();
|
2017-09-28 09:06:00 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void
|
|
|
|
ircd::ctx::shared_mutex::lock_upgrade()
|
|
|
|
{
|
2020-05-02 00:16:37 +02:00
|
|
|
assert(current);
|
2018-11-14 03:18:38 +01:00
|
|
|
q.wait([this]
|
|
|
|
{
|
|
|
|
return can_lock_upgrade();
|
|
|
|
});
|
2017-09-28 09:06:00 +02:00
|
|
|
|
2020-05-01 22:32:49 +02:00
|
|
|
u = current;
|
2017-09-28 09:06:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
inline void
|
|
|
|
ircd::ctx::shared_mutex::lock_shared()
|
|
|
|
{
|
2018-11-14 03:18:38 +01:00
|
|
|
q.wait([this]
|
|
|
|
{
|
|
|
|
return can_lock_shared();
|
|
|
|
});
|
2017-09-28 09:06:00 +02:00
|
|
|
|
2018-11-14 03:18:38 +01:00
|
|
|
++s;
|
2017-09-28 09:06:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
inline void
|
|
|
|
ircd::ctx::shared_mutex::lock()
|
|
|
|
{
|
2020-05-02 00:16:37 +02:00
|
|
|
assert(current);
|
2018-11-14 03:18:38 +01:00
|
|
|
q.wait([this]
|
|
|
|
{
|
|
|
|
return can_lock();
|
|
|
|
});
|
2017-09-28 09:06:00 +02:00
|
|
|
|
2020-05-01 23:08:29 +02:00
|
|
|
u = current;
|
2018-11-14 03:18:38 +01:00
|
|
|
s = std::numeric_limits<decltype(s)>::min();
|
2017-09-28 09:06:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
template<class duration>
|
2020-10-29 08:08:06 +01:00
|
|
|
inline bool
|
2017-09-28 09:06:00 +02:00
|
|
|
ircd::ctx::shared_mutex::try_lock_upgrade_for(duration&& d)
|
|
|
|
{
|
2019-09-23 05:02:23 +02:00
|
|
|
return try_lock_upgrade_until(system_clock::now() + d);
|
2017-09-28 09:06:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
template<class duration>
|
2020-10-29 08:08:06 +01:00
|
|
|
inline bool
|
2017-09-28 09:06:00 +02:00
|
|
|
ircd::ctx::shared_mutex::try_lock_shared_for(duration&& d)
|
|
|
|
{
|
2019-09-23 05:02:23 +02:00
|
|
|
return try_lock_shared_until(system_clock::now() + d);
|
2017-09-28 09:06:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
template<class duration>
|
2020-10-29 08:08:06 +01:00
|
|
|
inline bool
|
2017-09-28 09:06:00 +02:00
|
|
|
ircd::ctx::shared_mutex::try_lock_for(duration&& d)
|
|
|
|
{
|
2019-09-23 05:02:23 +02:00
|
|
|
return try_lock_until(system_clock::now() + d);
|
2017-09-28 09:06:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
template<class time_point>
|
2020-10-29 08:08:06 +01:00
|
|
|
inline bool
|
2018-11-14 03:22:11 +01:00
|
|
|
ircd::ctx::shared_mutex::try_lock_upgrade_until(time_point&& tp)
|
2017-09-28 09:06:00 +02:00
|
|
|
{
|
2020-05-02 00:16:37 +02:00
|
|
|
assert(current);
|
2018-11-14 03:22:11 +01:00
|
|
|
const bool can_lock_upgrade
|
|
|
|
{
|
|
|
|
q.wait_until(tp, [this]
|
|
|
|
{
|
|
|
|
return this->can_lock_upgrade();
|
|
|
|
})
|
|
|
|
};
|
|
|
|
|
|
|
|
if(can_lock_upgrade)
|
2020-05-01 22:32:49 +02:00
|
|
|
u = current;
|
2018-11-14 03:22:11 +01:00
|
|
|
|
|
|
|
return can_lock_upgrade;
|
2017-09-28 09:06:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
template<class time_point>
|
2020-10-29 08:08:06 +01:00
|
|
|
inline bool
|
2018-11-14 03:22:11 +01:00
|
|
|
ircd::ctx::shared_mutex::try_lock_shared_until(time_point&& tp)
|
2017-09-28 09:06:00 +02:00
|
|
|
{
|
2020-05-02 00:16:37 +02:00
|
|
|
assert(current);
|
2018-11-14 03:22:11 +01:00
|
|
|
const bool can_lock_shared
|
|
|
|
{
|
|
|
|
q.wait_until(tp, [this]
|
|
|
|
{
|
|
|
|
return this->can_lock_shared();
|
|
|
|
})
|
|
|
|
};
|
|
|
|
|
|
|
|
if(can_lock_shared)
|
|
|
|
++s;
|
|
|
|
|
|
|
|
return can_lock_shared;
|
2017-09-28 09:06:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
template<class time_point>
|
2020-10-29 08:08:06 +01:00
|
|
|
inline bool
|
2017-09-28 09:06:00 +02:00
|
|
|
ircd::ctx::shared_mutex::try_lock_until(time_point&& tp)
|
|
|
|
{
|
2020-05-02 00:16:37 +02:00
|
|
|
assert(current);
|
2018-11-14 03:18:38 +01:00
|
|
|
const bool can_lock
|
2017-09-28 09:06:00 +02:00
|
|
|
{
|
2018-11-14 03:18:38 +01:00
|
|
|
q.wait_until(tp, [this]
|
2017-09-28 09:06:00 +02:00
|
|
|
{
|
2018-11-14 03:18:38 +01:00
|
|
|
return this->can_lock();
|
|
|
|
})
|
|
|
|
};
|
2017-09-28 09:06:00 +02:00
|
|
|
|
2018-11-14 03:18:38 +01:00
|
|
|
if(can_lock)
|
2020-05-01 23:08:29 +02:00
|
|
|
{
|
|
|
|
u = current;
|
2018-11-14 03:18:38 +01:00
|
|
|
s = std::numeric_limits<decltype(s)>::min();
|
2020-05-01 23:08:29 +02:00
|
|
|
}
|
2018-11-14 03:18:38 +01:00
|
|
|
|
|
|
|
return can_lock;
|
2017-09-28 09:06:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
inline bool
|
|
|
|
ircd::ctx::shared_mutex::try_lock_upgrade()
|
2018-11-14 03:18:38 +01:00
|
|
|
{
|
2020-05-02 00:16:37 +02:00
|
|
|
assert(current);
|
2018-11-14 03:18:38 +01:00
|
|
|
if(can_lock_upgrade())
|
|
|
|
{
|
2020-05-01 22:32:49 +02:00
|
|
|
u = current;
|
2018-11-14 03:18:38 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool
|
|
|
|
ircd::ctx::shared_mutex::try_lock_shared()
|
|
|
|
{
|
|
|
|
++s;
|
|
|
|
return s >= 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool
|
|
|
|
ircd::ctx::shared_mutex::try_lock()
|
|
|
|
{
|
2020-05-02 00:16:37 +02:00
|
|
|
assert(current);
|
2018-11-14 03:18:38 +01:00
|
|
|
if(can_lock())
|
|
|
|
{
|
2020-05-01 23:08:29 +02:00
|
|
|
u = current;
|
2018-11-14 03:18:38 +01:00
|
|
|
s = std::numeric_limits<decltype(s)>::min();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool
|
|
|
|
ircd::ctx::shared_mutex::can_lock_upgrade()
|
|
|
|
const
|
2017-09-28 09:06:00 +02:00
|
|
|
{
|
2020-05-01 23:08:29 +02:00
|
|
|
assert(u || can_lock_shared());
|
|
|
|
return !u;
|
2017-09-28 09:06:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
inline bool
|
2018-11-14 03:18:38 +01:00
|
|
|
ircd::ctx::shared_mutex::can_lock_shared()
|
|
|
|
const
|
2017-09-28 09:06:00 +02:00
|
|
|
{
|
|
|
|
return s >= 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool
|
2018-11-14 03:18:38 +01:00
|
|
|
ircd::ctx::shared_mutex::can_lock()
|
|
|
|
const
|
2017-09-28 09:06:00 +02:00
|
|
|
{
|
2020-05-01 23:08:29 +02:00
|
|
|
return s == 0 && (!u || u == current);
|
2017-09-28 09:06:00 +02:00
|
|
|
}
|
|
|
|
|
2018-03-06 10:09:37 +01:00
|
|
|
inline size_t
|
|
|
|
ircd::ctx::shared_mutex::waiting()
|
|
|
|
const
|
|
|
|
{
|
|
|
|
return q.size();
|
|
|
|
}
|
|
|
|
|
2018-03-27 03:47:29 +02:00
|
|
|
inline size_t
|
|
|
|
ircd::ctx::shared_mutex::shares()
|
|
|
|
const
|
|
|
|
{
|
|
|
|
return std::max(s, ssize_t(0));
|
|
|
|
}
|
|
|
|
|
2018-08-27 03:01:12 +02:00
|
|
|
inline bool
|
|
|
|
ircd::ctx::shared_mutex::upgrade()
|
|
|
|
const
|
|
|
|
{
|
|
|
|
return u;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool
|
|
|
|
ircd::ctx::shared_mutex::unique()
|
|
|
|
const
|
|
|
|
{
|
|
|
|
return s == std::numeric_limits<decltype(s)>::min();
|
|
|
|
}
|