From 61b06488fdf7c9a64771adff73a23c65715c5676 Mon Sep 17 00:00:00 2001 From: Lee Howes Date: Wed, 19 Oct 2016 08:34:20 -0700 Subject: [PATCH] Add capacity to semaphore so that initial size can be queried later. Reviewed By: yfeldblum Differential Revision: D4035412 fbshipit-source-id: 4b7a178088d2950f9f042e0c79b54b3982eb43f5 --- folly/fibers/Semaphore.cpp | 4 ++++ folly/fibers/Semaphore.h | 6 +++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/folly/fibers/Semaphore.cpp b/folly/fibers/Semaphore.cpp index 40efae3f..63c71e21 100644 --- a/folly/fibers/Semaphore.cpp +++ b/folly/fibers/Semaphore.cpp @@ -90,5 +90,9 @@ void Semaphore::wait() { std::memory_order_acquire)); } +size_t Semaphore::getCapacity() const { + return capacity_; +} + } // namespace fibers } // namespace folly diff --git a/folly/fibers/Semaphore.h b/folly/fibers/Semaphore.h index 24e5707c..047abee8 100644 --- a/folly/fibers/Semaphore.h +++ b/folly/fibers/Semaphore.h @@ -27,7 +27,8 @@ namespace fibers { */ class Semaphore { public: - explicit Semaphore(size_t tokenCount) : tokens_(tokenCount) {} + explicit Semaphore(size_t tokenCount) + : capacity_(tokenCount), tokens_(capacity_) {} Semaphore(const Semaphore&) = delete; Semaphore(Semaphore&&) = delete; @@ -44,10 +45,13 @@ class Semaphore { */ void wait(); + size_t getCapacity() const; + private: bool waitSlow(); bool signalSlow(); + size_t capacity_; // Atomic counter std::atomic tokens_; folly::Synchronized> waitList_; -- 2.34.1