aboutsummaryrefslogtreecommitdiff
path: root/zencore/include
diff options
context:
space:
mode:
authorDan Engelbrecht <[email protected]>2022-03-22 13:50:08 +0100
committerGitHub <[email protected]>2022-03-22 13:50:08 +0100
commit8667509907b8829b5148ee856dce675001051b01 (patch)
tree0252caa7cd01c533809b1b17dfa41721a0cccb82 /zencore/include
parentRemove unused TotalAttachmentsSize (Mac warning) (diff)
downloadzen-8667509907b8829b5148ee856dce675001051b01.tar.xz
zen-8667509907b8829b5148ee856dce675001051b01.zip
move workthreadpool to zencore (#63)
Diffstat (limited to 'zencore/include')
-rw-r--r--zencore/include/zencore/workthreadpool.h46
1 files changed, 46 insertions, 0 deletions
diff --git a/zencore/include/zencore/workthreadpool.h b/zencore/include/zencore/workthreadpool.h
new file mode 100644
index 000000000..834339d50
--- /dev/null
+++ b/zencore/include/zencore/workthreadpool.h
@@ -0,0 +1,46 @@
+// Copyright Epic Games, Inc. All Rights Reserved.
+
+#pragma once
+
+#include <zencore/zencore.h>
+
+#include <zencore/blockingqueue.h>
+#include <zencore/refcount.h>
+
+#include <exception>
+#include <functional>
+#include <system_error>
+#include <thread>
+#include <vector>
+
+namespace zen {
+
+struct IWork : public RefCounted
+{
+ virtual void Execute() = 0;
+
+ inline std::exception_ptr GetException() { return m_Exception; }
+
+private:
+ std::exception_ptr m_Exception;
+
+ friend class WorkerThreadPool;
+};
+
+class WorkerThreadPool
+{
+public:
+ WorkerThreadPool(int InThreadCount);
+ ~WorkerThreadPool();
+
+ void ScheduleWork(Ref<IWork> Work);
+ void ScheduleWork(std::function<void()>&& Work);
+
+ void WorkerThreadFunction();
+
+private:
+ std::vector<std::thread> m_WorkerThreads;
+ BlockingQueue<Ref<IWork>> m_WorkQueue;
+};
+
+} // namespace zen