Verdana,sans-serifArial; font-size:smaller;">
OsHndlT OsNewTimer( OsTicksT delay, OsHndlT task, OsEventsT events );
Function OsNewTimer() may be called by the client application to create a new one-shot event timer. The first argument is the delay time, in ticks, after which the timer should fire. This delay should not be zero. The second argument is a handle to the task to which events should be sent when the timer fires. The third argument is the pattern of events to be sent to the task. Any number of events may be set in this pattern. If no events are set, the timer will have no effect when it fires and is therefore useless.
The function returns a handle to the new timer if it was created successfully. Unless the application needs the option to destroy the timer, there is no need to save this handle. If a new timer cannot be created, for example due to the exhaustion of timer resources, the function returns OsHndl_NONE.
The example below shows a section of a task function that uses a timer to set a timeout on some process (which is not detailed in the example). The timer handle is saved so that the timer can be destroyed when the task receives event DONE_EVENT, indicating that the process is done. If the process does not complete in 100 time ticks, the first argument to OsNewTimer(), event TIMEOUT_EVENT will be sent to the task and it can take some sort of recovery action.
if ( OsAcceptEvents( START_EVENT ) )
{
StartMyProcess();
TimeoutTimer = OsNewTimer( 100, MyTask, TIMEOUT_EVENT );
}
else if ( OsAcceptEvents( DONE_EVENT ) )
{
if ( !OsAcceptEvents( TIMEOUT_EVENT ) )
OsDestroyTimer( TimeoutTimer );
GetMyProcessResults();
}
else if ( OsAcceptEvents( TIMEOUT_EVENT ) )
{
AbortMyProcess();
}