summaryrefslogtreecommitdiff
path: root/lib/worker.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'lib/worker.cpp')
-rw-r--r--lib/worker.cpp21
1 files changed, 21 insertions, 0 deletions
diff --git a/lib/worker.cpp b/lib/worker.cpp
index 7e7f296..45fb6df 100644
--- a/lib/worker.cpp
+++ b/lib/worker.cpp
@@ -42,3 +42,24 @@ Worker::worker()
j->doWork();
}
}
+
+void
+Worker::assist()
+{
+ auto job = [this]() {
+ using namespace std::chrono_literals;
+ if (todoLen.try_acquire_for(100us)) {
+ if (std::lock_guard<std::mutex> lck {todoMutex}; todo.size()) {
+ WorkPtr x = std::move(todo.front());
+ if (x) {
+ todo.pop_front();
+ }
+ return x;
+ }
+ }
+ return WorkPtr {};
+ };
+ if (auto j = job()) {
+ j->doWork();
+ }
+}