OSAPITask Class
The OSAPITask wraps a thread/task running in the process space of the application. More...
Header: | #include <OSAPI/Process/OSAPITask.h> |
Inherited By: |
Public Functions
OSAPITask() | |
virtual | ~OSAPITask() |
virtual void | Delete() |
OSAPITASK_HANDLE_TYPE | GetHandle() const |
virtual OSAPITASK_ID_TYPE | GetId() const |
virtual CDP::ThreadPriority | GetPriority() |
char * | Name() const |
virtual void | Resume() |
bool | Running() const |
void | SetName(const char *name) |
virtual void | SetPriority(CDP::ThreadPriority priority) |
void | SetRunningFlag(bool isRunning) |
virtual void | Start(OSAPITASK_START_ARGS) |
virtual void | Stop(bool block = false) |
bool | Stopped() const |
virtual void | Suspend() |
Detailed Description
The OSAPITask wraps a thread/task running in the process space of the application.
Usage
- 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:
OSAPITASK DoSomethingTask;
- 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()
returns
false, by calling Delete().
Priority levels
Priority must be one of the these priorities (defined in CDPDefines.h for each OS):
- CDPTHREAD_PRIORITY_IDLE
- CDPTHREAD_PRIORITY_LOWEST
- CDPTHREAD_PRIORITY_BELOW_NORMAL
- CDPTHREAD_PRIORITY_NORMAL (default)
- CDPTHREAD_PRIORITY_ABOVE_NORMAL
- CDPTHREAD_PRIORITY_HIGH
- CDPTHREAD_PRIORITY_ABOVEHIGH
- CDPTHREAD_PRIORITY_HIGHEST
Note: Stopped() will just return the state of the flag (set by calling Stop()). It does not tell if the Thread function has actually finished. Use Running() to check whether it is actually finished.
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
OSAPITask::OSAPITask()
Constructs an OSAPITask.
[virtual]
OSAPITask::~OSAPITask()
Closes the running thread.
[virtual]
void OSAPITask::Delete()
Free resources allocated by Start().
The thread must have exited before calling this function, or the behaviour is undefined (never execute if Running() returns true
)
OSAPITASK_HANDLE_TYPE OSAPITask::GetHandle() const
Returns the thread handle.
[virtual]
OSAPITASK_ID_TYPE OSAPITask::GetId() const
Returns the thread ID.
[virtual]
CDP::ThreadPriority OSAPITask::GetPriority()
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.
char *OSAPITask::Name() const
Returns the thread name.
[virtual]
void OSAPITask::Resume()
Resume execution of the thread by calling the OS specific thread function.
bool OSAPITask::Running() const
Returns true
or 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.
void OSAPITask::SetName(const char *name)
Sets the thread name to name.
[virtual]
void OSAPITask::SetPriority(CDP::ThreadPriority priority)
Set task priority level.
Sets thread priority level.
void OSAPITask::SetRunningFlag(bool isRunning)
Is set to false
by CDP to indicate that the thread has exited.
[virtual]
void OSAPITask::Start(OSAPITASK_START_ARGS)
[virtual]
void OSAPITask::Stop(bool block = false)
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).
bool OSAPITask::Stopped() const
The thread function should use this to detect that it should terminate.
[virtual]
void OSAPITask::Suspend()
Suspend execution of the thread by calling the OS specific thread function.
Get started with CDP Studio today
Let us help you take your great ideas and turn them into the products your customer will love.