Restructure RemoteLibrary and LocalLibrary queries that use

kWaitIndefinite to avoid deadlock.
This commit is contained in:
casey langen 2020-10-31 11:48:25 -07:00
parent 583acbc866
commit 84b2b8738a
2 changed files with 35 additions and 30 deletions

View File

@ -196,27 +196,27 @@ int LocalLibrary::EnqueueAndWait(QueryPtr query, size_t timeoutMs, Callback call
return -1;
}
if (VERBOSE_LOGGING) {
musik::debug::info(TAG, "query '" + localQuery->Name() + "' enqueued");
}
auto context = std::make_shared<QueryContext>();
context->query = localQuery;
context->callback = callback;
if (timeoutMs == kWaitIndefinite) {
this->RunQuery(context);
}
else {
queryQueue.push_back(context);
queueCondition.notify_all();
if (VERBOSE_LOGGING) {
musik::debug::info(TAG, "query '" + localQuery->Name() + "' enqueued");
}
if (timeoutMs > 0) {
while (!this->exit && (
context->query->GetStatus() == db::IQuery::Idle ||
context->query->GetStatus() == db::IQuery::Running)
)
{
if (timeoutMs == kWaitIndefinite) {
this->queueCondition.wait(lock);
}
else {
auto result = this->queueCondition.wait_for(lock, timeoutMs * milliseconds(1));
if (result == std::cv_status::timeout) {
break;

View File

@ -199,6 +199,10 @@ int RemoteLibrary::EnqueueAndWait(QueryPtr query, size_t timeoutMs, Callback cal
context->query = serializableQuery;
context->callback = callback;
if (timeoutMs == kWaitIndefinite) {
this->RunQuery(context);
}
else {
queryQueue.push_back(context);
queueCondition.notify_all();
@ -220,6 +224,7 @@ int RemoteLibrary::EnqueueAndWait(QueryPtr query, size_t timeoutMs, Callback cal
}
}
}
}
return query->GetId();
}