isle-portable/LEGO1/mxthread.h

59 lines
1.1 KiB
C
Raw Normal View History

#ifndef MXTHREAD_H
#define MXTHREAD_H
2023-07-12 17:12:03 -04:00
#include "compat.h"
#include "mxsemaphore.h"
2023-10-24 19:38:27 -04:00
#include "mxtypes.h"
class MxCore;
2023-10-24 19:38:27 -04:00
class MxThread {
public:
2023-10-24 19:38:27 -04:00
// Note: Comes before virtual destructor
virtual MxResult Run();
2023-10-24 19:38:27 -04:00
MxResult Start(int p_stack, int p_flag);
2023-10-24 19:38:27 -04:00
void Terminate();
2023-10-24 19:38:27 -04:00
void Sleep(MxS32 p_milliseconds);
2023-10-24 19:38:27 -04:00
// Inferred, not in DLL
inline MxBool IsRunning() { return m_running; }
protected:
2023-10-24 19:38:27 -04:00
MxThread();
public:
2023-10-24 19:38:27 -04:00
virtual ~MxThread();
private:
2023-10-24 19:38:27 -04:00
static unsigned ThreadProc(void* p_thread);
2023-10-24 19:38:27 -04:00
MxULong m_hThread;
MxU32 m_threadId;
MxBool m_running;
MxSemaphore m_semaphore;
};
2023-10-24 19:38:27 -04:00
class MxTickleThread : public MxThread {
public:
2023-10-24 19:38:27 -04:00
MxTickleThread(MxCore* p_target, int p_frequencyMS);
2023-10-24 19:38:27 -04:00
// Unclear at this time whether this function and the m_target field are
// actually a general "userdata" pointer in the base MxThread, but it seems
// like the only usage is with an MxTickleThread.
MxResult StartWithTarget(MxCore* p_target);
2023-10-24 19:38:27 -04:00
// Only inlined, no offset
virtual ~MxTickleThread() {}
2023-10-24 19:38:27 -04:00
MxResult Run() override;
private:
2023-10-24 19:38:27 -04:00
MxCore* m_target;
MxS32 m_frequencyMS;
};
2023-07-12 17:12:03 -04:00
#endif // MXTHREAD_H