mirror of
https://github.com/clangen/musikcube.git
synced 2025-01-16 04:14:05 +00:00
Restructure RemoteLibrary and LocalLibrary queries that use
kWaitIndefinite to avoid deadlock.
This commit is contained in:
parent
583acbc866
commit
84b2b8738a
@ -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;
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user