Timer

Overview

Functions to check if time expired

Copyright (C) 2004-2022 OKTET Labs Ltd. More…

// typedefs

typedef struct te_timer_t te_timer_t;

// structs

struct te_timer_t;

// global functions

te_errno te_timer_start(te_timer_t* timer, unsigned int timeout_s);
te_errno te_timer_restart(te_timer_t* timer, unsigned int timeout_s);
te_errno te_timer_stop(te_timer_t* timer);
te_errno te_timer_expired(te_timer_t* timer);

// macros

#define TE_TIMER_INIT

Detailed Documentation

Functions to check if time expired

Copyright (C) 2004-2022 OKTET Labs Ltd. All rights reserved.

Example of usage

Let’s assume we need to do some routine until certain time has expired

#include "te_timer.h"

te_timer_t timer = TE_TIMER_INIT;
te_errno rc;

CHECK_RC(te_timer_start(&timer, 3));
do {
    VSLEEP(1, "repeat some routine until the timer expires");
} while ((rc = te_timer_expired(&timer)) == 0);
CHECK_RC(te_timer_stop(&timer));
if (rc != TE_ETIMEDOUT)
    CHECK_RC(rc);

Typedefs

typedef struct te_timer_t te_timer_t

Timer context

Global Functions

te_errno te_timer_start(te_timer_t* timer, unsigned int timeout_s)

Start timer

Parameters:

timer

Timer handle

timeout_s

Timeout for triggering timer

Returns:

Status code

te_errno te_timer_restart(te_timer_t* timer, unsigned int timeout_s)

Restart already running or expired timer with a new timeout.

Parameters:

timer

Timer handle.

timeout_s

Timeout for triggering timer.

Returns:

Status code.

te_errno te_timer_stop(te_timer_t* timer)

Stop the timer and free its resources.

Parameters:

timer

Timer handle.

Returns:

Status code.

te_errno te_timer_expired(te_timer_t* timer)

Check whether timeout has expired or not.

It does not stop the timer if it expires, so te_timer_stop() should be called to free timer’s resources.

Parameters:

timer

Timer handle

0

Time has not expired yet

TE_ETIMEDOUT

Time has expired

Others

Internal error, there is no way to use this timer any more

Returns:

Status code

Macros

#define TE_TIMER_INIT

On-stack timer context initializer