Fix issue with incorrect acquisition counts with waits_for dependencies.
authorDavin McCall <davmac@davmac.org>
Tue, 20 Mar 2018 00:11:17 +0000 (00:11 +0000)
committerDavin McCall <davmac@davmac.org>
Tue, 20 Mar 2018 00:11:17 +0000 (00:11 +0000)
src/service.cc

index 9acc09c24ce16ce0f6a24e28e43dd286efe46b30..5095b2c3c3d7ae791be8d53b476561cb1d99f521 100644 (file)
@@ -89,10 +89,14 @@ void service_record::stopped() noexcept
         becoming_inactive();
         
         if (start_explicit) {
+            // If we were explicitly started, our required_by count must be at least 1. Use
+            // release() to correctly release, mark inactive and release dependencies.
             start_explicit = false;
             release();
         }
         else if (required_by == 0) {
+            // This can only be the case if we didn't have start_explicit, since required_by would
+            // otherwise by non-zero.
             services->service_inactive(this);
         }
     }
@@ -146,8 +150,10 @@ void service_record::release_dependencies() noexcept
     for (auto & dependency : depends_on) {
         service_record * dep_to = dependency.get_to();
         if (dependency.holding_acq) {
-            dep_to->release();
+            // We must clear holding_acq before calling release, otherwise the dependency
+            // may decide to stop, check this link and release itself a second time.
             dependency.holding_acq = false;
+            dep_to->release();
         }
     }
 }