From: Lee Howes <lwh@fb.com>
Date: Wed, 19 Oct 2016 15:34:20 +0000 (-0700)
Subject: Add capacity to semaphore so that initial size can be queried later.
X-Git-Tag: v2016.10.24.00~12
X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=61b06488fdf7c9a64771adff73a23c65715c5676;p=folly.git

Add capacity to semaphore so that initial size can be queried later.

Reviewed By: yfeldblum

Differential Revision: D4035412

fbshipit-source-id: 4b7a178088d2950f9f042e0c79b54b3982eb43f5
---

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<int64_t> tokens_;
   folly::Synchronized<std::queue<folly::fibers::Baton*>> waitList_;