Commit 2e8a121a authored by Yedidya Feldblum's avatar Yedidya Feldblum Committed by Facebook Github Bot 8

Nomenclature in Synchronized - prefer read to shared

Summary:
[Folly] Nomenclature in `Synchronized` - prefer `read` to `shared`.

`folly::Synchronized` is a higher-level abstraction, so it will use higher-level nomenclature than will lower-level tools like `std::mutex` and `folly::LockTraits`. `shared` describes the lock state, and is used in the C++ libraries. `read` describes the class of operations that calling code is permitted to perform.

Reviewed By: simpkins

Differential Revision: D3840060

fbshipit-source-id: 4b23eaa391cb59d1eca2bfacf72db89d3c7c591e
parent 2f028f63
...@@ -1151,7 +1151,7 @@ class LockedPtr : public LockedPtrBase< ...@@ -1151,7 +1151,7 @@ class LockedPtr : public LockedPtrBase<
typename = typename std::enable_if< typename = typename std::enable_if<
LockTraits<typename SyncType::MutexType>::is_upgrade>::type> LockTraits<typename SyncType::MutexType>::is_upgrade>::type>
LockedPtr<SynchronizedType, LockPolicyFromUpgradeToShared> LockedPtr<SynchronizedType, LockPolicyFromUpgradeToShared>
moveFromUpgradeToShared() { moveFromUpgradeToRead() {
auto* parent_to_pass_on = this->parent_; auto* parent_to_pass_on = this->parent_;
this->parent_ = nullptr; this->parent_ = nullptr;
return LockedPtr<SynchronizedType, LockPolicyFromUpgradeToShared>( return LockedPtr<SynchronizedType, LockPolicyFromUpgradeToShared>(
...@@ -1167,7 +1167,7 @@ class LockedPtr : public LockedPtrBase< ...@@ -1167,7 +1167,7 @@ class LockedPtr : public LockedPtrBase<
typename = typename std::enable_if< typename = typename std::enable_if<
LockTraits<typename SyncType::MutexType>::is_upgrade>::type> LockTraits<typename SyncType::MutexType>::is_upgrade>::type>
LockedPtr<SynchronizedType, LockPolicyFromExclusiveToShared> LockedPtr<SynchronizedType, LockPolicyFromExclusiveToShared>
moveFromWriteToShared() { moveFromWriteToRead() {
auto* parent_to_pass_on = this->parent_; auto* parent_to_pass_on = this->parent_;
this->parent_ = nullptr; this->parent_ = nullptr;
return LockedPtr<SynchronizedType, LockPolicyFromExclusiveToShared>( return LockedPtr<SynchronizedType, LockPolicyFromExclusiveToShared>(
......
...@@ -397,8 +397,8 @@ downgraded by calling any of the following methods on the `LockedPtr` proxy ...@@ -397,8 +397,8 @@ downgraded by calling any of the following methods on the `LockedPtr` proxy
* `moveFromUpgradeToWrite()` * `moveFromUpgradeToWrite()`
* `moveFromWriteToUpgrade()` * `moveFromWriteToUpgrade()`
* `moveFromWriteToShared()` * `moveFromWriteToRead()`
* `moveFromUpgradeToShared()` * `moveFromUpgradeToRead()`
Calling these leaves the `LockedPtr` object on which the method was called in Calling these leaves the `LockedPtr` object on which the method was called in
an invalid `null` state and returns another LockedPtr proxy holding the an invalid `null` state and returns another LockedPtr proxy holding the
...@@ -429,15 +429,15 @@ This "move" can also occur in the context of a `withULockPtr()` ...@@ -429,15 +429,15 @@ This "move" can also occur in the context of a `withULockPtr()`
// ulock is now null // ulock is now null
wlock->updateObj(); wlock->updateObj();
// release write lock and acquire shared lock atomically // release write lock and acquire read lock atomically
auto rlock = wlock.moveFromWriteToShared(); auto rlock = wlock.moveFromWriteToRead();
// wlock is now null // wlock is now null
return rlock->newSize(); return rlock->newSize();
} else { } else {
// release upgrade lock and acquire shared lock atomically // release upgrade lock and acquire read lock atomically
auto rlock = ulock.moveFromUpgradeToShared(); auto rlock = ulock.moveFromUpgradeToRead();
// ulock is now null // ulock is now null
return rlock->newSize(); return rlock->newSize();
} }
......
...@@ -433,7 +433,7 @@ TEST_F(SynchronizedLockTest, UpgradableLocking) { ...@@ -433,7 +433,7 @@ TEST_F(SynchronizedLockTest, UpgradableLocking) {
// test going from upgrade to shared // test going from upgrade to shared
{ {
auto ulock = sync.ulock(); auto ulock = sync.ulock();
auto slock = ulock.moveFromUpgradeToShared(); auto slock = ulock.moveFromUpgradeToRead();
EXPECT_EQ(static_cast<bool>(ulock), false); EXPECT_EQ(static_cast<bool>(ulock), false);
EXPECT_EQ( EXPECT_EQ(
globalAllPowerfulAssertingMutex.lock_state, globalAllPowerfulAssertingMutex.lock_state,
...@@ -463,7 +463,7 @@ TEST_F(SynchronizedLockTest, UpgradableLocking) { ...@@ -463,7 +463,7 @@ TEST_F(SynchronizedLockTest, UpgradableLocking) {
// test going from exclusive to shared // test going from exclusive to shared
{ {
auto wlock = sync.wlock(); auto wlock = sync.wlock();
auto slock = wlock.moveFromWriteToShared(); auto slock = wlock.moveFromWriteToRead();
EXPECT_EQ(static_cast<bool>(wlock), false); EXPECT_EQ(static_cast<bool>(wlock), false);
EXPECT_EQ( EXPECT_EQ(
globalAllPowerfulAssertingMutex.lock_state, globalAllPowerfulAssertingMutex.lock_state,
...@@ -529,7 +529,7 @@ TEST_F(SynchronizedLockTest, UpgradableLockingWithULock) { ...@@ -529,7 +529,7 @@ TEST_F(SynchronizedLockTest, UpgradableLockingWithULock) {
globalAllPowerfulAssertingMutex.lock_state, globalAllPowerfulAssertingMutex.lock_state,
FakeAllPowerfulAssertingMutexInternal::CurrentLockState::UPGRADE); FakeAllPowerfulAssertingMutexInternal::CurrentLockState::UPGRADE);
auto slock = ulock.moveFromUpgradeToShared(); auto slock = ulock.moveFromUpgradeToRead();
EXPECT_EQ(static_cast<bool>(ulock), false); EXPECT_EQ(static_cast<bool>(ulock), false);
EXPECT_EQ( EXPECT_EQ(
globalAllPowerfulAssertingMutex.lock_state, globalAllPowerfulAssertingMutex.lock_state,
...@@ -548,7 +548,7 @@ TEST_F(SynchronizedLockTest, UpgradableLockingWithULock) { ...@@ -548,7 +548,7 @@ TEST_F(SynchronizedLockTest, UpgradableLockingWithULock) {
globalAllPowerfulAssertingMutex.lock_state, globalAllPowerfulAssertingMutex.lock_state,
FakeAllPowerfulAssertingMutexInternal::CurrentLockState::UNIQUE); FakeAllPowerfulAssertingMutexInternal::CurrentLockState::UNIQUE);
auto slock = wlock.moveFromWriteToShared(); auto slock = wlock.moveFromWriteToRead();
EXPECT_EQ(static_cast<bool>(wlock), false); EXPECT_EQ(static_cast<bool>(wlock), false);
EXPECT_EQ( EXPECT_EQ(
globalAllPowerfulAssertingMutex.lock_state, globalAllPowerfulAssertingMutex.lock_state,
......
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