diff options
| author | Martin Ridgers <[email protected]> | 2021-11-30 17:02:21 +0100 |
|---|---|---|
| committer | Martin Ridgers <[email protected]> | 2021-11-30 17:02:21 +0100 |
| commit | 75e53ead9f7195b33a4956f1d30f65ed034764d6 (patch) | |
| tree | 32f0c478d48392b978270c5ddcce58d058fdf6d8 /zenserver/upstream/upstreamapply.cpp | |
| parent | Merge pull request #30 from EpicGames/non-elevated-asio (diff) | |
| parent | Wait on an event instead of using sleep() (diff) | |
| download | zen-75e53ead9f7195b33a4956f1d30f65ed034764d6.tar.xz zen-75e53ead9f7195b33a4956f1d30f65ed034764d6.zip | |
Merge remote-tracking branch 'origin/ridgers-pr' into main
Diffstat (limited to 'zenserver/upstream/upstreamapply.cpp')
| -rw-r--r-- | zenserver/upstream/upstreamapply.cpp | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/zenserver/upstream/upstreamapply.cpp b/zenserver/upstream/upstreamapply.cpp index 0118902a6..1779099ff 100644 --- a/zenserver/upstream/upstreamapply.cpp +++ b/zenserver/upstream/upstreamapply.cpp @@ -14,6 +14,7 @@ #include <zencore/session.h> #include <zencore/stats.h> #include <zencore/stream.h> +#include <zencore/thread.h> #include <zencore/timer.h> #include <zenstore/cas.h> @@ -1199,6 +1200,8 @@ public: if (m_RunState.IsRunning) { + m_ShutdownEvent.Reset(); + for (uint32_t Idx = 0; Idx < m_Options.ThreadCount; Idx++) { m_UpstreamThreads.emplace_back(&DefaultUpstreamApply::ProcessUpstreamQueue, this); @@ -1422,11 +1425,9 @@ private: void ProcessUpstreamUpdates() { - const auto& UpdateSleep = std::chrono::seconds(m_Options.UpdatesInterval); - for (;;) + const auto& UpdateSleep = std::chrono::milliseconds(m_Options.UpdatesInterval); + while (!m_ShutdownEvent.Wait(uint32_t(UpdateSleep.count()))) { - std::this_thread::sleep_for(UpdateSleep); - if (!m_RunState.IsRunning) { break; @@ -1489,6 +1490,8 @@ private: { if (m_RunState.Stop()) { + m_ShutdownEvent.Set(); + m_UpstreamQueue.CompleteAdding(); for (std::thread& Thread : m_UpstreamThreads) { @@ -1536,6 +1539,7 @@ private: UpstreamApplyTasks m_ApplyTasks; std::mutex m_ApplyTasksMutex; std::vector<std::unique_ptr<UpstreamApplyEndpoint>> m_Endpoints; + Event m_ShutdownEvent; std::vector<std::thread> m_UpstreamThreads; std::thread m_UpstreamUpdatesThread; std::thread m_EndpointMonitorThread; |