# HG changeset patch # User Sebastien Jodogne # Date 1647941024 -3600 # Node ID 3b244557470529bdd4fa1cf4f9f87299bc0b7802 # Parent 05f0327d26c8cd60cc0dbf1ba4963bd34a444792 fix OracleScheduler::SpawnFromQueue() if using cache diff -r 05f0327d26c8 -r 3b2445574705 OrthancStone/Sources/Loaders/OracleScheduler.cpp --- a/OrthancStone/Sources/Loaders/OracleScheduler.cpp Mon Mar 21 16:57:41 2022 +0100 +++ b/OrthancStone/Sources/Loaders/OracleScheduler.cpp Tue Mar 22 10:23:44 2022 +0100 @@ -161,13 +161,15 @@ void OracleScheduler::CheckInvariants() const { +#if 0 + char buf[1024]; + sprintf(buf, "active: %d %d %d ; pending: %lu %lu %lu", + activeHighPriorityCommands_, activeStandardPriorityCommands_, activeLowPriorityCommands_, + highPriorityQueue_.size(), standardPriorityQueue_.size(), lowPriorityQueue_.size()); + LOG(WARNING) << buf; +#endif + #ifndef NDEBUG - /*char buf[1024]; - sprintf(buf, "active: %d %d %d ; pending: %lu %lu %lu", - activeHighPriorityCommands_, activeStandardPriorityCommands_, activeLowPriorityCommands_, - highPriorityQueue_.size(), standardPriorityQueue_.size(), lowPriorityQueue_.size()); - LOG(INFO) << buf;*/ - assert(activeHighPriorityCommands_ <= maxHighPriorityCommands_); assert(activeStandardPriorityCommands_ <= maxStandardPriorityCommands_); assert(activeLowPriorityCommands_ <= maxLowPriorityCommands_); @@ -192,6 +194,32 @@ } + void OracleScheduler::ModifyNumberOfActiveCommands(Priority priority, + int delta) + { + switch (priority) + { + case Priority_High: + assert(static_cast(activeHighPriorityCommands_) + delta >= 0); + activeHighPriorityCommands_ += delta; + break; + + case Priority_Standard: + assert(static_cast(activeStandardPriorityCommands_) + delta >= 0); + activeStandardPriorityCommands_ += delta; + break; + + case Priority_Low: + assert(static_cast(activeLowPriorityCommands_) + delta >= 0); + activeLowPriorityCommands_ += delta; + break; + + default: + throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); + } + } + + void OracleScheduler::SpawnFromQueue(Queue& queue, Priority priority) { @@ -212,6 +240,8 @@ boost::shared_ptr observer(command->GetReceiver().lock()); if (observer) { + ModifyNumberOfActiveCommands(priority, 1); + if (oracle_.Schedule(GetSharedObserver(), command->WrapCommand(priority))) { /** @@ -224,27 +254,11 @@ * "shared_ptr" of the Stone context (check * out "sjo-playground/WebViewer/Backend/Leak") **/ - - switch (priority) - { - case Priority_High: - activeHighPriorityCommands_ ++; - break; - - case Priority_Standard: - activeStandardPriorityCommands_ ++; - break; - - case Priority_Low: - activeLowPriorityCommands_ ++; - break; - - default: - throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); - } } else { + // This is similar to "RemoveActiveCommand()" + ModifyNumberOfActiveCommands(priority, -1); totalProcessed_ ++; } } @@ -320,27 +334,8 @@ totalProcessed_ ++; - switch (payload.GetActivePriority()) - { - case Priority_High: - assert(activeHighPriorityCommands_ > 0); - activeHighPriorityCommands_ --; - break; - - case Priority_Standard: - assert(activeStandardPriorityCommands_ > 0); - activeStandardPriorityCommands_ --; - break; - - case Priority_Low: - assert(activeLowPriorityCommands_ > 0); - activeLowPriorityCommands_ --; - break; - - default: - throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); - } - + ModifyNumberOfActiveCommands(payload.GetActivePriority(), -1); + SpawnCommands(); CheckInvariants(); diff -r 05f0327d26c8 -r 3b2445574705 OrthancStone/Sources/Loaders/OracleScheduler.h --- a/OrthancStone/Sources/Loaders/OracleScheduler.h Mon Mar 21 16:57:41 2022 +0100 +++ b/OrthancStone/Sources/Loaders/OracleScheduler.h Tue Mar 22 10:23:44 2022 +0100 @@ -85,6 +85,9 @@ void CheckInvariants() const; + void ModifyNumberOfActiveCommands(Priority priority, + int delta); + void SpawnFromQueue(Queue& queue, Priority priority);