A base class for implementing INtime real time threads; the CIThread class exists only in the RT environment.
You can use the thread object in these ways:
Create a new executing thread by deriving a specific class from CIThread, which overrides either or both of the InitInstance and DoForever calls and the Create call is used for it.
It is a way to control an existing thread, which is created somewhere else and the CIThread object is used to control some attributes of the RT thread object.
Constructor
Destructor
Create
InitInstance
DoForever
ExitInstance
SuspendThread
ResumeThread
GetThreadPriority
SetThreadPriority
Sleep
The constructor, which has no arguments, creates an unattached object.
If the object is attached, the destructor detaches then destroys the object.
If the object is already attached, it is first detached. Then this call creates a new active RT thread object and attaches it to the object.
DWORD CIThread::Create( char * pszName, BYTE byPrio, DWORD dwStack, BOOLEAN bGo );
pszName
byPrio
dwStack
bGo
E_OK
E_MEM
E_LIMIT
E_SLOT
byPrio
contains a bad value, or the object directory is full.
E_PARAM
dwStack
contains a value of less than 2048, or the name is too long or is improperly formatted.
E_CONTEXT
The thread that is created executes code resembling this pattern (typically one or both of Init and DoForever will be overruled):
void ThreadCode() { if (!bGo) Suspend(); if (InitInstance()) while (DoForever()) ; ExitInstance(); Detach(); }
CIThread::InitInstance is called by the framework at the start of the thread and should never be called explicitly. It may be overruled to do some custom, one-time initialization. CIThread::InitInstance returns TRUE immediately.
BOOLEAN CIThread::InitInstance(void);
The result should be TRUE if the thread may continue, or FALSE if the thread should be terminated.
CIThread::DoForever is called by the framework in the body of the thread until it returns FALSE; it should never be called explicitly. CIThread::DoForever returns FALSE immediately, so it is typically overruled.
BOOLEAN CIThread::DoForever(void);
The result indicates if the thread should continue calling DoForever (TRUE) or should terminate (FALSE).
CIThread::ExitInstance is called by the framework before terminating the thread and should never be called explicitly. CIThread::ExitInstance returns zero immediately.
int CIThread::ExitInstance(void);
The result is a success indicator (zero means OK), but is currently ignored.
The thread member variable m_run is cleared which should cause the thread to delete itself. Using Terminate is recommended over using Delete as the latter may cause memory leaks.
BOOLEAN CIThread::Terminate(DWORD timout);
timeout is the number of milliseconds to poll for the thread to be gone; if less than 10, no wait is done.
The return value is TRUE if the thread has deleted itself within the timeout or FALSE if it did not.
BOOLEAN m_run;// if FALSE, causes DoForever to exit
This call suspends execution of a thread. It may be called more than once for a given thread (up to 255 times), in which case each call to SuspendThread must be offset by a call to ResumeThread. SuspendThread may also be called by a thread for itself.
DWORD CIThread::SuspendThread(void);
The result of this call indicates the success or failure.
E_OK
E_LIMIT
E_CONTEXT
E_EXIST
This call resumes execution of a thread that is in suspended state. It undoes one level of suspending.
DWORD CIThread::ResumeThread(void);
The result of this call indicates the success or failure.
E_OK
E_CONTEXT
E_EXIST
E_LIMIT
Use this call to obtain the priority of a thread.
BYTE CIThread::GetThreadPriority(void);
The result is either the priority of the thread (0 - 254) or the value BAD_PRIORITY if an error occurred (use GetLastError to obtain the actual error code).
E_OK
E_EXIST
With this call the priority of a thread can be changed; such a change may affect the scheduling of threads.
DWORD CIThread:SetThreadPriority( BYTE byPrio );
byPrio
E_OK
E_LIMIT
byPrio
contains a bad value.
E_CONTEXT
E_EXIST
This call puts the thread in an asleep state for a given period. Since the call is a static call, it can be called with a CIThread object, or with just the class name: CIThread::Sleep(..);
DWORD CIThread::Sleep( DWORD dwTime );
dwTime
E_OK
E_PARAM
dwTime
contains a bad value.