Etterna
0.74.4
Loading...
Searching...
No Matches
src
arch
Threads
Threads.h
1
#ifndef THREADS_H
2
#define THREADS_H
3
4
/* This is the low-level implementation; you probably want RageThreads. */
5
class
RageMutex
;
6
class
RageTimer
;
7
8
class
ThreadImpl
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
24
class
MutexImpl
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
54
class
EventImpl
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
64
class
SemaImpl
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.
75
ThreadImpl
*
76
MakeThread(
int
(*fn)(
void
*),
void
* data, uint64_t* piThreadID);
77
ThreadImpl
*
78
MakeThisThread();
79
MutexImpl
*
80
MakeMutex(
RageMutex
* pParent);
81
EventImpl
*
82
MakeEvent(
MutexImpl
* pMutex);
83
SemaImpl
*
84
MakeSemaphore(
int
iInitialValue);
85
uint64_t
86
GetThisThreadId();
87
88
/* Since ThreadId is implementation-defined, we can't define a universal
89
* invalid value. Return the invalid value for this implementation. */
90
uint64_t
91
GetInvalidThreadId();
92
93
#endif
EventImpl
Definition
Threads.h:55
MutexImpl
Definition
Threads.h:25
RageMutex
Definition
RageThreads.h:232
RageTimer
Definition
RageTimer.h:9
SemaImpl
Definition
Threads.h:65
ThreadImpl
Definition
Threads.h:9
Generated by
1.9.8