Commit a130b23a authored by Dan Melnic's avatar Dan Melnic Committed by Facebook Github Bot

Remove/make private the default ***Holder constructor to allow compile time...

Remove/make private the default ***Holder constructor to allow compile time detection of ***Holder(mutexPtr_) constructs

Summary: Avoid unintended C++ stuff - this is not the same as the "fleeting rvalue" - this change might break the build but I will fix it

Reviewed By: yfeldblum

Differential Revision: D4814104

fbshipit-source-id: 058a0eac44893c573062fcf5665d4fd022ee64a0
parent bd068648
......@@ -307,7 +307,7 @@ class RWSpinLock {
class ReadHolder {
public:
explicit ReadHolder(RWSpinLock* lock = nullptr) : lock_(lock) {
explicit ReadHolder(RWSpinLock* lock) : lock_(lock) {
if (lock_) lock_->lock_shared();
}
......@@ -360,7 +360,7 @@ class RWSpinLock {
class UpgradedHolder {
public:
explicit UpgradedHolder(RWSpinLock* lock = nullptr) : lock_(lock) {
explicit UpgradedHolder(RWSpinLock* lock) : lock_(lock) {
if (lock_) lock_->lock_upgrade();
}
......@@ -409,7 +409,7 @@ class RWSpinLock {
class WriteHolder {
public:
explicit WriteHolder(RWSpinLock* lock = nullptr) : lock_(lock) {
explicit WriteHolder(RWSpinLock* lock) : lock_(lock) {
if (lock_) lock_->lock();
}
......@@ -692,8 +692,7 @@ class RWTicketSpinLockT {
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();
}
......@@ -732,7 +731,7 @@ class RWTicketSpinLockT {
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) {
......
......@@ -1133,10 +1133,15 @@ class SharedMutexImpl {
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)) {
......@@ -1190,10 +1195,14 @@ class SharedMutexImpl {
};
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();
......@@ -1236,10 +1245,14 @@ class SharedMutexImpl {
};
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();
......
......@@ -45,7 +45,7 @@ void StaticMetaBase::onThreadExit(void* ptr) {
};
{
SharedMutex::ReadHolder rlock;
SharedMutex::ReadHolder rlock(nullptr);
if (meta.strict_) {
rlock = SharedMutex::ReadHolder(meta.accessAllThreadsLock_);
}
......@@ -103,7 +103,7 @@ void StaticMetaBase::destroy(EntryID* ent) {
std::vector<ElementWrapper> elements;
{
SharedMutex::WriteHolder wlock;
SharedMutex::WriteHolder wlock(nullptr);
if (meta.strict_) {
/*
* In strict mode, the logic guarantees per-thread instances are
......
......@@ -98,7 +98,7 @@ void runBasicHoldersTest() {
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));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment