all repos — mgba @ eb232690114374d0307c5b5b00c3d520353b7f1c

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