Cavestory Mod API
Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | Friends | List of all members
ModeThreadInstance Class Reference

Easy multi-threading for modes. More...

#include <CSMAPI_BaseModeInstance.h>

Public Types

enum  ThreadState {
  THREAD_NOT_RUNNING = 0 , THREAD_STARTING = 1 , THREAD_RUNNING = 2 , THREAD_STOPPING = 3 ,
  THREAD_DELETABLE = 4
}
 Thread states. More...
 
typedef void(* ModeCallback_OnThreadComplete) (BaseModeInstance *pMode, ModeThreadInstance *pThread, void *pUserData)
 Callback function for when a thread completes.
 
typedef void(* ModeCallback_OnThreadLoop) (BaseModeInstance *pMode, ModeThreadInstance *pThread, void *pUserData)
 Callback function for when a thread completes.
 

Public Member Functions

 ModeThreadInstance ()
 Main constructor.
 
 ~ModeThreadInstance ()
 Deconstructor.
 
bool TryLockUnique ()
 Try to lock a critical part of code. More...
 
void LockUnique ()
 Lock a critical part of code.
 
void UnlockUnique ()
 Unlock a critical part of code.
 
bool Start ()
 Start the thread.
 
void End (int iResult=0)
 End the thread.
 
void WaitToFinish ()
 Wait for the thread to finish.
 
void Detach ()
 Detach this thread.
 
int GetResult ()
 Get the return result.
 

Static Public Member Functions

static bool TryLock ()
 Try to lock a critical part of code. More...
 
static void Lock ()
 Lock a critical part of code.
 
static void Unlock ()
 Unlock a critical part of code.
 

Protected Member Functions

bool InitThread (BaseModeInstance *pOwner, ModeCallback_OnThreadLoop pOnLoopFunc, ModeCallback_OnThreadComplete pOnCompleteFunc, void *pUserData=NULL)
 Initialize this thread instance. More...
 
void __Complete_And_Send_Result__ ()
 Complete this mode. More...
 

Protected Attributes

char m_ThreadName [128]
 The thread name.
 
ModeThreadId m_ThreadId
 This thread's local ID.
 
ModeCallback_OnThreadComplete m_OnComplete
 Called when the asynchronous operation ends, by any means.
 
ModeCallback_OnThreadComplete m_OnLoop
 Called every frame.
 
BaseModeInstancem_Owner
 The owner of this thread.
 
void * m_Thread
 The thread for this mode.
 
void * m_Mutex
 This thread's unique mutex.
 
ThreadState m_State
 The state of this thread.
 
bool m_Running
 This is controlled by the async function.
 
int m_Result
 The result from the async operation.
 
void * m_UserData
 Function callback userdata.
 

Friends

class BaseModeInstance
 
int ModeThreadInstance_AsyncFunc (void *ptr)
 

Detailed Description

Easy multi-threading for modes.

Member Enumeration Documentation

◆ ThreadState

Thread states.

Enumerator
THREAD_NOT_RUNNING 

Thread has not started running yet.

THREAD_STARTING 

Thread is starting.

THREAD_RUNNING 

Thread is running.

THREAD_STOPPING 

Thread is being forced to stop.

THREAD_DELETABLE 

Thread is ready to be deleted.

Member Function Documentation

◆ __Complete_And_Send_Result__()

void ModeThreadInstance::__Complete_And_Send_Result__ ( )
protected

Complete this mode.

Do not call this.

◆ InitThread()

bool ModeThreadInstance::InitThread ( BaseModeInstance pOwner,
ModeCallback_OnThreadLoop  pOnLoopFunc,
ModeCallback_OnThreadComplete  pOnCompleteFunc,
void *  pUserData = NULL 
)
protected

Initialize this thread instance.

Parameters
pOwnerThe owner of this thread.
pOnLoopFuncThe 'OnLoop' callback function.
pOnCompleteFuncThe 'OnComplete' callback function.
pUserDataThe user data for the callback functions.
Returns
Returns true on success, false otherwise.

◆ TryLock()

static bool ModeThreadInstance::TryLock ( )
static

Try to lock a critical part of code.

Returns
Returns true on success, false if it's already locked.

◆ TryLockUnique()

bool ModeThreadInstance::TryLockUnique ( )

Try to lock a critical part of code.

Returns
Returns true on success, false if it's already locked.

The documentation for this class was generated from the following file: