Add threadpool::queue_size() and synchronyzed_queue::size()
This commit is contained in:
parent
a09eccdf0c
commit
42501ec7c2
2 changed files with 12 additions and 1 deletions
|
|
@ -40,8 +40,10 @@ namespace psemek::util
|
||||||
// e.g. when no new items are going to be pushed
|
// e.g. when no new items are going to be pushed
|
||||||
void wait();
|
void wait();
|
||||||
|
|
||||||
|
std::size_t size() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::mutex mutex;
|
mutable std::mutex mutex;
|
||||||
std::condition_variable push_cv, pop_cv;
|
std::condition_variable push_cv, pop_cv;
|
||||||
std::deque<T> queue;
|
std::deque<T> queue;
|
||||||
std::size_t const max_size_;
|
std::size_t const max_size_;
|
||||||
|
|
@ -144,4 +146,11 @@ namespace psemek::util
|
||||||
push_cv.wait(lock, [this]{ return queue.empty(); });
|
push_cv.wait(lock, [this]{ return queue.empty(); });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
std::size_t synchronized_queue<T>::size() const
|
||||||
|
{
|
||||||
|
std::lock_guard lock{mutex};
|
||||||
|
return queue.size();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -57,6 +57,8 @@ namespace psemek::util
|
||||||
working_count_cv_.wait(lock, [this]{ return working_count_ == 0; });
|
working_count_cv_.wait(lock, [this]{ return working_count_ == 0; });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::size_t queue_size() const { return tasks_queue.size(); }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::string const name;
|
std::string const name;
|
||||||
std::vector<util::thread> threads;
|
std::vector<util::thread> threads;
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue