diff options
-rw-r--r-- | lib/worker.cpp | 12 | ||||
-rw-r--r-- | lib/worker.h | 35 | ||||
-rw-r--r-- | test/Jamfile.jam | 1 | ||||
-rw-r--r-- | test/test-worker.cpp | 7 |
4 files changed, 24 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 diff --git a/test/Jamfile.jam b/test/Jamfile.jam index 390880d..482b388 100644 --- a/test/Jamfile.jam +++ b/test/Jamfile.jam @@ -57,6 +57,7 @@ run test-glContextBhvr.cpp ; run test-assetFactory.cpp : -- : [ sequence.insertion-sort [ glob-tree $(res) : *.* ] fixtures/rgb.txt ] : <library>test ; run perf-assetFactory.cpp : : : <library>benchmark <library>test <dependency>test-assetFactory ; run perf-persistence.cpp : : : <library>benchmark <library>test <dependency>test-persistence ; +run test-worker.cpp ; compile test-static-enumDetails.cpp ; compile test-static-stream_support.cpp ; explicit perf-assetFactory ; diff --git a/test/test-worker.cpp b/test/test-worker.cpp new file mode 100644 index 0000000..3c5ed7e --- /dev/null +++ b/test/test-worker.cpp @@ -0,0 +1,7 @@ +#define BOOST_TEST_MODULE test_worker + +#include "testHelpers.h" +#include <boost/test/unit_test.hpp> +#include <stream_support.hpp> + +BOOST_AUTO_TEST_CASE(exists) { } |