Commit a463b55e authored by Yedidya Feldblum's avatar Yedidya Feldblum Committed by Facebook Github Bot

Use size_t for ThreadPoolExecutor::getPendingTaskCountImpl

Summary:
[Folly] Use `size_t` for `ThreadPoolExecutor::getPendingTaskCountImpl`, as it is the canonical size type for counting the number of entries in in-memory data structures.

Prevents confusion when using values returned from this function with other sizes, especially in contexts where the two types are required to match as might occur in calls to `std::min` without explicitly specifying the type.

Fixes #843.

Reviewed By: djwatson

Differential Revision: D7898443

fbshipit-source-id: eec789f661351d09545bc7118f2e4b3587fd7302
parent 82a8271d
......@@ -215,7 +215,7 @@ void CPUThreadPoolExecutor::stopThreads(size_t n) {
}
// threadListLock_ is read (or write) locked.
uint64_t CPUThreadPoolExecutor::getPendingTaskCountImpl() {
size_t CPUThreadPoolExecutor::getPendingTaskCountImpl() {
return taskQueue_->size();
}
......
......@@ -139,7 +139,7 @@ class CPUThreadPoolExecutor : public ThreadPoolExecutor,
private:
void threadRun(ThreadPtr thread) override;
void stopThreads(size_t n) override;
uint64_t getPendingTaskCountImpl() override;
size_t getPendingTaskCountImpl() override;
bool tryDecrToStop();
bool taskShouldStop(folly::Optional<CPUTask>&);
......
......@@ -206,8 +206,8 @@ void IOThreadPoolExecutor::stopThreads(size_t n) {
}
// threadListLock_ is readlocked
uint64_t IOThreadPoolExecutor::getPendingTaskCountImpl() {
uint64_t count = 0;
size_t IOThreadPoolExecutor::getPendingTaskCountImpl() {
size_t count = 0;
for (const auto& thread : threadList_.get()) {
auto ioThread = std::static_pointer_cast<IOThread>(thread);
size_t pendingTasks = ioThread->pendingTasks;
......
......@@ -90,7 +90,7 @@ class IOThreadPoolExecutor : public ThreadPoolExecutor,
std::shared_ptr<IOThread> pickThread();
void threadRun(ThreadPtr thread) override;
void stopThreads(size_t n) override;
uint64_t getPendingTaskCountImpl() override;
size_t getPendingTaskCountImpl() override;
std::atomic<size_t> nextThread_;
folly::ThreadLocal<std::shared_ptr<IOThread>> thisThread_;
......
......@@ -277,7 +277,7 @@ ThreadPoolExecutor::PoolStats ThreadPoolExecutor::getPoolStats() {
return stats;
}
uint64_t ThreadPoolExecutor::getPendingTaskCount() {
size_t ThreadPoolExecutor::getPendingTaskCount() {
RWSpinLock::ReadHolder r{&threadListLock_};
return getPendingTaskCountImpl();
}
......
......@@ -218,7 +218,7 @@ class ThreadPoolExecutor : public virtual folly::Executor {
}
// Prerequisite: threadListLock_ readlocked or writelocked
virtual uint64_t getPendingTaskCountImpl() = 0;
virtual size_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