all repos — mgba @ 85d30ac27174392c415c275d67a95badec64436a

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 <pthread.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	pthread_t thread;
33
34	pthread_mutex_t stateMutex;
35	pthread_cond_t stateCond;
36
37	ThreadCallback startCallback;
38	ThreadCallback cleanCallback;
39	void* userData;
40
41	struct GBASync {
42		int videoFramePending;
43		int videoFrameWait;
44		int videoFrameSkip;
45		int videoFrameOn;
46		pthread_mutex_t videoFrameMutex;
47		pthread_cond_t videoFrameAvailableCond;
48		pthread_cond_t videoFrameRequiredCond;
49
50		int audioWait;
51		pthread_cond_t audioRequiredCond;
52		pthread_mutex_t audioBufferMutex;
53	} sync;
54};
55
56int GBAThreadStart(struct GBAThread* threadContext);
57void GBAThreadJoin(struct GBAThread* threadContext);
58
59void GBAThreadPause(struct GBAThread* threadContext);
60void GBAThreadUnpause(struct GBAThread* threadContext);
61void GBAThreadTogglePause(struct GBAThread* threadContext);
62struct GBAThread* GBAThreadGetContext(void);
63
64void GBASyncPostFrame(struct GBASync* sync);
65int GBASyncWaitFrameStart(struct GBASync* sync, int frameskip);
66void GBASyncWaitFrameEnd(struct GBASync* sync);
67int GBASyncDrawingFrame(struct GBASync* sync);
68
69void GBASyncProduceAudio(struct GBASync* sync, int wait);
70void GBASyncLockAudio(struct GBASync* sync);
71void GBASyncConsumeAudio(struct GBASync* sync);
72
73#endif