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;
}
auto context = std::make_shared<QueryContext>();
context->query = localQuery;
context->callback = callback;
queryQueue.push_back(context);
queueCondition.notify_all();
if (VERBOSE_LOGGING) {
musik::debug::info(TAG, "query '" + localQuery->Name() + "' enqueued");
}
if (timeoutMs > 0) {
while (!this->exit && (
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 (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,24 +199,29 @@ int RemoteLibrary::EnqueueAndWait(QueryPtr query, size_t timeoutMs, Callback cal
context->query = serializableQuery;
context->callback = callback;
queryQueue.push_back(context);
queueCondition.notify_all();
if (timeoutMs == kWaitIndefinite) {
this->RunQuery(context);
}
else {
queryQueue.push_back(context);
queueCondition.notify_all();
if (timeoutMs > 0) {
while (
!this->exit &&
this->IsQueryInFlight(context->query) &&
!isQueryDone(context->query))
{
if (timeoutMs == kWaitIndefinite) {
this->syncQueryCondition.wait(lock);
break;
}
else {
auto result = this->syncQueryCondition.wait_for(lock, timeoutMs * milliseconds(1));
if (result == std::cv_status::timeout) {
if (timeoutMs > 0) {
while (
!this->exit &&
this->IsQueryInFlight(context->query) &&
!isQueryDone(context->query))
{
if (timeoutMs == kWaitIndefinite) {
this->syncQueryCondition.wait(lock);
break;
}
else {
auto result = this->syncQueryCondition.wait_for(lock, timeoutMs * milliseconds(1));
if (result == std::cv_status::timeout) {
break;
}
}
}
}
}