aboutsummaryrefslogtreecommitdiff
path: root/libstdc++-v3/include/std/shared_mutex
diff options
context:
space:
mode:
authorJonathan Wakely <jwakely@redhat.com>2022-12-05 12:39:23 +0000
committerJonathan Wakely <jwakely@redhat.com>2022-12-06 21:33:29 +0000
commitaf177d7280668e5b21560165dc828754618e6621 (patch)
tree00902363b9af926eff1d24b8048c8b51ae13b8da /libstdc++-v3/include/std/shared_mutex
parent48e21e878b2c6cfc7797088a7393a735de75883c (diff)
downloadgcc-af177d7280668e5b21560165dc828754618e6621.zip
gcc-af177d7280668e5b21560165dc828754618e6621.tar.gz
gcc-af177d7280668e5b21560165dc828754618e6621.tar.bz2
libstdc++: Add nodiscard attribute to mutex try_lock functions
libstdc++-v3/ChangeLog: * include/bits/std_mutex.h (mutex): Add nodiscard attribute to try_lock member function. * include/bits/unique_lock.h (unique_lock): Likewise for try_lock, try_lock_until, try_lock_for member functions, and owns_lock and mutex member functions. * include/std/mutex (recursive_mutex): Likewise for try_lock member function. (timed_mutex, recursive_timed_mutex, try_lock): Likewise for try_lock, try_lock_until, try_lock_for member functions. (try_lock): Likewise for non-member function. * include/std/shared_mutex (shared_mutex): Likewise for try_lock and try_lock_shared member functions. (shared_timed_mutex): Likewise for try_lock, try_lock_for, try_lock_shared, try_lock_shared_for, try_lock_until, and try_lock_shared_until member functions. (shared_lock): Likewise for try_lock, try_lock, try_lock_for, try_lock_until, owns_lock, and mutex member functions. * testsuite/30_threads/recursive_timed_mutex/try_lock_until/clock_neg.cc: Cast discarded value expression to void. * testsuite/30_threads/shared_lock/locking/3.cc: Likewise. * testsuite/30_threads/shared_lock/locking/4.cc: Likewise. * testsuite/30_threads/shared_lock/locking/clock_neg.cc: Likewise. * testsuite/30_threads/shared_timed_mutex/try_lock_until/clock_neg.cc: Likewise. * testsuite/30_threads/timed_mutex/try_lock_until/clock_neg.cc: Likewise. * testsuite/30_threads/try_lock/4.cc: Likewise. * testsuite/30_threads/unique_lock/cons/60497.cc: Likewise. * testsuite/30_threads/unique_lock/locking/3.cc: Likewise. * testsuite/30_threads/unique_lock/locking/clock_neg.cc: Likewise.
Diffstat (limited to 'libstdc++-v3/include/std/shared_mutex')
-rw-r--r--libstdc++-v3/include/std/shared_mutex22
1 files changed, 19 insertions, 3 deletions
diff --git a/libstdc++-v3/include/std/shared_mutex b/libstdc++-v3/include/std/shared_mutex
index cf74b32..7b70697 100644
--- a/libstdc++-v3/include/std/shared_mutex
+++ b/libstdc++-v3/include/std/shared_mutex
@@ -420,13 +420,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
// Exclusive ownership
void lock() { _M_impl.lock(); }
- bool try_lock() { return _M_impl.try_lock(); }
+ [[nodiscard]] bool try_lock() { return _M_impl.try_lock(); }
void unlock() { _M_impl.unlock(); }
// Shared ownership
void lock_shared() { _M_impl.lock_shared(); }
- bool try_lock_shared() { return _M_impl.try_lock_shared(); }
+ [[nodiscard]] bool try_lock_shared() { return _M_impl.try_lock_shared(); }
void unlock_shared() { _M_impl.unlock_shared(); }
#if _GLIBCXX_USE_PTHREAD_RWLOCK_T
@@ -473,10 +473,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
// Exclusive ownership
void lock() { _Base::lock(); }
- bool try_lock() { return _Base::try_lock(); }
+ _GLIBCXX_NODISCARD bool try_lock() { return _Base::try_lock(); }
void unlock() { _Base::unlock(); }
template<typename _Rep, typename _Period>
+ _GLIBCXX_NODISCARD
bool
try_lock_for(const chrono::duration<_Rep, _Period>& __rtime)
{
@@ -489,10 +490,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
// Shared ownership
void lock_shared() { _Base::lock_shared(); }
+ _GLIBCXX_NODISCARD
bool try_lock_shared() { return _Base::try_lock_shared(); }
void unlock_shared() { _Base::unlock_shared(); }
template<typename _Rep, typename _Period>
+ _GLIBCXX_NODISCARD
bool
try_lock_shared_for(const chrono::duration<_Rep, _Period>& __rtime)
{
@@ -507,6 +510,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
// Exclusive ownership
template<typename _Duration>
+ _GLIBCXX_NODISCARD
bool
try_lock_until(const chrono::time_point<chrono::system_clock,
_Duration>& __atime)
@@ -532,6 +536,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
#ifdef _GLIBCXX_USE_PTHREAD_RWLOCK_CLOCKLOCK
template<typename _Duration>
+ _GLIBCXX_NODISCARD
bool
try_lock_until(const chrono::time_point<chrono::steady_clock,
_Duration>& __atime)
@@ -558,6 +563,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
#endif
template<typename _Clock, typename _Duration>
+ _GLIBCXX_NODISCARD
bool
try_lock_until(const chrono::time_point<_Clock, _Duration>& __atime)
{
@@ -580,6 +586,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
// Shared ownership
template<typename _Duration>
+ _GLIBCXX_NODISCARD
bool
try_lock_shared_until(const chrono::time_point<chrono::system_clock,
_Duration>& __atime)
@@ -619,6 +626,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
#ifdef _GLIBCXX_USE_PTHREAD_RWLOCK_CLOCKLOCK
template<typename _Duration>
+ _GLIBCXX_NODISCARD
bool
try_lock_shared_until(const chrono::time_point<chrono::steady_clock,
_Duration>& __atime)
@@ -645,6 +653,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
#endif
template<typename _Clock, typename _Duration>
+ _GLIBCXX_NODISCARD
bool
try_lock_shared_until(const chrono::time_point<_Clock,
_Duration>& __atime)
@@ -670,6 +679,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
// Exclusive ownership
template<typename _Clock, typename _Duration>
+ _GLIBCXX_NODISCARD
bool
try_lock_until(const chrono::time_point<_Clock, _Duration>& __abs_time)
{
@@ -694,6 +704,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
// Shared ownership
template <typename _Clock, typename _Duration>
+ _GLIBCXX_NODISCARD
bool
try_lock_shared_until(const chrono::time_point<_Clock,
_Duration>& __abs_time)
@@ -776,6 +787,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
_M_owns = true;
}
+ _GLIBCXX_NODISCARD
bool
try_lock()
{
@@ -784,6 +796,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
}
template<typename _Rep, typename _Period>
+ _GLIBCXX_NODISCARD
bool
try_lock_for(const chrono::duration<_Rep, _Period>& __rel_time)
{
@@ -792,6 +805,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
}
template<typename _Clock, typename _Duration>
+ _GLIBCXX_NODISCARD
bool
try_lock_until(const chrono::time_point<_Clock, _Duration>& __abs_time)
{
@@ -826,10 +840,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
// Getters
+ _GLIBCXX_NODISCARD
bool owns_lock() const noexcept { return _M_owns; }
explicit operator bool() const noexcept { return _M_owns; }
+ _GLIBCXX_NODISCARD
mutex_type* mutex() const noexcept { return _M_pm; }
private: