[4.1] add [[nodiscard]] on LockGuard
This commit is contained in:
16
deps/oblib/src/lib/lock/ob_bucket_lock.h
vendored
16
deps/oblib/src/lib/lock/ob_bucket_lock.h
vendored
@ -68,7 +68,7 @@ private:
|
||||
class ObBucketRLockGuard final
|
||||
{
|
||||
public:
|
||||
ObBucketRLockGuard(ObBucketLock &lock, const uint64_t bucket_index)
|
||||
[[nodiscard]] ObBucketRLockGuard(ObBucketLock &lock, const uint64_t bucket_index)
|
||||
: lock_(lock),
|
||||
index_(bucket_index),
|
||||
ret_(OB_SUCCESS),
|
||||
@ -109,7 +109,7 @@ private:
|
||||
class ObBucketWLockGuard final
|
||||
{
|
||||
public:
|
||||
ObBucketWLockGuard(ObBucketLock &lock, const uint64_t bucket_index)
|
||||
[[nodiscard]] ObBucketWLockGuard(ObBucketLock &lock, const uint64_t bucket_index)
|
||||
: lock_(lock),
|
||||
index_(bucket_index),
|
||||
ret_(OB_SUCCESS),
|
||||
@ -150,7 +150,7 @@ private:
|
||||
class ObBucketWLockAllGuard final
|
||||
{
|
||||
public:
|
||||
ObBucketWLockAllGuard(ObBucketLock &lock)
|
||||
[[nodiscard]] ObBucketWLockAllGuard(ObBucketLock &lock)
|
||||
: lock_(lock),
|
||||
ret_(OB_SUCCESS),
|
||||
lock_start_ts_(0)
|
||||
@ -189,7 +189,7 @@ private:
|
||||
class ObBucketTryWLockAllGuard final
|
||||
{
|
||||
public:
|
||||
ObBucketTryWLockAllGuard(ObBucketLock &lock)
|
||||
[[nodiscard]] ObBucketTryWLockAllGuard(ObBucketLock &lock)
|
||||
: lock_(lock),
|
||||
ret_(OB_SUCCESS),
|
||||
lock_start_ts_(0)
|
||||
@ -234,7 +234,7 @@ private:
|
||||
class ObBucketTryRLockAllGuard final
|
||||
{
|
||||
public:
|
||||
ObBucketTryRLockAllGuard(ObBucketLock &lock)
|
||||
[[nodiscard]] ObBucketTryRLockAllGuard(ObBucketLock &lock)
|
||||
: lock_(lock),
|
||||
ret_(OB_SUCCESS),
|
||||
lock_start_ts_(0)
|
||||
@ -279,7 +279,7 @@ private:
|
||||
class ObMultiBucketLockGuard final
|
||||
{
|
||||
public:
|
||||
ObMultiBucketLockGuard(ObBucketLock &lock, const bool is_write_lock);
|
||||
[[nodiscard]] ObMultiBucketLockGuard(ObBucketLock &lock, const bool is_write_lock);
|
||||
~ObMultiBucketLockGuard();
|
||||
int lock_multi_buckets(ObIArray<uint64_t> &hash_array);
|
||||
private:
|
||||
@ -293,7 +293,7 @@ private:
|
||||
class ObBucketHashRLockGuard final
|
||||
{
|
||||
public:
|
||||
ObBucketHashRLockGuard(ObBucketLock &lock, const uint64_t hash_value)
|
||||
[[nodiscard]] ObBucketHashRLockGuard(ObBucketLock &lock, const uint64_t hash_value)
|
||||
: guard_(lock, lock.get_bucket_idx(hash_value))
|
||||
{
|
||||
}
|
||||
@ -307,7 +307,7 @@ private:
|
||||
class ObBucketHashWLockGuard final
|
||||
{
|
||||
public:
|
||||
ObBucketHashWLockGuard(ObBucketLock &lock, const uint64_t hash_value)
|
||||
[[nodiscard]] ObBucketHashWLockGuard(ObBucketLock &lock, const uint64_t hash_value)
|
||||
: guard_(lock, lock.get_bucket_idx(hash_value))
|
||||
{
|
||||
}
|
||||
|
||||
4
deps/oblib/src/lib/lock/ob_drw_lock.h
vendored
4
deps/oblib/src/lib/lock/ob_drw_lock.h
vendored
@ -34,7 +34,7 @@ public:
|
||||
class RDLockGuard
|
||||
{
|
||||
public:
|
||||
explicit RDLockGuard(DRWLock &rwlock): rwlock_(rwlock), ret_(OB_SUCCESS)
|
||||
[[nodiscard]] explicit RDLockGuard(DRWLock &rwlock): rwlock_(rwlock), ret_(OB_SUCCESS)
|
||||
{
|
||||
if (OB_UNLIKELY(OB_SUCCESS != (ret_ = rwlock_.rdlock()))) {
|
||||
COMMON_LOG(WARN, "Fail to read lock, ", K_(ret));
|
||||
@ -58,7 +58,7 @@ public:
|
||||
class WRLockGuard
|
||||
{
|
||||
public:
|
||||
explicit WRLockGuard(DRWLock &rwlock): rwlock_(rwlock), ret_(OB_SUCCESS)
|
||||
[[nodiscard]] explicit WRLockGuard(DRWLock &rwlock): rwlock_(rwlock), ret_(OB_SUCCESS)
|
||||
{
|
||||
if (OB_UNLIKELY(OB_SUCCESS != (ret_ = rwlock_.wrlock()))) {
|
||||
COMMON_LOG(WARN, "Fail to write lock, ", K_(ret));
|
||||
|
||||
6
deps/oblib/src/lib/lock/ob_latch.h
vendored
6
deps/oblib/src/lib/lock/ob_latch.h
vendored
@ -364,7 +364,7 @@ private:
|
||||
class ObLatchMutexGuard
|
||||
{
|
||||
public:
|
||||
ObLatchMutexGuard(ObLatchMutex &lock, const uint32_t latch_id)
|
||||
[[nodiscard]] ObLatchMutexGuard(ObLatchMutex &lock, const uint32_t latch_id)
|
||||
: lock_(lock), ret_(OB_SUCCESS)
|
||||
{
|
||||
if (OB_UNLIKELY(OB_SUCCESS != (ret_ = lock_.lock(latch_id)))) {
|
||||
@ -390,7 +390,7 @@ private:
|
||||
class ObLatchRGuard
|
||||
{
|
||||
public:
|
||||
ObLatchRGuard(ObLatch &lock, const uint32_t latch_id)
|
||||
[[nodiscard]] ObLatchRGuard(ObLatch &lock, const uint32_t latch_id)
|
||||
: lock_(lock),
|
||||
ret_(OB_SUCCESS)
|
||||
{
|
||||
@ -418,7 +418,7 @@ private:
|
||||
class ObLatchWGuard
|
||||
{
|
||||
public:
|
||||
ObLatchWGuard(ObLatch &lock, const uint32_t latch_id)
|
||||
[[nodiscard]] ObLatchWGuard(ObLatch &lock, const uint32_t latch_id)
|
||||
: lock_(lock),
|
||||
ret_(OB_SUCCESS)
|
||||
{
|
||||
|
||||
2
deps/oblib/src/lib/lock/ob_lock_guard.h
vendored
2
deps/oblib/src/lib/lock/ob_lock_guard.h
vendored
@ -25,7 +25,7 @@ template <typename LockT>
|
||||
class ObLockGuard
|
||||
{
|
||||
public:
|
||||
explicit ObLockGuard(LockT &lock);
|
||||
[[nodiscard]] explicit ObLockGuard(LockT &lock);
|
||||
~ObLockGuard();
|
||||
inline int get_ret() const { return ret_; }
|
||||
private:
|
||||
|
||||
6
deps/oblib/src/lib/lock/ob_rwlock.h
vendored
6
deps/oblib/src/lib/lock/ob_rwlock.h
vendored
@ -23,7 +23,7 @@ template <class T>
|
||||
class ObLockGuardBase
|
||||
{
|
||||
public:
|
||||
ObLockGuardBase(const T& lock, bool block = true) : lock_(lock)
|
||||
[[nodiscard]] ObLockGuardBase(const T& lock, bool block = true) : lock_(lock)
|
||||
{
|
||||
acquired_ = !(block ? lock_.lock() : lock_.trylock());
|
||||
}
|
||||
@ -87,7 +87,7 @@ private:
|
||||
class ObRLockGuard
|
||||
{
|
||||
public:
|
||||
ObRLockGuard(const ObRWLock& rwlock, bool block = true) : guard_((*rwlock.rlock()), block) {}
|
||||
[[nodiscard]] ObRLockGuard(const ObRWLock& rwlock, bool block = true) : guard_((*rwlock.rlock()), block) {}
|
||||
~ObRLockGuard(){}
|
||||
bool acquired() { return guard_.acquired(); }
|
||||
private:
|
||||
@ -97,7 +97,7 @@ private:
|
||||
class ObWLockGuard
|
||||
{
|
||||
public:
|
||||
ObWLockGuard(const ObRWLock& rwlock, bool block = true) : guard_((*rwlock.wlock()), block) {}
|
||||
[[nodiscard]] ObWLockGuard(const ObRWLock& rwlock, bool block = true) : guard_((*rwlock.wlock()), block) {}
|
||||
~ObWLockGuard(){}
|
||||
bool acquired() { return guard_.acquired(); }
|
||||
private:
|
||||
|
||||
26
deps/oblib/src/lib/lock/ob_tc_rwlock.h
vendored
26
deps/oblib/src/lib/lock/ob_tc_rwlock.h
vendored
@ -54,13 +54,13 @@ public:
|
||||
enum { WRITE_MASK = 1<<31 };
|
||||
struct RLockGuard
|
||||
{
|
||||
explicit RLockGuard(TCRWLock& lock): lock_(lock) { lock_.rdlock(); }
|
||||
[[nodiscard]] explicit RLockGuard(TCRWLock& lock): lock_(lock) { lock_.rdlock(); }
|
||||
~RLockGuard() { lock_.rdunlock(); }
|
||||
TCRWLock& lock_;
|
||||
};
|
||||
struct RLockGuardWithTimeout
|
||||
{
|
||||
explicit RLockGuardWithTimeout(TCRWLock &lock, const int64_t abs_timeout_us, int &ret): lock_(lock), need_unlock_(true)
|
||||
[[nodiscard]] explicit RLockGuardWithTimeout(TCRWLock &lock, const int64_t abs_timeout_us, int &ret): lock_(lock), need_unlock_(true)
|
||||
{
|
||||
if (OB_FAIL(lock_.rdlock(abs_timeout_us))) {
|
||||
need_unlock_ = false;
|
||||
@ -80,13 +80,13 @@ public:
|
||||
};
|
||||
struct WLockGuard
|
||||
{
|
||||
explicit WLockGuard(TCRWLock& lock): lock_(lock) { lock_.wrlock(); }
|
||||
[[nodiscard]] explicit WLockGuard(TCRWLock& lock): lock_(lock) { lock_.wrlock(); }
|
||||
~WLockGuard() { lock_.wrunlock(); }
|
||||
TCRWLock& lock_;
|
||||
};
|
||||
struct WLockGuardWithTimeout
|
||||
{
|
||||
explicit WLockGuardWithTimeout(TCRWLock &lock, const int64_t abs_timeout_us, int &ret): lock_(lock), need_unlock_(true)
|
||||
[[nodiscard]] explicit WLockGuardWithTimeout(TCRWLock &lock, const int64_t abs_timeout_us, int &ret): lock_(lock), need_unlock_(true)
|
||||
{
|
||||
if (OB_FAIL(lock_.wrlock(abs_timeout_us))) {
|
||||
need_unlock_ = false;
|
||||
@ -106,7 +106,7 @@ public:
|
||||
};
|
||||
struct WLockGuardWithRetry
|
||||
{
|
||||
explicit WLockGuardWithRetry(TCRWLock &lock, const int64_t abs_timeout_us) : lock_(lock)
|
||||
[[nodiscard]] explicit WLockGuardWithRetry(TCRWLock &lock, const int64_t abs_timeout_us) : lock_(lock)
|
||||
{
|
||||
lock_.wrlock_with_retry(abs_timeout_us);
|
||||
}
|
||||
@ -115,7 +115,7 @@ public:
|
||||
};
|
||||
struct WLockGuardWithRetryInterval
|
||||
{
|
||||
explicit WLockGuardWithRetryInterval(TCRWLock &lock,
|
||||
[[nodiscard]] explicit WLockGuardWithRetryInterval(TCRWLock &lock,
|
||||
const int64_t try_thresold_us,
|
||||
const int64_t retry_interval_us)
|
||||
: lock_(lock)
|
||||
@ -287,7 +287,7 @@ private:
|
||||
class TCWLockGuard
|
||||
{
|
||||
public:
|
||||
explicit TCWLockGuard(const TCRWLock &lock)
|
||||
[[nodiscard]] explicit TCWLockGuard(const TCRWLock &lock)
|
||||
: lock_(const_cast<TCRWLock&>(lock)), ret_(OB_SUCCESS)
|
||||
{
|
||||
if (OB_UNLIKELY(OB_SUCCESS != (ret_ = lock_.wrlock()))) {
|
||||
@ -313,7 +313,7 @@ private:
|
||||
class TCRLockGuard
|
||||
{
|
||||
public:
|
||||
explicit TCRLockGuard(const TCRWLock &lock)
|
||||
[[nodiscard]] explicit TCRLockGuard(const TCRWLock &lock)
|
||||
: lock_(const_cast<TCRWLock&>(lock)), ret_(OB_SUCCESS), slot_id_(0)
|
||||
{
|
||||
if (OB_UNLIKELY(OB_SUCCESS != (ret_ = lock_.rdlock(INT64_MAX, slot_id_)))) {
|
||||
@ -342,7 +342,7 @@ typedef TCRWLock RWLock;
|
||||
class RWLock
|
||||
{
|
||||
public:
|
||||
struct RLockGuard
|
||||
[[nodiscard]] struct RLockGuard
|
||||
{
|
||||
explicit RLockGuard(RWLock& lock): lock_(lock) { lock_.rdlock(); }
|
||||
~RLockGuard() { lock_.rdunlock(); }
|
||||
@ -350,7 +350,7 @@ public:
|
||||
};
|
||||
struct RLockGuardWithTimeout
|
||||
{
|
||||
explicit RLockGuardWithTimeout(RWLock &lock, const int64_t abs_timeout_us, int &ret): lock_(lock), need_unlock_(true)
|
||||
[[nodiscard]] explicit RLockGuardWithTimeout(RWLock &lock, const int64_t abs_timeout_us, int &ret): lock_(lock), need_unlock_(true)
|
||||
{
|
||||
if (OB_FAIL(lock_.rdlock(abs_timeout_us))) {
|
||||
need_unlock_ = false;
|
||||
@ -371,13 +371,13 @@ public:
|
||||
|
||||
struct WLockGuard
|
||||
{
|
||||
explicit WLockGuard(RWLock& lock): lock_(lock) { lock_.wrlock(); }
|
||||
[[nodiscard]] explicit WLockGuard(RWLock& lock): lock_(lock) { lock_.wrlock(); }
|
||||
~WLockGuard() { lock_.wrunlock(); }
|
||||
RWLock& lock_;
|
||||
};
|
||||
struct WLockGuardWithTimeout
|
||||
{
|
||||
explicit WLockGuardWithTimeout(RWLock &lock, const int64_t abs_timeout_us, int &ret): lock_(lock), need_unlock_(true)
|
||||
[[nodiscard]] explicit WLockGuardWithTimeout(RWLock &lock, const int64_t abs_timeout_us, int &ret): lock_(lock), need_unlock_(true)
|
||||
{
|
||||
if (OB_FAIL(lock_.wrlock(abs_timeout_us))) {
|
||||
need_unlock_ = false;
|
||||
@ -397,7 +397,7 @@ public:
|
||||
};
|
||||
struct WLockGuardWithRetry
|
||||
{
|
||||
explicit WLockGuardWithRetry(RWLock &lock, const int64_t abs_timeout_us) : lock_(lock)
|
||||
[[nodiscard]] explicit WLockGuardWithRetry(RWLock &lock, const int64_t abs_timeout_us) : lock_(lock)
|
||||
{
|
||||
lock_.wrlock_with_retry(abs_timeout_us);
|
||||
}
|
||||
|
||||
2
deps/oblib/src/lib/lock/threadmutex.h
vendored
2
deps/oblib/src/lib/lock/threadmutex.h
vendored
@ -52,7 +52,7 @@ protected:
|
||||
class ThreadGuard
|
||||
{
|
||||
public:
|
||||
ThreadGuard(ThreadMutex *mutex)
|
||||
[[nodiscard]] ThreadGuard(ThreadMutex *mutex)
|
||||
{
|
||||
mutex_ = NULL;
|
||||
if (mutex) {
|
||||
|
||||
Reference in New Issue
Block a user