Fixed a deadlock on shutdown introduced in the previous commit.

This commit is contained in:
casey langen 2016-10-21 21:19:21 -07:00
parent 144e5eeadc
commit 0e11128d0c
3 changed files with 8 additions and 14 deletions

View File

@ -98,6 +98,7 @@ Indexer::~Indexer() {
this->exit = true;
}
this->waitCondition.notify_all();
this->thread->join();
delete this->thread;
this->thread = nullptr;
@ -107,7 +108,7 @@ Indexer::~Indexer() {
void Indexer::Synchronize(bool restart) {
boost::mutex::scoped_lock lock(this->stateMutex);
this->restart = restart;
this->Notify();
this->waitCondition.notify_all();
}
void Indexer::AddPath(const std::string& path) {
@ -407,12 +408,12 @@ void Indexer::ThreadLoop() {
waitTimeout.sec += waitTime;
if (!this->Restarted()) {
this->NotificationTimedWait(waitTimeout);
this->Wait(waitTimeout);
}
}
else {
if (!this->Restarted()) {
this->NotificationWait(); /* zzz */
this->Wait(); /* zzz */
}
}
}
@ -689,20 +690,16 @@ bool Indexer::Exited() {
return this->exit;
}
void Indexer::NotificationWait() {
void Indexer::Wait() {
boost::mutex::scoped_lock lock(this->stateMutex);
if (!this->exit) {
this->waitCondition.wait(lock);
}
}
void Indexer::NotificationTimedWait(const boost::xtime &time) {
void Indexer::Wait(const boost::xtime &time) {
boost::mutex::scoped_lock lock(this->stateMutex);
if (!this->exit) {
this->waitCondition.timed_wait(lock, time);
}
}
void Indexer::Notify() {
this->waitCondition.notify_all();
}

View File

@ -71,9 +71,8 @@ namespace musik { namespace core {
void ThreadLoop();
bool Exited();
void NotificationWait();
void NotificationTimedWait(const boost::xtime &oTime);
void Notify();
void Wait();
void Wait(const boost::xtime &oTime);
bool Restarted();

View File

@ -47,8 +47,6 @@ namespace cursespp {
virtual void SetWidth(size_t width);
virtual int64 GetAttrs(size_t line);
void SetAttrs(int64 attrs);
private:
std::string value;
std::vector<std::string> lines;