indexer: fix race condition
It was possible for the worker to stop before the work was even started; and then we might wait forever for the queue to become empty.
This commit is contained in:
@ -198,7 +198,8 @@ Indexer::Private::worker()
|
|||||||
|
|
||||||
g_debug("started worker");
|
g_debug("started worker");
|
||||||
|
|
||||||
while (state_ == IndexState::Scanning || !fq_.empty()) {
|
while (state_ == IndexState::Scanning) {
|
||||||
|
|
||||||
if (!fq_.pop(item, 250ms))
|
if (!fq_.pop(item, 250ms))
|
||||||
continue;
|
continue;
|
||||||
try {
|
try {
|
||||||
@ -261,9 +262,12 @@ Indexer::Private::start(const Indexer::Config& conf)
|
|||||||
conf_.scan ? "yes" : "no",
|
conf_.scan ? "yes" : "no",
|
||||||
conf_.cleanup ? "yes" : "no");
|
conf_.cleanup ? "yes" : "no");
|
||||||
|
|
||||||
workers_.emplace_back(std::thread([this] { worker(); }));
|
|
||||||
|
|
||||||
state_.change_to(IndexState::Scanning);
|
state_.change_to(IndexState::Scanning);
|
||||||
|
{
|
||||||
|
/* kick off the first worker, which will spawn more if needed. */
|
||||||
|
std::lock_guard<std::mutex> wlock{wlock_};
|
||||||
|
workers_.emplace_back(std::thread([this] { worker(); }));
|
||||||
|
}
|
||||||
scanner_worker_ = std::thread([this] {
|
scanner_worker_ = std::thread([this] {
|
||||||
progress_ = {};
|
progress_ = {};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user