mirror of
https://github.com/clangen/musikcube.git
synced 2025-01-28 18:32:38 +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) {
|
if (this->thread) {
|
||||||
thread = this->thread;
|
thread = this->thread;
|
||||||
this->thread = nullptr;
|
this->thread = nullptr;
|
||||||
this->exit = true;
|
|
||||||
this->queryQueue.clear();
|
this->queryQueue.clear();
|
||||||
this->Exit();
|
this->exit = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (thread) {
|
if (thread) {
|
||||||
|
this->queueCondition.notify_all();
|
||||||
thread->join();
|
thread->join();
|
||||||
delete thread;
|
delete thread;
|
||||||
}
|
}
|
||||||
@ -186,42 +186,30 @@ int LocalLibrary::Enqueue(IQueryPtr query, unsigned int options) {
|
|||||||
return -1;
|
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() {
|
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();
|
LocalQueryPtr front = queryQueue.front();
|
||||||
queryQueue.pop_front();
|
queryQueue.pop_front();
|
||||||
return 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) {
|
void LocalLibrary::RunQuery(LocalQueryPtr query, bool notify) {
|
||||||
|
@ -94,8 +94,6 @@ namespace musik { namespace core { namespace library {
|
|||||||
LocalLibrary(std::string name, int id); /* ctor */
|
LocalLibrary(std::string name, int id); /* ctor */
|
||||||
|
|
||||||
void RunQuery(LocalQueryPtr query, bool notify = true);
|
void RunQuery(LocalQueryPtr query, bool notify = true);
|
||||||
virtual void Exit();
|
|
||||||
bool Exited();
|
|
||||||
void ThreadProc();
|
void ThreadProc();
|
||||||
LocalQueryPtr GetNextQuery();
|
LocalQueryPtr GetNextQuery();
|
||||||
|
|
||||||
@ -106,11 +104,11 @@ namespace musik { namespace core { namespace library {
|
|||||||
std::string identifier;
|
std::string identifier;
|
||||||
int id;
|
int id;
|
||||||
std::string name;
|
std::string name;
|
||||||
bool exit;
|
|
||||||
|
|
||||||
std::thread* thread;
|
std::thread* thread;
|
||||||
std::condition_variable queueCondition;
|
std::condition_variable queueCondition;
|
||||||
std::mutex mutex;
|
std::mutex mutex;
|
||||||
|
std::atomic<bool> exit;
|
||||||
|
|
||||||
core::IIndexer *indexer;
|
core::IIndexer *indexer;
|
||||||
core::db::Connection db;
|
core::db::Connection db;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user