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

View File

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