mirror of
https://github.com/clangen/musikcube.git
synced 2025-01-15 19:52:19 +00:00
This deadlock on shutdown still wasn't fixed? Dang. Should be fine now.
This commit is contained in:
parent
b81488400e
commit
473eeab381
@ -125,13 +125,13 @@ void LocalLibrary::Close() {
|
||||
if (this->thread) {
|
||||
thread = this->thread;
|
||||
this->thread = nullptr;
|
||||
this->exit = true;
|
||||
this->queryQueue.clear();
|
||||
this->Exit();
|
||||
this->exit = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (thread) {
|
||||
this->queueCondition.notify_all();
|
||||
thread->join();
|
||||
delete thread;
|
||||
}
|
||||
@ -186,42 +186,30 @@ int LocalLibrary::Enqueue(IQueryPtr query, unsigned int options) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
bool LocalLibrary::Exited() {
|
||||
return this->exit;
|
||||
}
|
||||
|
||||
void LocalLibrary::Exit() {
|
||||
this->exit = true;
|
||||
this->queueCondition.notify_all();
|
||||
}
|
||||
|
||||
void LocalLibrary::ThreadProc() {
|
||||
LocalQueryPtr query;
|
||||
|
||||
while (true) {
|
||||
if ((query = GetNextQuery())) {
|
||||
this->RunQuery(query);
|
||||
}
|
||||
|
||||
if (!this->queryQueue.size() && !this->Exited()) {
|
||||
std::unique_lock<std::mutex> lock(this->mutex);
|
||||
this->queueCondition.wait(lock);
|
||||
}
|
||||
|
||||
if (this->Exited()) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
LocalLibrary::LocalQueryPtr LocalLibrary::GetNextQuery() {
|
||||
if (queryQueue.size()) {
|
||||
std::unique_lock<std::mutex> lock(this->mutex);
|
||||
while (!this->queryQueue.size() && !this->exit) {
|
||||
this->queueCondition.wait(lock);
|
||||
}
|
||||
|
||||
if (this->exit) {
|
||||
return LocalQueryPtr();
|
||||
}
|
||||
else {
|
||||
LocalQueryPtr front = queryQueue.front();
|
||||
queryQueue.pop_front();
|
||||
return front;
|
||||
}
|
||||
}
|
||||
|
||||
return LocalQueryPtr();
|
||||
void LocalLibrary::ThreadProc() {
|
||||
while (!this->exit) {
|
||||
LocalQueryPtr query = GetNextQuery();
|
||||
if (query) {
|
||||
this->RunQuery(query);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void LocalLibrary::RunQuery(LocalQueryPtr query, bool notify) {
|
||||
|
@ -94,8 +94,6 @@ namespace musik { namespace core { namespace library {
|
||||
LocalLibrary(std::string name, int id); /* ctor */
|
||||
|
||||
void RunQuery(LocalQueryPtr query, bool notify = true);
|
||||
virtual void Exit();
|
||||
bool Exited();
|
||||
void ThreadProc();
|
||||
LocalQueryPtr GetNextQuery();
|
||||
|
||||
@ -106,11 +104,11 @@ namespace musik { namespace core { namespace library {
|
||||
std::string identifier;
|
||||
int id;
|
||||
std::string name;
|
||||
bool exit;
|
||||
|
||||
std::thread* thread;
|
||||
std::condition_variable queueCondition;
|
||||
std::mutex mutex;
|
||||
std::atomic<bool> exit;
|
||||
|
||||
core::IIndexer *indexer;
|
||||
core::db::Connection db;
|
||||
|
Loading…
Reference in New Issue
Block a user