From 3bf42c6ff3805a0d42bbc661794a95ff31bedc26 Mon Sep 17 00:00:00 2001 From: untodesu Date: Sat, 15 Mar 2025 16:22:09 +0500 Subject: Add whatever I was working on for the last month --- game/shared/threading.hh | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 game/shared/threading.hh (limited to 'game/shared/threading.hh') diff --git a/game/shared/threading.hh b/game/shared/threading.hh new file mode 100644 index 0000000..e143f4f --- /dev/null +++ b/game/shared/threading.hh @@ -0,0 +1,46 @@ +#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 m_status; + std::future m_future; +}; + +namespace threading +{ +void init(void); +void deinit(void); +void update(void); +void submit(Task *task); +} // namespace threading + +namespace threading +{ +template +void submit(AT &&... args); +} // namespace threading + +template +inline void threading::submit(AT &&... args) +{ + threading::submit(new T(args...)); +} + +#endif /* SHARED_THREADING_HH */ -- cgit