if (getMode() && !inside) {
if (getThreadPoolSize()) {
// We simply pause without waiting for all tasks to complete.
- // We could also call pause(false) which does not wait for
- // threads to stop and wait() so that all tasks are complete
- // and threads are stopped.
+ // We could also call wait() and pause(false) so that all tasks are
+ // complete and threads are stopped.
thread_pool_.pause();
}
// Now it is safe to call callbacks which can also create other CSs.
--critical_section_count_;
if (getMode() && !isInCriticalSection()) {
if (getThreadPoolSize()) {
- thread_pool_.resume();
+ // If apply has been called, threads have never been started inside
+ // a critical section, so start them now, otherwise just resume
+ // paused threads.
+ if (!thread_pool_.enabled()) {
+ thread_pool_.start(getThreadPoolSize());
+ } else {
+ thread_pool_.resume();
+ }
}
// Now it is safe to call callbacks which can also create other CSs.
callExitCallbacks();
///
/// @return True if the pool is running, false otherwise.
bool isThreadPoolRunning() {
- return (MultiThreadingMgr::instance().getThreadPool().size());
+ return (!MultiThreadingMgr::instance().getThreadPool().paused());
}
/// @brief Checks callback invocations over a series of nested
ASSERT_EQ(thread_pool.count(), 0);
// the thread count should be 0
ASSERT_EQ(thread_pool.size(), 0);
->>>>>>> 0d7199fdd8 ([#1599] implemented pause and resume)
}
/// @brief test ThreadPool max queue size
queue_.resume();
}
+ /// @brief return the state of the queue
+ ///
+ /// Returns the state of the queue
+ ///
+ /// @return the state
+ bool enabled() {
+ return (queue_.enabled());
+ }
+
+ /// @brief return the state of the threads
+ ///
+ /// Returns the state of the threads
+ ///
+ /// @return the state
+ bool paused() {
+ return (queue_.paused());
+ }
+
/// @brief set maximum number of work items in the queue
///
/// @param max_queue_size the maximum size (0 means unlimited)
void disable() {
{
std::lock_guard<std::mutex> lock(mutex_);
+ paused_ = false;
enabled_ = false;
}
// Notify pop so that it can exit.
+ pause_cv_.notify_all();
cv_.notify_all();
}
return (enabled_);
}
+ /// @brief return the state of the threads
+ ///
+ /// Returns the state of the threads
+ ///
+ /// @return the state
+ bool paused() {
+ return (paused_);
+ }
+
private:
/// @brief underlying queue container
QueueContainer queue_;