summaryrefslogtreecommitdiff
path: root/lib/worker.h
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2021-02-20 15:00:02 +0000
committerDan Goodliffe <dan@randomdan.homeip.net>2021-02-20 15:00:02 +0000
commitfe38b38725d9d639f0e09f444e746c0bf2f8dc10 (patch)
tree2d3e185f41c71d064f7c805c080600bf29e0aa93 /lib/worker.h
parentRemove unused worker from main (diff)
downloadilt-fe38b38725d9d639f0e09f444e746c0bf2f8dc10.tar.bz2
ilt-fe38b38725d9d639f0e09f444e746c0bf2f8dc10.tar.xz
ilt-fe38b38725d9d639f0e09f444e746c0bf2f8dc10.zip
Add a non-threaded worker
Runs work immediately for when compiler doesn't support C++20 semaphore
Diffstat (limited to 'lib/worker.h')
-rw-r--r--lib/worker.h29
1 files changed, 22 insertions, 7 deletions
diff --git a/lib/worker.h b/lib/worker.h
index 5a13138..04e351b 100644
--- a/lib/worker.h
+++ b/lib/worker.h
@@ -1,14 +1,16 @@
#ifndef WORKER_H
#define WORKER_H
-#include <deque>
-#include <memory>
-#include <mutex>
-#include <semaphore>
-#include <special_members.hpp>
-#include <thread>
#include <utility>
-#include <vector>
+
+#if __cpp_lib_semaphore
+# include <deque>
+# include <memory>
+# include <mutex>
+# include <semaphore>
+# include <special_members.hpp>
+# include <thread>
+# include <vector>
class Work;
@@ -43,4 +45,17 @@ private:
std::mutex todoMutex;
};
+#else
+
+class Worker {
+public:
+ template<typename T, typename... Params>
+ void
+ addWork(Params &&... params)
+ {
+ T(std::forward<Params>(params)...).doWork();
+ }
+};
+
+#endif
#endif