all repos — mgba @ b1a648e46e7878c4eebf457699bbf444fbeecf48

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 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
57int GBAThreadStart(struct GBAThread* threadContext);
58void GBAThreadJoin(struct GBAThread* threadContext);
59
60void GBAThreadPause(struct GBAThread* threadContext);
61void GBAThreadUnpause(struct GBAThread* threadContext);
62void GBAThreadTogglePause(struct GBAThread* threadContext);
63struct GBAThread* GBAThreadGetContext(void);
64
65void GBASyncPostFrame(struct GBASync* sync);
66int GBASyncWaitFrameStart(struct GBASync* sync, int frameskip);
67void GBASyncWaitFrameEnd(struct GBASync* sync);
68int GBASyncDrawingFrame(struct GBASync* sync);
69
70void GBASyncProduceAudio(struct GBASync* sync, int wait);
71void GBASyncLockAudio(struct GBASync* sync);
72void GBASyncConsumeAudio(struct GBASync* sync);
73
74#endif