KallistiOS git master
Independent SDK for the Sega Dreamcast
Loading...
Searching...
No Matches
oneshot_timer.h File Reference

One-shot timer support. More...

#include <sys/cdefs.h>

Go to the source code of this file.

Typedefs

typedef struct oneshot_timer oneshot_timer_t
 

Functions

oneshot_timer_toneshot_timer_create (void(*cb)(void *), void *data, unsigned int timeout_ms)
 Create a new one-shot timer.
 
void oneshot_timer_destroy (oneshot_timer_t *timer)
 Stop and destroy a one-shot timer.
 
void oneshot_timer_setup (oneshot_timer_t *timer, void(*cb)(void *), void *data, unsigned int timeout_ms)
 Re-configure a one-shot timer.
 
void oneshot_timer_start (oneshot_timer_t *timer)
 Start a one-shot timer.
 
void oneshot_timer_stop (oneshot_timer_t *timer)
 Stop a one-shot timer.
 
static void oneshot_timer_reset (oneshot_timer_t *timer)
 Reset a one-shot timer.
 

Detailed Description

One-shot timer support.

This file contains the one-shot timer API. A one-shot timer is a timer that will trigger an action (through a pre-registered callback) after a timeout expires.

Author
Paul Cercueil
See also
kos/thread.h
kos/worker_thread.h

Typedef Documentation

◆ oneshot_timer_t

typedef struct oneshot_timer oneshot_timer_t

Function Documentation

◆ oneshot_timer_create()

oneshot_timer_t * oneshot_timer_create ( void(* cb )(void *),
void * data,
unsigned int timeout_ms )

Create a new one-shot timer.

This function will create a one-shot timer using the specified callback, programmed to expire after the given timeout. The timer will be stopped by default and still need to be started using oneshot_timer_start().

Parameters
cbThe function to call in case the one-shot timer expires.
dataA parameter to pass to the function called.
timeout_msThe timeout value for the one-shot timer, in milliseconds.
Returns
The new one-shot timer on success, NULL on failure.
See also
oneshot_timer_destroy, oneshot_timer_start

◆ oneshot_timer_destroy()

void oneshot_timer_destroy ( oneshot_timer_t * timer)

Stop and destroy a one-shot timer.

This function will stop the one-shot timer and free its memory.

Parameters
timerA pointer to the one-shot timer.
See also
oneshot_timer_create

◆ oneshot_timer_reset()

static void oneshot_timer_reset ( oneshot_timer_t * timer)
inlinestatic

Reset a one-shot timer.

A convenience function to reset the one-shot timer by stopping it then starting it again.

Parameters
timerA pointer to the one-shot timer.
See also
oneshot_timer_start, oneshot_timer_stop

◆ oneshot_timer_setup()

void oneshot_timer_setup ( oneshot_timer_t * timer,
void(* cb )(void *),
void * data,
unsigned int timeout_ms )

Re-configure a one-shot timer.

This function can be used to change the registered callback or the timeout. Using it on a running timer is unsupported.

Parameters
timerA pointer to the one-shot timer.
cbThe function to call in case the one-shot timer expires.
dataA parameter to pass to the function called.
timeout_msThe timeout value for the one-shot timer, in milliseconds.
See also
oneshot_timer_stop, oneshot_timer_start

◆ oneshot_timer_start()

void oneshot_timer_start ( oneshot_timer_t * timer)

Start a one-shot timer.

This function will start the one-shot timer. If not stopped until the timeout value expires, the one-shot timer will call the registered callback function.

Parameters
timerA pointer to the one-shot timer.
See also
oneshot_timer_stop, oneshot_timer_reset

Referenced by oneshot_timer_t::oneshot_timer_reset().

◆ oneshot_timer_stop()

void oneshot_timer_stop ( oneshot_timer_t * timer)

Stop a one-shot timer.

This function will stop the one-shot timer. If it already expired, this function does nothing. If it did not expire yet, the one-shot timer is stopped and the registered callback won't be called.

Parameters
timerA pointer to the one-shot timer.
See also
oneshot_timer_start, oneshot_timer_reset

Referenced by oneshot_timer_t::oneshot_timer_reset().