From c918fea26cf47d603fdb34b3e0310cdeabfd7079 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Ha=C5=82as?= Date: Thu, 23 Nov 2017 23:08:02 +0100 Subject: [PATCH] quic fix --- src/WatchDog.cpp | 8 ++++++++ src/WatchDog.h | 1 + 2 files changed, 9 insertions(+) diff --git a/src/WatchDog.cpp b/src/WatchDog.cpp index e75c1a9..a33b41e 100644 --- a/src/WatchDog.cpp +++ b/src/WatchDog.cpp @@ -43,6 +43,14 @@ namespace crazygoat::shepherd { } std::shared_ptr WatchDog::getFreeWorker() { + std::future > fWorker = std::async(&WatchDog::workerIterator, this); + + while (fWorker.wait_for(std::chrono::microseconds(5)) != std::future_status::ready) {} + + return fWorker.get(); + } + + std::shared_ptr WatchDog::workerIterator() { do { auto worker = this->workers[(++this->requestsCount) % this->count]; if (!worker->isIsWorking()) { diff --git a/src/WatchDog.h b/src/WatchDog.h index d5a5bdf..1bad4ee 100644 --- a/src/WatchDog.h +++ b/src/WatchDog.h @@ -19,6 +19,7 @@ namespace crazygoat::shepherd { unsigned int requestsCount; std::vector > workers; std::shared_ptr timer; + std::shared_ptr workerIterator(); void watch(); public: