class ReadHolder {
public:
- explicit ReadHolder(RWSpinLock* lock = nullptr) : lock_(lock) {
+ explicit ReadHolder(RWSpinLock* lock) : lock_(lock) {
if (lock_) lock_->lock_shared();
}
class UpgradedHolder {
public:
- explicit UpgradedHolder(RWSpinLock* lock = nullptr) : lock_(lock) {
+ explicit UpgradedHolder(RWSpinLock* lock) : lock_(lock) {
if (lock_) lock_->lock_upgrade();
}
class WriteHolder {
public:
- explicit WriteHolder(RWSpinLock* lock = nullptr) : lock_(lock) {
+ explicit WriteHolder(RWSpinLock* lock) : lock_(lock) {
if (lock_) lock_->lock();
}
ReadHolder(ReadHolder const&) = delete;
ReadHolder& operator=(ReadHolder const&) = delete;
- explicit ReadHolder(RWSpinLock *lock = nullptr) :
- lock_(lock) {
+ explicit ReadHolder(RWSpinLock* lock) : lock_(lock) {
if (lock_) lock_->lock_shared();
}
WriteHolder(WriteHolder const&) = delete;
WriteHolder& operator=(WriteHolder const&) = delete;
- explicit WriteHolder(RWSpinLock *lock = nullptr) : lock_(lock) {
+ explicit WriteHolder(RWSpinLock* lock) : lock_(lock) {
if (lock_) lock_->lock();
}
explicit WriteHolder(RWSpinLock &lock) : lock_ (&lock) {
public:
class ReadHolder {
- public:
ReadHolder() : lock_(nullptr) {}
- explicit ReadHolder(const SharedMutexImpl* lock) : ReadHolder(*lock) {}
+ public:
+ explicit ReadHolder(const SharedMutexImpl* lock)
+ : lock_(const_cast<SharedMutexImpl*>(lock)) {
+ if (lock_) {
+ lock_->lock_shared(token_);
+ }
+ }
explicit ReadHolder(const SharedMutexImpl& lock)
: lock_(const_cast<SharedMutexImpl*>(&lock)) {
};
class UpgradeHolder {
- public:
UpgradeHolder() : lock_(nullptr) {}
- explicit UpgradeHolder(SharedMutexImpl* lock) : UpgradeHolder(*lock) {}
+ public:
+ explicit UpgradeHolder(SharedMutexImpl* lock) : lock_(lock) {
+ if (lock_) {
+ lock_->lock_upgrade();
+ }
+ }
explicit UpgradeHolder(SharedMutexImpl& lock) : lock_(&lock) {
lock_->lock_upgrade();
};
class WriteHolder {
- public:
WriteHolder() : lock_(nullptr) {}
- explicit WriteHolder(SharedMutexImpl* lock) : WriteHolder(*lock) {}
+ public:
+ explicit WriteHolder(SharedMutexImpl* lock) : lock_(lock) {
+ if (lock_) {
+ lock_->lock();
+ }
+ }
explicit WriteHolder(SharedMutexImpl& lock) : lock_(&lock) {
lock_->lock();
};
{
- SharedMutex::ReadHolder rlock;
+ SharedMutex::ReadHolder rlock(nullptr);
if (meta.strict_) {
rlock = SharedMutex::ReadHolder(meta.accessAllThreadsLock_);
}
std::vector<ElementWrapper> elements;
{
- SharedMutex::WriteHolder wlock;
+ SharedMutex::WriteHolder wlock(nullptr);
if (meta.strict_) {
/*
* In strict mode, the logic guarantees per-thread instances are
EXPECT_FALSE(lock.try_lock_shared(token));
// move ownership to another write holder via assign operator
- typename Lock::WriteHolder holder3;
+ typename Lock::WriteHolder holder3(nullptr);
holder3 = std::move(holder2);
EXPECT_FALSE(lock.try_lock());
EXPECT_FALSE(lock.try_lock_shared(token));