summaryrefslogtreecommitdiffstats
path: root/src/game/shared/threading.hh
diff options
context:
space:
mode:
Diffstat (limited to 'src/game/shared/threading.hh')
-rw-r--r--src/game/shared/threading.hh50
1 files changed, 50 insertions, 0 deletions
diff --git a/src/game/shared/threading.hh b/src/game/shared/threading.hh
new file mode 100644
index 0000000..bce4811
--- /dev/null
+++ b/src/game/shared/threading.hh
@@ -0,0 +1,50 @@
+#ifndef SHARED_THREADING_HH
+#define SHARED_THREADING_HH 1
+#pragma once
+
+enum class task_status : unsigned int {
+ ENQUEUED = 0x0000U,
+ PROCESSING = 0x0001U,
+ COMPLETED = 0x0002U,
+ CANCELLED = 0x0004U,
+};
+
+class Task {
+public:
+ virtual ~Task(void) = default;
+ virtual void process(void) = 0;
+ virtual void finalize(void) = 0;
+
+ task_status get_status(void) const;
+ void set_status(task_status status);
+
+protected:
+ std::atomic<task_status> m_status;
+ std::future<void> m_future;
+};
+
+namespace threading
+{
+void init(void);
+void deinit(void);
+void update(void);
+} // namespace threading
+
+namespace threading::detail
+{
+void submit_new(Task* task);
+} // namespace threading::detail
+
+namespace threading
+{
+template<typename T, typename... AT>
+void submit(AT&&... args);
+} // namespace threading
+
+template<typename T, typename... AT>
+inline void threading::submit(AT&&... args)
+{
+ threading::detail::submit_new(new T(args...));
+}
+
+#endif /* SHARED_THREADING_HH */