+ // Add a service record to the start queue
+ void addToStartQueue(ServiceRecord *service) noexcept
+ {
+ if (service->next_in_start_queue == nullptr && first_start_queue != service) {
+ service->next_in_start_queue = first_start_queue;
+ first_start_queue = service;
+ }
+ }
+
+ // Add a service to the stop queue
+ void addToStopQueue(ServiceRecord *service) noexcept
+ {
+ if (service->next_in_stop_queue == nullptr && first_stop_queue != service) {
+ service->next_in_stop_queue = first_stop_queue;
+ first_stop_queue = service;
+ }
+ }
+
+ void processQueues(bool do_start_first) noexcept
+ {
+ if (! do_start_first) {
+ while (first_stop_queue != nullptr) {
+ auto next = first_stop_queue;
+ first_stop_queue = next->next_in_stop_queue;
+ next->next_in_stop_queue = nullptr;
+ next->do_stop();
+ }
+ }
+
+ while (first_stop_queue != nullptr || first_start_queue != nullptr) {
+ while (first_start_queue != nullptr) {
+ auto next = first_start_queue;
+ first_start_queue = next->next_in_start_queue;
+ next->next_in_start_queue = nullptr;
+ next->do_start();
+ }
+ while (first_stop_queue != nullptr) {
+ auto next = first_stop_queue;
+ first_stop_queue = next->next_in_stop_queue;
+ next->next_in_stop_queue = nullptr;
+ next->do_stop();
+ }
+ }
+ }
+