Commit 7426f02a authored by Yedidya Feldblum's avatar Yedidya Feldblum Committed by Facebook GitHub Bot

remove folly::SpinLockGuard

Summary:
C++17 permits use of `std::unique_lock` instead of `folly::SpinLockGuard`; just use that.

C++11 permits use of `std::unique_lock<SpinLock>`.

Differential Revision: D27390136

fbshipit-source-id: bcc34a043644289523ddfdfbf47a260c133db186
parent e4fb76b6
......@@ -52,24 +52,4 @@ class SpinLock {
mutable folly::MicroSpinLock lock_;
};
template <typename LOCK>
class SpinLockGuardImpl {
public:
FOLLY_ALWAYS_INLINE explicit SpinLockGuardImpl(LOCK& lock) noexcept(
noexcept(lock.lock()))
: lock_(lock) {
lock_.lock();
}
SpinLockGuardImpl(const SpinLockGuardImpl&) = delete;
SpinLockGuardImpl& operator=(const SpinLockGuardImpl&) = delete;
FOLLY_ALWAYS_INLINE ~SpinLockGuardImpl() { lock_.unlock(); }
private:
LOCK& lock_;
};
typedef SpinLockGuardImpl<SpinLock> SpinLockGuard;
} // namespace folly
......@@ -561,7 +561,7 @@ void AsyncSSLSocket::attachSSLContext(const std::shared_ptr<SSLContext>& ctx) {
OpenSSLUtils::setSSLInitialCtx(ssl_.get(), sslCtx);
// Detach sets the socket's context to the dummy context. Thus we must acquire
// this lock.
SpinLockGuard guard(dummyCtxLock);
std::unique_lock<SpinLock> guard(dummyCtxLock);
SSL_set_SSL_CTX(ssl_.get(), sslCtx);
}
......@@ -587,7 +587,7 @@ void AsyncSSLSocket::detachSSLContext() {
OpenSSLUtils::setSSLInitialCtx(ssl_.get(), nullptr);
}
SpinLockGuard guard(dummyCtxLock);
std::unique_lock<SpinLock> guard(dummyCtxLock);
if (nullptr == dummyCtx) {
// We need to lazily initialize the dummy context so we don't
// accidentally override any programmatic settings to openssl
......
......@@ -423,7 +423,7 @@ class NotificationQueue {
std::unique_ptr<Node> data;
{
folly::SpinLockGuard g(spinlock_);
std::unique_lock<SpinLock> g(spinlock_);
if (UNLIKELY(queue_.empty())) {
return false;
......@@ -440,7 +440,7 @@ class NotificationQueue {
}
size_t size() const {
folly::SpinLockGuard g(spinlock_);
std::unique_lock<SpinLock> g(spinlock_);
return queue_.size();
}
......@@ -548,12 +548,12 @@ class NotificationQueue {
}
void ensureSignal() const {
folly::SpinLockGuard g(spinlock_);
std::unique_lock<SpinLock> g(spinlock_);
ensureSignalLocked();
}
void syncSignalAndQueue() {
folly::SpinLockGuard g(spinlock_);
std::unique_lock<SpinLock> g(spinlock_);
if (queue_.empty()) {
drainSignalsLocked();
......@@ -569,7 +569,7 @@ class NotificationQueue {
{
auto data = std::make_unique<Node>(
std::forward<MessageTT>(message), RequestContext::saveContext());
folly::SpinLockGuard g(spinlock_);
std::unique_lock<SpinLock> g(spinlock_);
if (checkDraining(throws) || !checkQueueSize(maxSize, throws)) {
return false;
}
......@@ -599,7 +599,7 @@ class NotificationQueue {
q.push_back(*data.release());
++first;
}
folly::SpinLockGuard g(spinlock_);
std::unique_lock<SpinLock> g(spinlock_);
checkDraining();
queue_.splice(queue_.end(), q);
if (numActiveConsumers_ < numConsumers_) {
......@@ -781,7 +781,7 @@ void NotificationQueue<MessageT>::Consumer::init(
queue_ = queue;
{
folly::SpinLockGuard g(queue_->spinlock_);
std::unique_lock<SpinLock> g(queue_->spinlock_);
queue_->numConsumers_++;
}
queue_->ensureSignal();
......@@ -801,7 +801,7 @@ void NotificationQueue<MessageT>::Consumer::stopConsuming() {
}
{
folly::SpinLockGuard g(queue_->spinlock_);
std::unique_lock<SpinLock> g(queue_->spinlock_);
queue_->numConsumers_--;
setActive(false);
}
......@@ -817,7 +817,7 @@ bool NotificationQueue<MessageT>::Consumer::consumeUntilDrained(
size_t* numConsumed) noexcept {
DestructorGuard dg(this);
{
folly::SpinLockGuard g(queue_->spinlock_);
std::unique_lock<SpinLock> g(queue_->spinlock_);
if (queue_->draining_) {
return false;
}
......@@ -825,7 +825,7 @@ bool NotificationQueue<MessageT>::Consumer::consumeUntilDrained(
}
consumeMessages(true, numConsumed);
{
folly::SpinLockGuard g(queue_->spinlock_);
std::unique_lock<SpinLock> g(queue_->spinlock_);
queue_->draining_ = false;
}
return true;
......@@ -840,7 +840,7 @@ void NotificationQueue<MessageT>::SimpleConsumer::consume(F&& foreach) {
std::unique_ptr<Node> data;
{
folly::SpinLockGuard g(queue_.spinlock_);
std::unique_lock<SpinLock> g(queue_.spinlock_);
if (UNLIKELY(queue_.queue_.empty())) {
return;
......
......@@ -40,7 +40,7 @@ DigestT DigestBuilder<DigestT>::build() {
digestPtrs.reserve(cpuLocalBuffers_.size());
for (auto& cpuLocalBuffer : cpuLocalBuffers_) {
SpinLockGuard g(cpuLocalBuffer.mutex);
std::unique_lock<SpinLock> g(cpuLocalBuffer.mutex);
valuesVec.push_back(std::move(cpuLocalBuffer.buffer));
if (cpuLocalBuffer.digest) {
digestPtrs.push_back(std::move(cpuLocalBuffer.digest));
......
......@@ -23,8 +23,6 @@
#include <folly/portability/GMock.h>
#include <folly/portability/GTest.h>
using folly::SpinLockGuardImpl;
namespace {
template <typename LOCK>
......@@ -41,7 +39,7 @@ void spinlockTestThread(LockedVal<LOCK>* v) {
auto rng = folly::ThreadLocalPRNG();
for (int i = 0; i < max; i++) {
folly::asm_volatile_pause();
SpinLockGuardImpl<LOCK> g(v->lock);
std::unique_lock g(v->lock);
EXPECT_THAT(v->ar, testing::Each(testing::Eq(v->ar[0])));
......@@ -64,7 +62,7 @@ void trylockTestThread(TryLockState<LOCK>* state, size_t count) {
while (true) {
folly::asm_volatile_pause();
bool ret = state->lock2.try_lock();
SpinLockGuardImpl<LOCK> g(state->lock1);
std::unique_lock g(state->lock1);
if (state->obtained >= count) {
if (ret) {
state->lock2.unlock();
......
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