src/gba/gba-thread.h (view raw)
1#ifndef GBA_THREAD_H
2#define GBA_THREAD_H
3
4#include "threading.h"
5
6struct GBAThread;
7typedef void (*ThreadCallback)(struct GBAThread* threadContext);
8
9enum ThreadState {
10 THREAD_INITIALIZED = -1,
11 THREAD_RUNNING = 0,
12 THREAD_PAUSED = 1,
13 THREAD_EXITING = 2,
14 THREAD_SHUTDOWN = 3
15};
16
17struct GBAThread {
18 // Output
19 enum ThreadState state;
20 int useDebugger;
21 struct GBA* gba;
22 struct ARMDebugger* debugger;
23
24 // Input
25 struct GBAVideoRenderer* renderer;
26 int fd;
27 const char* fname;
28 int activeKeys;
29 int frameskip;
30
31 // Threading state
32 Thread thread;
33
34 Mutex stateMutex;
35 Condition stateCond;
36
37 ThreadCallback startCallback;
38 ThreadCallback cleanCallback;
39 ThreadCallback frameCallback;
40 void* userData;
41
42 struct GBASync {
43 int videoFramePending;
44 int videoFrameWait;
45 int videoFrameSkip;
46 int videoFrameOn;
47 Mutex videoFrameMutex;
48 Condition videoFrameAvailableCond;
49 Condition videoFrameRequiredCond;
50
51 int audioWait;
52 Condition audioRequiredCond;
53 Mutex audioBufferMutex;
54 } sync;
55
56 int rewindBufferSize;
57 int rewindBufferCapacity;
58 int rewindBufferInterval;
59 int rewindBufferNext;
60 struct GBASerializedState** rewindBuffer;
61 int rewindBufferWriteOffset;
62};
63
64int GBAThreadStart(struct GBAThread* threadContext);
65void GBAThreadJoin(struct GBAThread* threadContext);
66
67void GBAThreadPause(struct GBAThread* threadContext);
68void GBAThreadUnpause(struct GBAThread* threadContext);
69void GBAThreadTogglePause(struct GBAThread* threadContext);
70struct GBAThread* GBAThreadGetContext(void);
71
72void GBASyncPostFrame(struct GBASync* sync);
73int GBASyncWaitFrameStart(struct GBASync* sync, int frameskip);
74void GBASyncWaitFrameEnd(struct GBASync* sync);
75int GBASyncDrawingFrame(struct GBASync* sync);
76
77void GBASyncProduceAudio(struct GBASync* sync, int wait);
78void GBASyncLockAudio(struct GBASync* sync);
79void GBASyncConsumeAudio(struct GBASync* sync);
80
81#endif