summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/worker.cpp10
-rw-r--r--lib/worker.h29
2 files changed, 28 insertions, 11 deletions
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 <algorithm>
-#include <iterator>
-#include <mutex>
+#if __cpp_lib_semaphore
+# include "work.h"
+# include <algorithm>
+# include <iterator>
+# include <mutex>
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 <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