summaryrefslogtreecommitdiffstats
path: root/src/game/shared/threading.hh
blob: 02903d5720f43ceb56ab4eb032b8feff55754959 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
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 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 // SHARED_THREADING_HH