Skip to content
This repository has been archived by the owner on Nov 18, 2022. It is now read-only.

Commit

Permalink
Pause DoMainLoop until stop/reload signal in daemon mode
Browse files Browse the repository at this point in the history
When in deamon mode, just wait for the Stop signal instead of looping
constantly, in a way that doesn't affect responsiveness.
  • Loading branch information
fedux committed Jan 3, 2019
1 parent 49e8fea commit 794f240
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
13 changes: 13 additions & 0 deletions daemon/main/nzbget.cpp
Expand Up @@ -223,6 +223,7 @@ class NZBGet : public Options::Extender

bool m_reloading = false;
bool m_daemonized = false;
std::promise<void> m_stopSignal;

void Init();
void Final();
Expand Down Expand Up @@ -652,6 +653,7 @@ void NZBGet::DoMainLoop()
}

// enter main program-loop
int stopSignalReceived = false;
while (m_queueCoordinator->IsRunning() ||
m_urlCoordinator->IsRunning() ||
m_prePostProcessor->IsRunning() ||
Expand Down Expand Up @@ -694,6 +696,14 @@ void NZBGet::DoMainLoop()
}
}
usleep(100 * 1000);

if (m_options->GetServerMode() && !stopSignalReceived)
{
// wait for stop signal
std::future<void> futureStop = m_stopSignal.get_future();
futureStop.wait();
stopSignalReceived = true;
}
}

debug("Main program loop terminated");
Expand Down Expand Up @@ -896,6 +906,9 @@ void NZBGet::Stop(bool reload)
#endif
}
}

// trigger stop/reload signal
m_stopSignal.set_value();
}

void NZBGet::PrintOptions()
Expand Down
1 change: 1 addition & 0 deletions daemon/main/nzbget.h
Expand Up @@ -225,6 +225,7 @@ using namespace MSXML;
#include <mutex>
#include <atomic>
#include <thread>
#include <future>

// NOTE: do not include <iostream> in "nzbget.h". <iostream> contains objects requiring
// intialization, causing every unit in nzbget to have initialization routine. This in particular
Expand Down

0 comments on commit 794f240

Please sign in to comment.