Commit 22073b2c authored by Andrii Grynenko's avatar Andrii Grynenko Committed by Facebook GitHub Bot

Remove MicroLock::init()

Summary: Have constructor do init() instead. I can't think of any valid reason to have this API other than confusing everyone who decides to use it.

Reviewed By: praihan

Differential Revision: D32302228

fbshipit-source-id: 136e0d2919291acd60be953337309cd006bd674b
parent 84c2ff1c
...@@ -94,7 +94,7 @@ namespace folly { ...@@ -94,7 +94,7 @@ namespace folly {
class MicroLockCore { class MicroLockCore {
protected: protected:
uint8_t lock_; uint8_t lock_{};
/** /**
* Arithmetic shift required to get to the byte from the word. * Arithmetic shift required to get to the byte from the word.
*/ */
...@@ -183,11 +183,6 @@ class MicroLockCore { ...@@ -183,11 +183,6 @@ class MicroLockCore {
*/ */
void unlockAndStore(uint8_t value) noexcept; void unlockAndStore(uint8_t value) noexcept;
void unlock() noexcept; void unlock() noexcept;
/**
* Initializes the lock state and sets the data bits to 0.
*/
void init() noexcept { lock_ = 0; }
}; };
inline detail::Futex<>* MicroLockCore::word() const noexcept { inline detail::Futex<>* MicroLockCore::word() const noexcept {
......
...@@ -168,7 +168,7 @@ class basic_once_flag { ...@@ -168,7 +168,7 @@ class basic_once_flag {
class compact_once_flag { class compact_once_flag {
public: public:
compact_once_flag() noexcept { mutex_.init(); } compact_once_flag() = default;
compact_once_flag(const compact_once_flag&) = delete; compact_once_flag(const compact_once_flag&) = delete;
compact_once_flag& operator=(const compact_once_flag&) = delete; compact_once_flag& operator=(const compact_once_flag&) = delete;
......
...@@ -401,7 +401,7 @@ BENCHMARK(PicoSpinLockUncontendedBenchmark, iters) { ...@@ -401,7 +401,7 @@ BENCHMARK(PicoSpinLockUncontendedBenchmark, iters) {
} }
BENCHMARK(MicroLockUncontendedBenchmark, iters) { BENCHMARK(MicroLockUncontendedBenchmark, iters) {
runUncontended<InitLock<folly::MicroLock>>(iters); runUncontended<folly::MicroLock>(iters);
} }
BENCHMARK(SharedMutexUncontendedBenchmark, iters) { BENCHMARK(SharedMutexUncontendedBenchmark, iters) {
...@@ -718,7 +718,7 @@ int main(int argc, char** argv) { ...@@ -718,7 +718,7 @@ int main(int argc, char** argv) {
"folly::MicroSpinLock", numThreads); "folly::MicroSpinLock", numThreads);
fairnessTest<InitLock<folly::PicoSpinLock<std::uint16_t>>>( fairnessTest<InitLock<folly::PicoSpinLock<std::uint16_t>>>(
"folly::PicoSpinLock<std::uint16_t>", numThreads); "folly::PicoSpinLock<std::uint16_t>", numThreads);
fairnessTest<InitLock<folly::MicroLock>>("folly::MicroLock", numThreads); fairnessTest<folly::MicroLock>("folly::MicroLock", numThreads);
fairnessTest<folly::SharedMutex>("folly::SharedMutex", numThreads); fairnessTest<folly::SharedMutex>("folly::SharedMutex", numThreads);
fairnessTest<folly::DistributedMutex>( fairnessTest<folly::DistributedMutex>(
"folly::DistributedMutex", numThreads); "folly::DistributedMutex", numThreads);
......
...@@ -267,7 +267,6 @@ TEST(SmallLocks, MicroLock) { ...@@ -267,7 +267,6 @@ TEST(SmallLocks, MicroLock) {
x.a = 'a'; x.a = 'a';
x.b = origB; x.b = origB;
x.alock.init();
x.d = origD; x.d = origD;
// This thread touches other parts of the host word to show that // This thread touches other parts of the host word to show that
...@@ -317,7 +316,6 @@ TEST(SmallLocks, MicroLock) { ...@@ -317,7 +316,6 @@ TEST(SmallLocks, MicroLock) {
TEST(SmallLocks, MicroLockTryLock) { TEST(SmallLocks, MicroLockTryLock) {
MicroLock lock; MicroLock lock;
lock.init();
EXPECT_TRUE(lock.try_lock()); EXPECT_TRUE(lock.try_lock());
EXPECT_FALSE(lock.try_lock()); EXPECT_FALSE(lock.try_lock());
lock.unlock(); lock.unlock();
...@@ -325,7 +323,6 @@ TEST(SmallLocks, MicroLockTryLock) { ...@@ -325,7 +323,6 @@ TEST(SmallLocks, MicroLockTryLock) {
TEST(SmallLocks, MicroLockWithData) { TEST(SmallLocks, MicroLockWithData) {
MicroLock lock; MicroLock lock;
lock.init();
EXPECT_EQ(lock.load(std::memory_order_relaxed), 0); EXPECT_EQ(lock.load(std::memory_order_relaxed), 0);
EXPECT_EQ(lock.lockAndLoad(), 0); EXPECT_EQ(lock.lockAndLoad(), 0);
...@@ -363,7 +360,6 @@ TEST(SmallLocks, MicroLockDataAlignment) { ...@@ -363,7 +360,6 @@ TEST(SmallLocks, MicroLockDataAlignment) {
uint8_t padding2; uint8_t padding2;
} thing; } thing;
auto& lock = thing.lock; auto& lock = thing.lock;
lock.init();
EXPECT_EQ(lock.lockAndLoad(), 0); EXPECT_EQ(lock.lockAndLoad(), 0);
lock.unlockAndStore(60); lock.unlockAndStore(60);
......
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