Esempio n. 1
0
/**********************************************************************
 * 
 * Method:      waitfor()
 *
 * Description: Wait for the software timer to finish.
 *
 * Notes:    
 *
 * Returns:     0 on success, -1 if the timer is not running.
 *
 **********************************************************************/
int
Timer::waitfor()
{
    if (state != Active)
    {
        return (-1);
    }

    //
    // Wait for the timer to expire.
    //
    pMutex->take();

    //
    // Restart or idle the timer, depending on its type.
    //
    if (type == Periodic)
    {
        state = Active;
        timerList.insert(this);
    }
    else
    {
        pMutex->release();
        state = Idle;
    }

    return (0);

}   /* waitfor() */
Esempio n. 2
0
/**********************************************************************
 * 
 * Method:      start()
 *
 * Description: Start a software timer, based on the tick from the
 *              underlying hardware timer.
 *
 * Notes:    
 *
 * Returns:     0 on success, -1 if the timer is already in use.
 *
 **********************************************************************/
int
Timer::start(unsigned int nMilliseconds, TimerType timerType)
{
    if (state != Idle)
    {
        return (-1);
    }

    //
    // Take the mutex.  It will be released when the timer expires.
    //
    pMutex->take();

    //
    // Initialize the timer.
    //
    type   = timerType;
    length = nMilliseconds / MS_PER_TICK;
    state  = Active;

    //
    // Add the timer to the timer list.
    //
    timerList.insert(this);

    return (0);

}   /* start() */
Esempio n. 3
0
/**********************************************************************
 * 
 * Method:      isDone()
 *
 * Description: check for the software timer to finish.
 *
 * Notes:    
 *
 * Returns:     1 on success, 0 if the timer is running.
 *
 **********************************************************************/
int
Timer::isDone()
{
#if 0
    if (state != Active)
    {
        return (-1);    
        }
#endif

    //
    // Wait for the timer to expire.
    //
        if (state != Done)
                return 0;

        timerList.remove(this);

    //
    // Restart or idle the timer, depending on its type.
    //
    if (type == Periodic)
    {
        state = Active;
        timerList.insert(this);    
        }
    else
    {
        state = Idle;    
        }

    return 1;

}   /* isDone() */
Esempio n. 4
0
/**********************************************************************
 * 
 * Method:      waitfor()
 *
 * Description: Wait for the software timer to finish.
 *
 * Notes:    
 *
 * Returns:     0 on success, -1 if the timer is not running.
 *
 **********************************************************************/
int
Timer::waitfor()
{
    if (state != Active)
    {
        return (-1);    
	}

    //
    // Wait for the timer to expire.
    //
	while (state != Done);

	timerList.remove(this);

    //
    // Restart or idle the timer, depending on its type.
    //
    if (type == Periodic)
    {
        state = Active;
        timerList.insert(this);    
	}
    else
    {
        state = Idle;    
	}

    return (0);

}   /* waitfor() */
Esempio n. 5
0
/**********************************************************************
 * 
 * Method:      start()
 *
 * Description: Start a software timer, based on the tick from the
 *              underlying hardware timer.
 *
 * Notes:    
 *
 * Returns:     0 on success, -1 if the timer is already in use.
 *
 **********************************************************************/
int
Timer::start(unsigned int nMilliseconds, TimerType timerType)
{
    if (state != Idle)
    {
        return (-1);    
	}

    //
    // Initialize the software timer.
    //
    state  = Active;
    type   = timerType;
    length = nMilliseconds / MS_PER_TICK;

    //
    // Add the timer to the timer list.
    //
    timerList.insert(this);

    return (0);

}   /* start() */