Isle
Loading...
Searching...
No Matches
mxthread.cpp
Go to the documentation of this file.
1#include "mxthread.h"
2
3#include "decomp.h"
4
5#include <process.h>
6
8
9// FUNCTION: LEGO1 0x100bf510
11{
12 m_hThread = NULL;
13 m_running = TRUE;
14 m_threadId = 0;
15}
16
17// FUNCTION: LEGO1 0x100bf5a0
19{
20 if (m_hThread) {
21 CloseHandle((HANDLE) m_hThread);
22 }
23}
24
25typedef unsigned(__stdcall* ThreadFunc)(void*);
26
27// FUNCTION: LEGO1 0x100bf610
28MxResult MxThread::Start(MxS32 p_stackSize, MxS32 p_flag)
29{
30 MxResult result = FAILURE;
31
32 if (m_semaphore.Init(0, 1) == SUCCESS) {
33 if ((m_hThread =
34 _beginthreadex(NULL, p_stackSize * 4, (ThreadFunc) &MxThread::ThreadProc, this, p_flag, &m_threadId)
35 )) {
36 result = SUCCESS;
37 }
38 }
39
40 return result;
41}
42
43// FUNCTION: LEGO1 0x100bf660
44void MxThread::Sleep(MxS32 p_milliseconds)
45{
46 ::Sleep(p_milliseconds);
47}
48
49// FUNCTION: LEGO1 0x100bf670
51{
52 m_running = FALSE;
53 m_semaphore.Wait(INFINITE);
54}
55
56// FUNCTION: LEGO1 0x100bf680
57unsigned MxThread::ThreadProc(void* p_thread)
58{
59 return static_cast<MxThread*>(p_thread)->Run();
60}
61
62// FUNCTION: LEGO1 0x100bf690
64{
65 m_semaphore.Release(1);
66 return SUCCESS;
67}
virtual MxResult Init(MxU32 p_initialCount, MxU32 p_maxCount)
Initializes the semaphore with both initial and maximum counts.
Definition: mxsemaphore.cpp:15
void Release(MxU32 p_releaseCount)
Increases the semaphore count, unblocking waiting threads if any.
Definition: mxsemaphore.cpp:33
void Wait(MxU32 p_timeoutMS)
Waits on the semaphore for the specified timeout (in milliseconds).
Definition: mxsemaphore.cpp:27
[AI] Abstract thread class providing a platform-independent interface for thread management.
Definition: mxthread.h:17
virtual ~MxThread()
[AI] Virtual destructor for MxThread.
Definition: mxthread.cpp:18
void Terminate()
[AI] Signals the thread to terminate.
Definition: mxthread.cpp:50
virtual MxResult Run()
[AI] Virtual function executed when the thread runs.
Definition: mxthread.cpp:63
MxResult Start(MxS32 p_stackSize, MxS32 p_flag)
[AI] Starts the thread with a given stack size and creation flags.
Definition: mxthread.cpp:28
void Sleep(MxS32 p_milliseconds)
[AI] Sleeps the current thread for the given duration in milliseconds.
Definition: mxthread.cpp:44
#define TRUE
Definition: d3drmdef.h:28
#define FALSE
Definition: d3drmdef.h:27
#define DECOMP_SIZE_ASSERT(T, S)
Definition: decomp.h:19
#define NULL
[AI] Null pointer value (C/C++ semantics).
Definition: legotypes.h:26
#define FAILURE
[AI] Used to indicate a failed operation in result codes.
Definition: legotypes.h:34
#define SUCCESS
[AI] Used to indicate a successful operation in result codes.
Definition: legotypes.h:30
unsigned(__stdcall * ThreadFunc)(void *)
Definition: mxthread.cpp:25
MxLong MxResult
[AI]
Definition: mxtypes.h:106
signed int MxS32
[AI]
Definition: mxtypes.h:38