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