From fe38b38725d9d639f0e09f444e746c0bf2f8dc10 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sat, 20 Feb 2021 15:00:02 +0000 Subject: Add a non-threaded worker Runs work immediately for when compiler doesn't support C++20 semaphore --- lib/worker.cpp | 10 ++++++---- lib/worker.h | 29 ++++++++++++++++++++++------- 2 files changed, 28 insertions(+), 11 deletions(-) (limited to 'lib') diff --git a/lib/worker.cpp b/lib/worker.cpp index 3c12caa..fd255c7 100644 --- a/lib/worker.cpp +++ b/lib/worker.cpp @@ -1,8 +1,9 @@ #include "worker.h" -#include "work.h" -#include -#include -#include +#if __cpp_lib_semaphore +# include "work.h" +# include +# include +# include Worker::Worker() : todoLen {0} { @@ -44,3 +45,4 @@ Worker::worker() j->doWork(); } } +#endif 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 -#include -#include -#include -#include -#include #include -#include + +#if __cpp_lib_semaphore +# include +# include +# include +# include +# include +# include +# include class Work; @@ -43,4 +45,17 @@ private: std::mutex todoMutex; }; +#else + +class Worker { +public: + template + void + addWork(Params &&... params) + { + T(std::forward(params)...).doWork(); + } +}; + +#endif #endif -- cgit v1.2.3