2013-04-20 22:54:09 +00:00
|
|
|
#ifndef GBA_THREAD_H
|
|
|
|
#define GBA_THREAD_H
|
|
|
|
|
|
|
|
#include <pthread.h>
|
|
|
|
|
2013-10-09 07:44:31 +00:00
|
|
|
struct GBAThread;
|
|
|
|
typedef void (*ThreadCallback)(struct GBAThread* threadContext);
|
|
|
|
|
2013-04-20 22:54:09 +00:00
|
|
|
struct GBAThread {
|
2013-04-20 23:16:37 +00:00
|
|
|
// Output
|
2013-04-20 23:40:08 +00:00
|
|
|
int started;
|
2013-09-22 01:10:13 +00:00
|
|
|
int useDebugger;
|
2013-04-20 22:54:09 +00:00
|
|
|
struct GBA* gba;
|
|
|
|
struct ARMDebugger* debugger;
|
2013-04-20 23:16:37 +00:00
|
|
|
|
|
|
|
// Input
|
|
|
|
struct GBAVideoRenderer* renderer;
|
2013-04-20 22:54:09 +00:00
|
|
|
int fd;
|
2013-09-22 23:45:19 +00:00
|
|
|
const char* fname;
|
2013-04-21 07:35:21 +00:00
|
|
|
int activeKeys;
|
2013-10-05 09:11:53 +00:00
|
|
|
int frameskip;
|
2013-04-20 23:40:08 +00:00
|
|
|
|
|
|
|
// Threading state
|
2013-04-20 23:44:03 +00:00
|
|
|
pthread_t thread;
|
2013-10-05 09:11:53 +00:00
|
|
|
|
|
|
|
pthread_mutex_t startMutex;
|
|
|
|
pthread_cond_t startCond;
|
|
|
|
|
2013-10-09 07:44:31 +00:00
|
|
|
ThreadCallback startCallback;
|
|
|
|
ThreadCallback cleanCallback;
|
|
|
|
void* userData;
|
|
|
|
|
2013-10-05 09:11:53 +00:00
|
|
|
struct GBASync {
|
|
|
|
int videoFramePending;
|
|
|
|
int videoFrameWait;
|
|
|
|
int videoFrameSkip;
|
|
|
|
pthread_mutex_t videoFrameMutex;
|
|
|
|
pthread_cond_t videoFrameAvailableCond;
|
|
|
|
pthread_cond_t videoFrameRequiredCond;
|
2013-10-05 09:52:57 +00:00
|
|
|
|
|
|
|
int audioWait;
|
|
|
|
pthread_cond_t audioRequiredCond;
|
2013-10-05 09:11:53 +00:00
|
|
|
} sync;
|
2013-04-20 22:54:09 +00:00
|
|
|
};
|
|
|
|
|
2013-04-20 23:44:03 +00:00
|
|
|
int GBAThreadStart(struct GBAThread* threadContext);
|
|
|
|
void GBAThreadJoin(struct GBAThread* threadContext);
|
2013-09-30 08:42:31 +00:00
|
|
|
struct GBAThread* GBAThreadGetContext(void);
|
2013-04-20 22:54:09 +00:00
|
|
|
|
2013-10-05 09:11:53 +00:00
|
|
|
void GBASyncPostFrame(struct GBASync* sync);
|
|
|
|
void GBASyncWaitFrameStart(struct GBASync* sync, int frameskip);
|
|
|
|
void GBASyncWaitFrameEnd(struct GBASync* sync);
|
|
|
|
int GBASyncDrawingFrame(struct GBASync* sync);
|
|
|
|
|
2013-10-05 09:52:57 +00:00
|
|
|
void GBASyncProduceAudio(struct GBASync* sync, pthread_mutex_t* mutex);
|
|
|
|
void GBASyncConsumeAudio(struct GBASync* sync);
|
|
|
|
|
2013-04-20 22:54:09 +00:00
|
|
|
#endif
|