Skip to content

Commit

Permalink
add isEmpty() method to and fix bug in Ocean::ThreadPool
Browse files Browse the repository at this point in the history
Reviewed By: janherling

Differential Revision: D67174302

fbshipit-source-id: 1201715719507ffa5d803de656c82f05ec353d4a
  • Loading branch information
ASchneiderMeta authored and facebook-github-bot committed Dec 13, 2024
1 parent 2dba831 commit 797d6d3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion impl/ocean/base/ThreadPool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ void ThreadPool::threadRun()
}
}

while (capacity_ < busyPoolThreads_.size() + idlePoolThreads_.size() && idlePoolThreads_.empty())
while (capacity_ < busyPoolThreads_.size() + idlePoolThreads_.size() && !idlePoolThreads_.empty())
{
// we have an idle pool thread and we have more threads than the specified capacity (e.g., because the capacity has been reduced lately)

Expand Down
13 changes: 13 additions & 0 deletions impl/ocean/base/ThreadPool.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,12 @@ class OCEAN_BASE_EXPORT ThreadPool : protected Thread
*/
inline size_t pending() const;

/**
* Returns whether the ThreadPool has completed all jobs that have been submitted
* @return True, if the results of size() and pending() are atomically both 0
*/
inline bool isEmpty() const;

protected:

/**
Expand Down Expand Up @@ -220,6 +226,13 @@ inline size_t ThreadPool::pending() const
return pendingFunctions_.size();
}

inline bool ThreadPool::isEmpty() const
{
const ScopedLock scopedLock(lock_);

return (pendingFunctions_.size() + busyPoolThreads_.size()) == 0;
}

}

#endif // META_OCEAN_BASE_THREAD_POOL_H

0 comments on commit 797d6d3

Please sign in to comment.