Commit 4e12f97c authored by Dave Watson's avatar Dave Watson Committed by Facebook Github Bot

Drop read lock from getPendingTaskCountImpl

Summary: Need to also allow calling this function with a writeLock.

Reviewed By: magedm

Differential Revision: D7477326

fbshipit-source-id: 403e2667a3f77be4c1d7d06dbd5f36218a659abc
parent d0bddaa0
...@@ -153,8 +153,7 @@ void CPUThreadPoolExecutor::stopThreads(size_t n) { ...@@ -153,8 +153,7 @@ void CPUThreadPoolExecutor::stopThreads(size_t n) {
} }
// threadListLock_ is readlocked // threadListLock_ is readlocked
uint64_t CPUThreadPoolExecutor::getPendingTaskCountImpl( uint64_t CPUThreadPoolExecutor::getPendingTaskCountImpl() {
const folly::RWSpinLock::ReadHolder&) {
return taskQueue_->size(); return taskQueue_->size();
} }
......
...@@ -131,7 +131,7 @@ class CPUThreadPoolExecutor : public ThreadPoolExecutor { ...@@ -131,7 +131,7 @@ class CPUThreadPoolExecutor : public ThreadPoolExecutor {
private: private:
void threadRun(ThreadPtr thread) override; void threadRun(ThreadPtr thread) override;
void stopThreads(size_t n) override; void stopThreads(size_t n) override;
uint64_t getPendingTaskCountImpl(const RWSpinLock::ReadHolder&) override; uint64_t getPendingTaskCountImpl() override;
std::unique_ptr<BlockingQueue<CPUTask>> taskQueue_; std::unique_ptr<BlockingQueue<CPUTask>> taskQueue_;
std::atomic<ssize_t> threadsToStop_{0}; std::atomic<ssize_t> threadsToStop_{0};
......
...@@ -203,8 +203,7 @@ void IOThreadPoolExecutor::stopThreads(size_t n) { ...@@ -203,8 +203,7 @@ void IOThreadPoolExecutor::stopThreads(size_t n) {
} }
// threadListLock_ is readlocked // threadListLock_ is readlocked
uint64_t IOThreadPoolExecutor::getPendingTaskCountImpl( uint64_t IOThreadPoolExecutor::getPendingTaskCountImpl() {
const folly::RWSpinLock::ReadHolder&) {
uint64_t count = 0; uint64_t count = 0;
for (const auto& thread : threadList_.get()) { for (const auto& thread : threadList_.get()) {
auto ioThread = std::static_pointer_cast<IOThread>(thread); auto ioThread = std::static_pointer_cast<IOThread>(thread);
......
...@@ -87,7 +87,7 @@ class IOThreadPoolExecutor : public ThreadPoolExecutor, public IOExecutor { ...@@ -87,7 +87,7 @@ class IOThreadPoolExecutor : public ThreadPoolExecutor, public IOExecutor {
std::shared_ptr<IOThread> pickThread(); std::shared_ptr<IOThread> pickThread();
void threadRun(ThreadPtr thread) override; void threadRun(ThreadPtr thread) override;
void stopThreads(size_t n) override; void stopThreads(size_t n) override;
uint64_t getPendingTaskCountImpl(const RWSpinLock::ReadHolder&) override; uint64_t getPendingTaskCountImpl() override;
std::atomic<size_t> nextThread_; std::atomic<size_t> nextThread_;
folly::ThreadLocal<std::shared_ptr<IOThread>> thisThread_; folly::ThreadLocal<std::shared_ptr<IOThread>> thisThread_;
......
...@@ -187,14 +187,14 @@ ThreadPoolExecutor::PoolStats ThreadPoolExecutor::getPoolStats() { ...@@ -187,14 +187,14 @@ ThreadPoolExecutor::PoolStats ThreadPoolExecutor::getPoolStats() {
stats.activeThreadCount++; stats.activeThreadCount++;
} }
} }
stats.pendingTaskCount = getPendingTaskCountImpl(r); stats.pendingTaskCount = getPendingTaskCountImpl();
stats.totalTaskCount = stats.pendingTaskCount + stats.activeThreadCount; stats.totalTaskCount = stats.pendingTaskCount + stats.activeThreadCount;
return stats; return stats;
} }
uint64_t ThreadPoolExecutor::getPendingTaskCount() { uint64_t ThreadPoolExecutor::getPendingTaskCount() {
RWSpinLock::ReadHolder r{&threadListLock_}; RWSpinLock::ReadHolder r{&threadListLock_};
return getPendingTaskCountImpl(r); return getPendingTaskCountImpl();
} }
std::atomic<uint64_t> ThreadPoolExecutor::Thread::nextId(0); std::atomic<uint64_t> ThreadPoolExecutor::Thread::nextId(0);
......
...@@ -185,8 +185,8 @@ class ThreadPoolExecutor : public virtual folly::Executor { ...@@ -185,8 +185,8 @@ class ThreadPoolExecutor : public virtual folly::Executor {
return std::make_shared<Thread>(this); return std::make_shared<Thread>(this);
} }
// Prerequisite: threadListLock_ readlocked // Prerequisite: threadListLock_ readlocked or writelocked
virtual uint64_t getPendingTaskCountImpl(const RWSpinLock::ReadHolder&) = 0; virtual uint64_t getPendingTaskCountImpl() = 0;
class ThreadList { class ThreadList {
public: public:
......
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