mirror of https://github.com/mgba-emu/mgba.git
Clean up thread starting, stopping and sound
This commit is contained in:
parent
2f9bcf63b7
commit
9698531702
|
@ -65,6 +65,10 @@ static void* _GBAThreadRun(void* context) {
|
|||
}
|
||||
gba.keySource = &threadContext->activeKeys;
|
||||
|
||||
if (threadContext->startCallback) {
|
||||
threadContext->startCallback(threadContext);
|
||||
}
|
||||
|
||||
threadContext->started = 1;
|
||||
pthread_mutex_lock(&threadContext->startMutex);
|
||||
pthread_cond_broadcast(&threadContext->startCond);
|
||||
|
@ -78,7 +82,15 @@ static void* _GBAThreadRun(void* context) {
|
|||
ARMRun(&gba.cpu);
|
||||
}
|
||||
}
|
||||
|
||||
if (threadContext->cleanCallback) {
|
||||
threadContext->cleanCallback(threadContext);
|
||||
}
|
||||
|
||||
GBADeinit(&gba);
|
||||
|
||||
pthread_cond_broadcast(&threadContext->sync.videoFrameAvailableCond);
|
||||
pthread_cond_broadcast(&threadContext->sync.audioRequiredCond);
|
||||
free(savedata);
|
||||
|
||||
return 0;
|
||||
|
|
|
@ -3,6 +3,9 @@
|
|||
|
||||
#include <pthread.h>
|
||||
|
||||
struct GBAThread;
|
||||
typedef void (*ThreadCallback)(struct GBAThread* threadContext);
|
||||
|
||||
struct GBAThread {
|
||||
// Output
|
||||
int started;
|
||||
|
@ -23,6 +26,10 @@ struct GBAThread {
|
|||
pthread_mutex_t startMutex;
|
||||
pthread_cond_t startCond;
|
||||
|
||||
ThreadCallback startCallback;
|
||||
ThreadCallback cleanCallback;
|
||||
void* userData;
|
||||
|
||||
struct GBASync {
|
||||
int videoFramePending;
|
||||
int videoFrameWait;
|
||||
|
|
|
@ -61,6 +61,7 @@ void GBAInit(struct GBA* gba) {
|
|||
void GBADeinit(struct GBA* gba) {
|
||||
GBAMemoryDeinit(&gba->memory);
|
||||
GBAVideoDeinit(&gba->video);
|
||||
GBAAudioDeinit(&gba->audio);
|
||||
}
|
||||
|
||||
void GBABoardInit(struct GBABoard* board) {
|
||||
|
|
|
@ -29,6 +29,8 @@ struct GLSoftwareRenderer {
|
|||
static int _GBASDLInit(struct GLSoftwareRenderer* renderer);
|
||||
static void _GBASDLDeinit(struct GLSoftwareRenderer* renderer);
|
||||
static void _GBASDLRunloop(struct GBAThread* context, struct GLSoftwareRenderer* renderer);
|
||||
static void _GBASDLStart(struct GBAThread* context);
|
||||
static void _GBASDLClean(struct GBAThread* context);
|
||||
|
||||
static const GLint _glVertices[] = {
|
||||
0, 0,
|
||||
|
@ -74,8 +76,10 @@ int main(int argc, char** argv) {
|
|||
context.frameskip = 0;
|
||||
context.sync.videoFrameWait = 0;
|
||||
context.sync.audioWait = 1;
|
||||
context.startCallback = _GBASDLStart;
|
||||
context.cleanCallback = _GBASDLClean;
|
||||
context.userData = &renderer;
|
||||
GBAThreadStart(&context);
|
||||
renderer.audio.audio = &context.gba->audio;
|
||||
|
||||
_GBASDLRunloop(&context, &renderer);
|
||||
|
||||
|
@ -158,3 +162,13 @@ static void _GBASDLDeinit(struct GLSoftwareRenderer* renderer) {
|
|||
GBASDLDeinitAudio(&renderer->audio);
|
||||
SDL_Quit();
|
||||
}
|
||||
|
||||
static void _GBASDLStart(struct GBAThread* threadContext) {
|
||||
struct GLSoftwareRenderer* renderer = threadContext->userData;
|
||||
renderer->audio.audio = &threadContext->gba->audio;
|
||||
}
|
||||
|
||||
static void _GBASDLClean(struct GBAThread* threadContext) {
|
||||
struct GLSoftwareRenderer* renderer = threadContext->userData;
|
||||
renderer->audio.audio = 0;
|
||||
}
|
||||
|
|
|
@ -29,6 +29,7 @@ int GBASDLInitAudio(struct GBASDLAudio* context) {
|
|||
|
||||
void GBASDLDeinitAudio(struct GBASDLAudio* context) {
|
||||
(void)(context);
|
||||
SDL_PauseAudio(1);
|
||||
SDL_CloseAudio();
|
||||
SDL_QuitSubSystem(SDL_INIT_AUDIO);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue