all repos — mgba @ 9d351d4a5835da48fd7a4ed24f7cba27adf0ce74

mGBA Game Boy Advance Emulator

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 GBASync {
18	int videoFramePending;
19	int videoFrameWait;
20	int videoFrameSkip;
21	int videoFrameOn;
22	Mutex videoFrameMutex;
23	Condition videoFrameAvailableCond;
24	Condition videoFrameRequiredCond;
25
26	int audioWait;
27	Condition audioRequiredCond;
28	Mutex audioBufferMutex;
29};
30
31struct GBAThread {
32	// Output
33	enum ThreadState state;
34	int useDebugger;
35	struct GBA* gba;
36	struct ARMDebugger* debugger;
37
38	// Input
39	struct GBAVideoRenderer* renderer;
40	int fd;
41	const char* fname;
42	int activeKeys;
43	int frameskip;
44
45	// Threading state
46	Thread thread;
47
48	Mutex stateMutex;
49	Condition stateCond;
50
51	ThreadCallback startCallback;
52	ThreadCallback cleanCallback;
53	ThreadCallback frameCallback;
54	void* userData;
55
56	struct GBASync sync;
57
58	int rewindBufferSize;
59	int rewindBufferCapacity;
60	int rewindBufferInterval;
61	int rewindBufferNext;
62	struct GBASerializedState** rewindBuffer;
63	int rewindBufferWriteOffset;
64};
65
66int GBAThreadStart(struct GBAThread* threadContext);
67void GBAThreadEnd(struct GBAThread* threadContext);
68void GBAThreadJoin(struct GBAThread* threadContext);
69
70void GBAThreadPause(struct GBAThread* threadContext);
71void GBAThreadUnpause(struct GBAThread* threadContext);
72int GBAThreadIsPaused(struct GBAThread* threadContext);
73void GBAThreadTogglePause(struct GBAThread* threadContext);
74struct GBAThread* GBAThreadGetContext(void);
75
76void GBASyncPostFrame(struct GBASync* sync);
77int GBASyncWaitFrameStart(struct GBASync* sync, int frameskip);
78void GBASyncWaitFrameEnd(struct GBASync* sync);
79int GBASyncDrawingFrame(struct GBASync* sync);
80
81void GBASyncProduceAudio(struct GBASync* sync, int wait);
82void GBASyncLockAudio(struct GBASync* sync);
83void GBASyncConsumeAudio(struct GBASync* sync);
84
85#endif