summaryrefslogtreecommitdiffstats
path: root/core/threading.hh
diff options
context:
space:
mode:
authoruntodesu <kirill@untode.su>2025-09-11 13:51:50 +0500
committeruntodesu <kirill@untode.su>2025-09-11 13:51:50 +0500
commitf0cc06c7388acb32b86301965c5b2547e4e3b919 (patch)
treed6fc939b1b660562a8abdedb3330ae66defc1bcb /core/threading.hh
parentaaed751bf4430bf4b9b30cef532b8753b9f639ce (diff)
downloadvoxelius-f0cc06c7388acb32b86301965c5b2547e4e3b919.tar.bz2
voxelius-f0cc06c7388acb32b86301965c5b2547e4e3b919.zip
Displace threading into core (qfortress graft)
Diffstat (limited to 'core/threading.hh')
-rw-r--r--core/threading.hh50
1 files changed, 50 insertions, 0 deletions
diff --git a/core/threading.hh b/core/threading.hh
new file mode 100644
index 0000000..bd359ad
--- /dev/null
+++ b/core/threading.hh
@@ -0,0 +1,50 @@
+#ifndef CORE_THREADING_HH
+#define CORE_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 shutdown(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 // CORE_THREADING_HH