all repos — mgba @ e9c441281988d973b8e9fc7956e983249f7c8acd

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 GBASIODriverSet sioDrivers;
40	struct ARMDebugger* debugger;
41	int fd;
42	int biosFd;
43	const char* fname;
44	int activeKeys;
45	int frameskip;
46
47	// Threading state
48	Thread thread;
49
50	Mutex stateMutex;
51	Condition stateCond;
52
53	GBALogHandler logHandler;
54	ThreadCallback startCallback;
55	ThreadCallback cleanCallback;
56	ThreadCallback frameCallback;
57	void* userData;
58
59	struct GBASync sync;
60
61	int rewindBufferSize;
62	int rewindBufferCapacity;
63	int rewindBufferInterval;
64	int rewindBufferNext;
65	struct GBASerializedState** rewindBuffer;
66	int rewindBufferWriteOffset;
67};
68
69int GBAThreadStart(struct GBAThread* threadContext);
70int GBAThreadHasStarted(struct GBAThread* threadContext);
71void GBAThreadEnd(struct GBAThread* threadContext);
72void GBAThreadJoin(struct GBAThread* threadContext);
73
74void GBAThreadPause(struct GBAThread* threadContext);
75void GBAThreadUnpause(struct GBAThread* threadContext);
76int GBAThreadIsPaused(struct GBAThread* threadContext);
77void GBAThreadTogglePause(struct GBAThread* threadContext);
78struct GBAThread* GBAThreadGetContext(void);
79
80void GBASyncPostFrame(struct GBASync* sync);
81int GBASyncWaitFrameStart(struct GBASync* sync, int frameskip);
82void GBASyncWaitFrameEnd(struct GBASync* sync);
83int GBASyncDrawingFrame(struct GBASync* sync);
84
85void GBASyncProduceAudio(struct GBASync* sync, int wait);
86void GBASyncLockAudio(struct GBASync* sync);
87void GBASyncConsumeAudio(struct GBASync* sync);
88
89#endif