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 "mxsemaphore.h"
|
||||||
#include "mxtypes.h"
|
#include "mxtypes.h"
|
||||||
|
|
||||||
|
#include <SDL3/SDL_thread.h>
|
||||||
|
|
||||||
class MxCore;
|
class MxCore;
|
||||||
|
|
||||||
// VTABLE: LEGO1 0x100dc860
|
// VTABLE: LEGO1 0x100dc860
|
||||||
@ -33,10 +35,9 @@ public:
|
|||||||
private:
|
private:
|
||||||
static unsigned ThreadProc(void* p_thread);
|
static unsigned ThreadProc(void* p_thread);
|
||||||
|
|
||||||
MxULong m_hThread; // 0x04
|
SDL_Thread* m_thread;
|
||||||
MxU32 m_threadId; // 0x08
|
MxBool m_running;
|
||||||
MxBool m_running; // 0x0c
|
MxSemaphore m_semaphore;
|
||||||
MxSemaphore m_semaphore; // 0x10
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
MxCore* m_target; // 0x18
|
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
|
// [library:synchronization] No support for max count, but shouldn't be necessary
|
||||||
MxResult result = FAILURE;
|
MxResult result = FAILURE;
|
||||||
|
|
||||||
if ((m_semaphore = SDL_CreateSemaphore(p_initialCount))) {
|
if ((m_semaphore = SDL_CreateSemaphore(p_initialCount))) {
|
||||||
result = SUCCESS;
|
result = SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,39 +2,45 @@
|
|||||||
|
|
||||||
#include "decomp.h"
|
#include "decomp.h"
|
||||||
|
|
||||||
#include <process.h>
|
#include <SDL3/SDL_timer.h>
|
||||||
#include <windows.h>
|
|
||||||
|
|
||||||
DECOMP_SIZE_ASSERT(MxThread, 0x1c)
|
DECOMP_SIZE_ASSERT(MxThread, 0x1c)
|
||||||
|
|
||||||
// FUNCTION: LEGO1 0x100bf510
|
// FUNCTION: LEGO1 0x100bf510
|
||||||
MxThread::MxThread()
|
MxThread::MxThread()
|
||||||
{
|
{
|
||||||
m_hThread = NULL;
|
m_thread = NULL;
|
||||||
m_running = TRUE;
|
m_running = TRUE;
|
||||||
m_threadId = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// FUNCTION: LEGO1 0x100bf5a0
|
// FUNCTION: LEGO1 0x100bf5a0
|
||||||
MxThread::~MxThread()
|
MxThread::~MxThread()
|
||||||
{
|
{
|
||||||
if (m_hThread) {
|
if (m_thread) {
|
||||||
CloseHandle((HANDLE) m_hThread);
|
SDL_WaitThread(m_thread, NULL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef unsigned(__stdcall* ThreadFunc)(void*);
|
|
||||||
|
|
||||||
// FUNCTION: LEGO1 0x100bf610
|
// FUNCTION: LEGO1 0x100bf610
|
||||||
MxResult MxThread::Start(MxS32 p_stack, MxS32 p_flag)
|
MxResult MxThread::Start(MxS32 p_stack, MxS32 p_flag)
|
||||||
{
|
{
|
||||||
MxResult result = FAILURE;
|
MxResult result = FAILURE;
|
||||||
|
|
||||||
if (m_semaphore.Init(0, 1) == SUCCESS) {
|
if (m_semaphore.Init(0, 1) == SUCCESS) {
|
||||||
if ((m_hThread =
|
const SDL_PropertiesID props = SDL_CreateProperties();
|
||||||
_beginthreadex(NULL, p_stack << 2, (ThreadFunc) &MxThread::ThreadProc, this, p_flag, &m_threadId))) {
|
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;
|
result = SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SDL_DestroyProperties(props);
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
@ -43,7 +49,7 @@ MxResult MxThread::Start(MxS32 p_stack, MxS32 p_flag)
|
|||||||
// FUNCTION: LEGO1 0x100bf660
|
// FUNCTION: LEGO1 0x100bf660
|
||||||
void MxThread::Sleep(MxS32 p_milliseconds)
|
void MxThread::Sleep(MxS32 p_milliseconds)
|
||||||
{
|
{
|
||||||
::Sleep(p_milliseconds);
|
SDL_Delay(p_milliseconds);
|
||||||
}
|
}
|
||||||
|
|
||||||
// FUNCTION: LEGO1 0x100bf670
|
// 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) |
|
| [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) |
|
| 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) |
|
| 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) |
|
| 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) |
|
| 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