mirror of
https://github.com/isledecomp/isle-portable.git
synced 2025-09-27 14:42:51 -04:00
Replace Windows threads with SDL threads (#8)
* Replace Windows threads with SDL threads * Wait for thread in dtor
This commit is contained in:
parent
641ae70ab9
commit
21502ecf18
@ -5,6 +5,8 @@
|
||||
#include "mxsemaphore.h"
|
||||
#include "mxtypes.h"
|
||||
|
||||
#include <SDL3/SDL_thread.h>
|
||||
|
||||
class MxCore;
|
||||
|
||||
// VTABLE: LEGO1 0x100dc860
|
||||
@ -33,10 +35,9 @@ public:
|
||||
private:
|
||||
static unsigned ThreadProc(void* p_thread);
|
||||
|
||||
MxULong m_hThread; // 0x04
|
||||
MxU32 m_threadId; // 0x08
|
||||
MxBool m_running; // 0x0c
|
||||
MxSemaphore m_semaphore; // 0x10
|
||||
SDL_Thread* m_thread;
|
||||
MxBool m_running;
|
||||
MxSemaphore m_semaphore;
|
||||
|
||||
protected:
|
||||
MxCore* m_target; // 0x18
|
||||
|
@ -16,9 +16,11 @@ MxResult MxSemaphore::Init(MxU32 p_initialCount, MxU32 p_maxCount)
|
||||
{
|
||||
// [library:synchronization] No support for max count, but shouldn't be necessary
|
||||
MxResult result = FAILURE;
|
||||
|
||||
if ((m_semaphore = SDL_CreateSemaphore(p_initialCount))) {
|
||||
result = SUCCESS;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -2,39 +2,45 @@
|
||||
|
||||
#include "decomp.h"
|
||||
|
||||
#include <process.h>
|
||||
#include <windows.h>
|
||||
#include <SDL3/SDL_timer.h>
|
||||
|
||||
DECOMP_SIZE_ASSERT(MxThread, 0x1c)
|
||||
|
||||
// FUNCTION: LEGO1 0x100bf510
|
||||
MxThread::MxThread()
|
||||
{
|
||||
m_hThread = NULL;
|
||||
m_thread = NULL;
|
||||
m_running = TRUE;
|
||||
m_threadId = 0;
|
||||
}
|
||||
|
||||
// FUNCTION: LEGO1 0x100bf5a0
|
||||
MxThread::~MxThread()
|
||||
{
|
||||
if (m_hThread) {
|
||||
CloseHandle((HANDLE) m_hThread);
|
||||
if (m_thread) {
|
||||
SDL_WaitThread(m_thread, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
typedef unsigned(__stdcall* ThreadFunc)(void*);
|
||||
|
||||
// FUNCTION: LEGO1 0x100bf610
|
||||
MxResult MxThread::Start(MxS32 p_stack, MxS32 p_flag)
|
||||
{
|
||||
MxResult result = FAILURE;
|
||||
|
||||
if (m_semaphore.Init(0, 1) == SUCCESS) {
|
||||
if ((m_hThread =
|
||||
_beginthreadex(NULL, p_stack << 2, (ThreadFunc) &MxThread::ThreadProc, this, p_flag, &m_threadId))) {
|
||||
const SDL_PropertiesID props = SDL_CreateProperties();
|
||||
SDL_SetProperty(
|
||||
props,
|
||||
SDL_PROP_THREAD_CREATE_ENTRY_FUNCTION_POINTER,
|
||||
(SDL_FunctionPointer) &MxThread::ThreadProc
|
||||
);
|
||||
SDL_SetProperty(props, SDL_PROP_THREAD_CREATE_USERDATA_POINTER, this);
|
||||
SDL_SetNumberProperty(props, SDL_PROP_THREAD_CREATE_STACKSIZE_NUMBER, p_stack << 2);
|
||||
|
||||
if ((m_thread = SDL_CreateThreadWithProperties(props))) {
|
||||
result = SUCCESS;
|
||||
}
|
||||
|
||||
SDL_DestroyProperties(props);
|
||||
}
|
||||
|
||||
return result;
|
||||
@ -43,7 +49,7 @@ MxResult MxThread::Start(MxS32 p_stack, MxS32 p_flag)
|
||||
// FUNCTION: LEGO1 0x100bf660
|
||||
void MxThread::Sleep(MxS32 p_milliseconds)
|
||||
{
|
||||
::Sleep(p_milliseconds);
|
||||
SDL_Delay(p_milliseconds);
|
||||
}
|
||||
|
||||
// FUNCTION: LEGO1 0x100bf670
|
||||
|
@ -24,7 +24,7 @@ To achieve our goal of platform independence, we need to replace any Windows-onl
|
||||
| - | - | - | - |
|
||||
| [Smacker](https://github.com/isledecomp/isle/tree/master/3rdparty/smacker) | [libsmacker](https://github.com/foxtacles/libsmacker) | ✅ | [Remarks](https://github.com/search?q=repo%3Aisledecomp%2Fisle-portable%20%22%2F%2F%20%5Blibrary%3Alibsmacker%5D%22&type=code) |
|
||||
| Filesystem | C standard library | ❌ | [Remarks](https://github.com/search?q=repo%3Aisledecomp%2Fisle-portable+%22%2F%2F+%5Blibrary%3Afilesystem%5D%22&type=code) |
|
||||
| Threads, Mutexes (Synchronization) | [SDL3](https://www.libsdl.org/) | ❌ | [Remarks](https://github.com/search?q=repo%3Aisledecomp%2Fisle-portable+%22%2F%2F+%5Blibrary%3Asynchronization%5D%22&type=code) |
|
||||
| Threads, Mutexes (Synchronization) | [SDL3](https://www.libsdl.org/) | ✅ | [Remarks](https://github.com/search?q=repo%3Aisledecomp%2Fisle-portable+%22%2F%2F+%5Blibrary%3Asynchronization%5D%22&type=code) |
|
||||
| Keyboard, Mouse, Joystick, DirectInput (Input) | [SDL3](https://www.libsdl.org/) | ❌ | [Remarks](https://github.com/search?q=repo%3Aisledecomp%2Fisle-portable+%22%2F%2F+%5Blibrary%3Ainput%5D%22&type=code) |
|
||||
| WinMM, DirectSound (Audio) | [SDL3](https://www.libsdl.org/) | ❌ | [Remarks](https://github.com/search?q=repo%3Aisledecomp%2Fisle-portable+%22%2F%2F+%5Blibrary%3Aaudio%5D%22&type=code) |
|
||||
| DirectDraw (2D video) | [SDL3](https://www.libsdl.org/) | ❌ | [Remarks](https://github.com/search?q=repo%3Aisledecomp%2Fisle-portable+%22%2F%2F+%5Blibrary%3A2d%5D%22&type=code) |
|
||||
|
Loading…
x
Reference in New Issue
Block a user