summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2023-04-14 10:24:10 +0100
committerDan Goodliffe <dan@randomdan.homeip.net>2023-04-14 10:24:10 +0100
commit4bf94458d5d7abafb154e914620dc758d26719c2 (patch)
tree95a1d5db3c27b0069318798c90dc5e8ff093dc1f /lib
parentExternalise a neater definition of TGAHead (diff)
downloadilt-4bf94458d5d7abafb154e914620dc758d26719c2.tar.bz2
ilt-4bf94458d5d7abafb154e914620dc758d26719c2.tar.xz
ilt-4bf94458d5d7abafb154e914620dc758d26719c2.zip
Global worker instance
Diffstat (limited to 'lib')
-rw-r--r--lib/worker.cpp12
-rw-r--r--lib/worker.h35
2 files changed, 16 insertions, 31 deletions
diff --git a/lib/worker.cpp b/lib/worker.cpp
index fd255c7..cf59f56 100644
--- a/lib/worker.cpp
+++ b/lib/worker.cpp
@@ -1,9 +1,10 @@
#include "worker.h"
-#if __cpp_lib_semaphore
-# include "work.h"
-# include <algorithm>
-# include <iterator>
-# include <mutex>
+#include "work.h"
+#include <algorithm>
+#include <iterator>
+#include <mutex>
+
+Worker Worker::instance;
Worker::Worker() : todoLen {0}
{
@@ -45,4 +46,3 @@ Worker::worker()
j->doWork();
}
}
-#endif
diff --git a/lib/worker.h b/lib/worker.h
index 7cd06f9..136c50e 100644
--- a/lib/worker.h
+++ b/lib/worker.h
@@ -1,19 +1,17 @@
#pragma once
+#include <deque>
+#include <memory>
+#include <mutex>
+#include <semaphore>
+#include <special_members.hpp>
+#include <thread>
#include <utility>
-class Work;
-
-#if __cpp_lib_semaphore
-# include <deque>
-# include <memory>
-# include <mutex>
-# include <semaphore>
-# include <special_members.hpp>
-# include <thread>
-# include <vector>
+#include <vector>
+class Work;
class Worker {
-public:
+private:
Worker();
~Worker();
@@ -42,19 +40,6 @@ private:
ToDo todo;
std::counting_semaphore<16> todoLen;
std::mutex todoMutex;
-};
-
-#else
-class Worker {
-public:
- template<typename T, typename... Params>
- void
- addWork(Params &&... params)
- requires std::is_base_of_v<Work, T>
- {
- T(std::forward<Params>(params)...).doWork();
- }
+ static Worker instance;
};
-
-#endif