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