|virtual OSAPITASK_ID_TYPE||GetId() const|
|void||SetName(const char *name)|
|virtual void||SetPriority(CDP::ThreadPriority priority)|
|virtual void||Stop(bool block = false)|
The OSAPITask wraps a thread/task running in the process space of the application.
- Declare the task/thread-function in your header-file like this:
static OSAPITASK TaskDoSomething( OSAPITASK_ARG );
- Add a OSAPITask member in your header-file like this:
- Create task method OSAPITASK TaskDoSomething( OSAPITASK_ARG ) in cpp-file.
- Start() the task by passing the address of TaskDoSomething().
- Use Stopped() inside the thread function to determine if the thread should terminate.
- Call Stop() from another thread to signal to the thread that it should stop.
- SetRunningFlag(false) is called from CDP when TaskDoSomething() returns.
- Use Running() to check if the thread has exited.
- Free the resources allocated to the thread after the thread has finished, when Running()
returnsfalse, by calling Delete().
Priority must be one of the these priorities (defined in CDPDefines.h for each OS):
- CDPTHREAD_PRIORITY_NORMAL (default)
Note: Use OSAPIThread class if you prefer to create a task object class with the thread function as a virtual member function.
See also OSAPIThread.
Member Function Documentation
Constructs an OSAPITask.
Closes the running thread.
Free resources allocated by Start().
The thread must have exited before calling this function, or the behaviour is undefined (never execute if Running() returns
OSAPITASK_HANDLE_TYPE OSAPITask::GetHandle() const
Returns the thread handle.
[virtual] OSAPITASK_ID_TYPE OSAPITask::GetId() const
Returns the thread ID.
Get task priority level.
In a Linux environment, this function can be used to check whether or not the task has called the OSAPISetThreadPriority function.
Returns the thread name.
Resume execution of the thread by calling the OS specific thread function.
false if the task is running or not.
CDP sets the Running flag to
false as the last thing, so this function can be used to check if the thread has exited. Returns
true if thread is running.
Sets the thread name to name.
Set task priority level.
Sets thread priority level.
Is set to
false by CDP to indicate that the thread has exited.
Signal to the thread function that it should terminate.
Set block to
true to have the function block until thread has stopped (upto 5 seconds then exit is forced).
The thread function should use this to detect that it should terminate.
Suspend execution of the thread by calling the OS specific thread function.