Etterna 0.74.4
Loading...
Searching...
No Matches
Threads.h
1#ifndef THREADS_H
2#define THREADS_H
3
4/* This is the low-level implementation; you probably want RageThreads. */
5class RageMutex;
6class RageTimer;
7
9{
10 public:
11 virtual ~ThreadImpl() = default;
12 virtual void Halt(bool Kill) = 0;
13 virtual void Resume() = 0;
14
15 /* Get the identifier for this thread. The actual meaning of this is
16 * implementation-defined, except that each thread has exactly one ID
17 * and each ID corresponds to one thread. (This means that Win32
18 * thread handles are not acceptable as ThreadIds.) */
19 virtual uint64_t GetThreadId() const = 0;
20
21 virtual int Wait() = 0;
22};
23
25{
26 public:
27 RageMutex* m_Parent;
28
29 explicit MutexImpl(RageMutex* pParent)
30 : m_Parent(pParent)
31 {
32 }
33 virtual ~MutexImpl() = default;
34
35 /* Lock the mutex. If mutex timeouts are implemented, and the mutex
36 * times out, return false and do not lock the mutex. No other failure
37 * return is allowed; all other errors should fail with an assertion. */
38 virtual bool Lock() = 0;
39
40 /* Non-blocking lock. If locking the mutex would block because the mutex
41 * is already locked by another thread, return false; otherwise
42 * return true and lock the mutex. */
43 virtual bool TryLock() = 0;
44
45 /* Unlock the mutex. This must only be called when the mutex is locked;
46 * implementations may fail with an assertion if the mutex is not locked. */
47 virtual void Unlock() = 0;
48
49 private:
50 MutexImpl(const MutexImpl& rhs) = delete;
51 MutexImpl& operator=(const MutexImpl& rhs) = delete;
52};
53
55{
56 public:
57 virtual ~EventImpl() = default;
58 virtual bool Wait(float timeout) = 0;
59 virtual void Signal() = 0;
60 virtual void Broadcast() = 0;
61 virtual bool WaitTimeoutSupported() const = 0;
62};
63
65{
66 public:
67 virtual ~SemaImpl() = default;
68 virtual int GetValue() const = 0;
69 virtual void Post() = 0;
70 virtual bool Wait() = 0;
71 virtual bool TryWait() = 0;
72};
73
74// These functions must be implemented by the thread implementation.
76MakeThread(int (*fn)(void*), void* data, uint64_t* piThreadID);
78MakeThisThread();
80MakeMutex(RageMutex* pParent);
82MakeEvent(MutexImpl* pMutex);
84MakeSemaphore(int iInitialValue);
85uint64_t
86GetThisThreadId();
87
88/* Since ThreadId is implementation-defined, we can't define a universal
89 * invalid value. Return the invalid value for this implementation. */
90uint64_t
91GetInvalidThreadId();
92
93#endif
Definition Threads.h:55
Definition Threads.h:25
Definition RageThreads.h:232
Definition RageTimer.h:9
Definition Threads.h:65
Definition Threads.h:9