add Platform thread/semaphore support, using SDL

This commit is contained in:
StapleButter 2017-09-19 15:39:41 +02:00
parent 62405cde0a
commit 4db1a51fa4
1 changed files with 23 additions and 31 deletions

View File

@ -19,6 +19,7 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <SDL2/SDL.h>
#include "../Platform.h" #include "../Platform.h"
#include "../Config.h" #include "../Config.h"
@ -47,27 +48,19 @@ namespace Platform
{ {
/*class Thread : public wxThread typedef struct
{ {
public: SDL_Thread* ID;
Thread(void (*func)())
: wxThread(wxTHREAD_JOINABLE)
{
this->Func = func;
}
~Thread() {}
protected:
virtual ExitCode Entry()
{
Func();
return (ExitCode)0;
}
private:
void (*Func)(); void (*Func)();
};*/
} ThreadData;
int ThreadEntry(void* data)
{
ThreadData* thread = (ThreadData*)data;
thread->Func();
return 0;
}
/*socket_t MPSocket; /*socket_t MPSocket;
@ -79,47 +72,46 @@ u8 PacketBuffer[2048];
void* Thread_Create(void (*func)()) void* Thread_Create(void (*func)())
{ {
/*Thread* ret = new Thread(func); ThreadData* data = new ThreadData;
ret->Run(); data->Func = func;
return (void*)ret;*/ data->ID = SDL_CreateThread(ThreadEntry, "melonDS core thread", data);
return NULL; return data;
} }
void Thread_Free(void* thread) void Thread_Free(void* thread)
{ {
//delete (Thread*)thread; delete (ThreadData*)thread;
} }
void Thread_Wait(void* thread) void Thread_Wait(void* thread)
{ {
//((Thread*)thread)->Wait(); SDL_WaitThread((SDL_Thread*)((ThreadData*)thread)->ID, NULL);
} }
void* Semaphore_Create() void* Semaphore_Create()
{ {
//return (void*)new wxSemaphore(); return SDL_CreateSemaphore(0);
return NULL;
} }
void Semaphore_Free(void* sema) void Semaphore_Free(void* sema)
{ {
//delete (wxSemaphore*)sema; SDL_DestroySemaphore((SDL_sem*)sema);
} }
void Semaphore_Reset(void* sema) void Semaphore_Reset(void* sema)
{ {
//while (((wxSemaphore*)sema)->TryWait() == wxSEMA_NO_ERROR); while (SDL_SemTryWait((SDL_sem*)sema) == 0);
} }
void Semaphore_Wait(void* sema) void Semaphore_Wait(void* sema)
{ {
//((wxSemaphore*)sema)->Wait(); SDL_SemWait((SDL_sem*)sema);
} }
void Semaphore_Post(void* sema) void Semaphore_Post(void* sema)
{ {
//((wxSemaphore*)sema)->Post(); SDL_SemPost((SDL_sem*)sema);
} }