timer_list.h

Include dependency graph for timer_list.h:

digraph {
    graph [bgcolor="#00000000"]
    node [shape=rectangle style=filled fillcolor="#FFFFFF" font=Helvetica padding=2]
    edge [color="#1414CE"]
    "2" [label="stdbool.h" tooltip="stdbool.h"]
    "4" [label="list.h" tooltip="list.h"]
    "3" [label="stdint.h" tooltip="stdint.h"]
    "1" [label="/__w/AtomVM/AtomVM/src/libAtomVM/timer_list.h" tooltip="/__w/AtomVM/AtomVM/src/libAtomVM/timer_list.h" fillcolor="#BFBFBF"]
    "1" -> "2" [dir=forward tooltip="include"]
    "1" -> "3" [dir=forward tooltip="include"]
    "1" -> "4" [dir=forward tooltip="include"]
}

This graph shows which files directly or indirectly include timer_list.h:

digraph {
    graph [bgcolor="#00000000"]
    node [shape=rectangle style=filled fillcolor="#FFFFFF" font=Helvetica padding=2]
    edge [color="#1414CE"]
    "23" [label="/__w/AtomVM/AtomVM/src/libAtomVM/interop.c" tooltip="/__w/AtomVM/AtomVM/src/libAtomVM/interop.c"]
    "16" [label="/__w/AtomVM/AtomVM/src/libAtomVM/refc_binary.c" tooltip="/__w/AtomVM/AtomVM/src/libAtomVM/refc_binary.c"]
    "19" [label="/__w/AtomVM/AtomVM/src/libAtomVM/interop.h" tooltip="/__w/AtomVM/AtomVM/src/libAtomVM/interop.h"]
    "11" [label="/__w/AtomVM/AtomVM/src/libAtomVM/erl_nif_priv.h" tooltip="/__w/AtomVM/AtomVM/src/libAtomVM/erl_nif_priv.h"]
    "6" [label="/__w/AtomVM/AtomVM/src/libAtomVM/nifs.c" tooltip="/__w/AtomVM/AtomVM/src/libAtomVM/nifs.c"]
    "31" [label="/__w/AtomVM/AtomVM/src/libAtomVM/nifs.h" tooltip="/__w/AtomVM/AtomVM/src/libAtomVM/nifs.h"]
    "43" [label="/__w/AtomVM/AtomVM/src/libAtomVM/defaultatoms.h" tooltip="/__w/AtomVM/AtomVM/src/libAtomVM/defaultatoms.h"]
    "44" [label="/__w/AtomVM/AtomVM/src/libAtomVM/dictionary.c" tooltip="/__w/AtomVM/AtomVM/src/libAtomVM/dictionary.c"]
    "7" [label="/__w/AtomVM/AtomVM/src/libAtomVM/context.c" tooltip="/__w/AtomVM/AtomVM/src/libAtomVM/context.c"]
    "4" [label="/__w/AtomVM/AtomVM/src/libAtomVM/bif.c" tooltip="/__w/AtomVM/AtomVM/src/libAtomVM/bif.c"]
    "2" [label="/__w/AtomVM/AtomVM/src/libAtomVM/context.h" tooltip="/__w/AtomVM/AtomVM/src/libAtomVM/context.h"]
    "3" [label="/__w/AtomVM/AtomVM/src/libAtomVM/bif.h" tooltip="/__w/AtomVM/AtomVM/src/libAtomVM/bif.h"]
    "24" [label="/__w/AtomVM/AtomVM/src/libAtomVM/otp_crypto.c" tooltip="/__w/AtomVM/AtomVM/src/libAtomVM/otp_crypto.c"]
    "32" [label="/__w/AtomVM/AtomVM/src/libAtomVM/otp_crypto.h" tooltip="/__w/AtomVM/AtomVM/src/libAtomVM/otp_crypto.h"]
    "10" [label="/__w/AtomVM/AtomVM/src/libAtomVM/memory.c" tooltip="/__w/AtomVM/AtomVM/src/libAtomVM/memory.c"]
    "30" [label="/__w/AtomVM/AtomVM/src/libAtomVM/sys.h" tooltip="/__w/AtomVM/AtomVM/src/libAtomVM/sys.h"]
    "5" [label="/__w/AtomVM/AtomVM/src/libAtomVM/module.c" tooltip="/__w/AtomVM/AtomVM/src/libAtomVM/module.c"]
    "26" [label="/__w/AtomVM/AtomVM/src/libAtomVM/module.h" tooltip="/__w/AtomVM/AtomVM/src/libAtomVM/module.h"]
    "22" [label="/__w/AtomVM/AtomVM/src/libAtomVM/otp_net.c" tooltip="/__w/AtomVM/AtomVM/src/libAtomVM/otp_net.c"]
    "33" [label="/__w/AtomVM/AtomVM/src/libAtomVM/otp_net.h" tooltip="/__w/AtomVM/AtomVM/src/libAtomVM/otp_net.h"]
    "17" [label="/__w/AtomVM/AtomVM/src/libAtomVM/resources.c" tooltip="/__w/AtomVM/AtomVM/src/libAtomVM/resources.c"]
    "21" [label="/__w/AtomVM/AtomVM/src/libAtomVM/inet.c" tooltip="/__w/AtomVM/AtomVM/src/libAtomVM/inet.c"]
    "25" [label="/__w/AtomVM/AtomVM/src/libAtomVM/term.c" tooltip="/__w/AtomVM/AtomVM/src/libAtomVM/term.c"]
    "20" [label="/__w/AtomVM/AtomVM/src/libAtomVM/inet.h" tooltip="/__w/AtomVM/AtomVM/src/libAtomVM/inet.h"]
    "9" [label="/__w/AtomVM/AtomVM/src/libAtomVM/debug.c" tooltip="/__w/AtomVM/AtomVM/src/libAtomVM/debug.c"]
    "8" [label="/__w/AtomVM/AtomVM/src/libAtomVM/debug.h" tooltip="/__w/AtomVM/AtomVM/src/libAtomVM/debug.h"]
    "18" [label="/__w/AtomVM/AtomVM/src/libAtomVM/externalterm.c" tooltip="/__w/AtomVM/AtomVM/src/libAtomVM/externalterm.c"]
    "42" [label="/__w/AtomVM/AtomVM/src/libAtomVM/avmpack.c" tooltip="/__w/AtomVM/AtomVM/src/libAtomVM/avmpack.c"]
    "41" [label="/__w/AtomVM/AtomVM/src/libAtomVM/avmpack.h" tooltip="/__w/AtomVM/AtomVM/src/libAtomVM/avmpack.h"]
    "12" [label="/__w/AtomVM/AtomVM/src/libAtomVM/globalcontext.c" tooltip="/__w/AtomVM/AtomVM/src/libAtomVM/globalcontext.c"]
    "40" [label="/__w/AtomVM/AtomVM/src/libAtomVM/globalcontext.h" tooltip="/__w/AtomVM/AtomVM/src/libAtomVM/globalcontext.h"]
    "27" [label="/__w/AtomVM/AtomVM/src/libAtomVM/platform_nifs.h" tooltip="/__w/AtomVM/AtomVM/src/libAtomVM/platform_nifs.h"]
    "38" [label="/__w/AtomVM/AtomVM/src/libAtomVM/scheduler.h" tooltip="/__w/AtomVM/AtomVM/src/libAtomVM/scheduler.h"]
    "13" [label="/__w/AtomVM/AtomVM/src/libAtomVM/otp_socket.c" tooltip="/__w/AtomVM/AtomVM/src/libAtomVM/otp_socket.c"]
    "34" [label="/__w/AtomVM/AtomVM/src/libAtomVM/otp_socket.h" tooltip="/__w/AtomVM/AtomVM/src/libAtomVM/otp_socket.h"]
    "29" [label="/__w/AtomVM/AtomVM/src/libAtomVM/stacktrace.c" tooltip="/__w/AtomVM/AtomVM/src/libAtomVM/stacktrace.c"]
    "28" [label="/__w/AtomVM/AtomVM/src/libAtomVM/stacktrace.h" tooltip="/__w/AtomVM/AtomVM/src/libAtomVM/stacktrace.h"]
    "14" [label="/__w/AtomVM/AtomVM/src/libAtomVM/otp_ssl.c" tooltip="/__w/AtomVM/AtomVM/src/libAtomVM/otp_ssl.c"]
    "46" [label="/__w/AtomVM/AtomVM/src/libAtomVM/timer_list.c" tooltip="/__w/AtomVM/AtomVM/src/libAtomVM/timer_list.c"]
    "35" [label="/__w/AtomVM/AtomVM/src/libAtomVM/otp_ssl.h" tooltip="/__w/AtomVM/AtomVM/src/libAtomVM/otp_ssl.h"]
    "1" [label="/__w/AtomVM/AtomVM/src/libAtomVM/timer_list.h" tooltip="/__w/AtomVM/AtomVM/src/libAtomVM/timer_list.h" fillcolor="#BFBFBF"]
    "15" [label="/__w/AtomVM/AtomVM/src/libAtomVM/posix_nifs.c" tooltip="/__w/AtomVM/AtomVM/src/libAtomVM/posix_nifs.c"]
    "45" [label="/__w/AtomVM/AtomVM/src/libAtomVM/posix_nifs.h" tooltip="/__w/AtomVM/AtomVM/src/libAtomVM/posix_nifs.h"]
    "39" [label="/__w/AtomVM/AtomVM/src/libAtomVM/mailbox.c" tooltip="/__w/AtomVM/AtomVM/src/libAtomVM/mailbox.c"]
    "36" [label="/__w/AtomVM/AtomVM/src/libAtomVM/port.c" tooltip="/__w/AtomVM/AtomVM/src/libAtomVM/port.c"]
    "37" [label="/__w/AtomVM/AtomVM/src/libAtomVM/port.h" tooltip="/__w/AtomVM/AtomVM/src/libAtomVM/port.h"]
    "19" -> "20" [dir=back tooltip="include"]
    "19" -> "23" [dir=back tooltip="include"]
    "19" -> "6" [dir=back tooltip="include"]
    "19" -> "24" [dir=back tooltip="include"]
    "19" -> "22" [dir=back tooltip="include"]
    "19" -> "13" [dir=back tooltip="include"]
    "19" -> "14" [dir=back tooltip="include"]
    "19" -> "15" [dir=back tooltip="include"]
    "19" -> "25" [dir=back tooltip="include"]
    "11" -> "7" [dir=back tooltip="include"]
    "11" -> "12" [dir=back tooltip="include"]
    "11" -> "10" [dir=back tooltip="include"]
    "11" -> "13" [dir=back tooltip="include"]
    "11" -> "14" [dir=back tooltip="include"]
    "11" -> "15" [dir=back tooltip="include"]
    "11" -> "16" [dir=back tooltip="include"]
    "11" -> "17" [dir=back tooltip="include"]
    "31" -> "5" [dir=back tooltip="include"]
    "31" -> "6" [dir=back tooltip="include"]
    "31" -> "24" [dir=back tooltip="include"]
    "31" -> "32" [dir=back tooltip="include"]
    "31" -> "22" [dir=back tooltip="include"]
    "31" -> "33" [dir=back tooltip="include"]
    "31" -> "13" [dir=back tooltip="include"]
    "31" -> "34" [dir=back tooltip="include"]
    "31" -> "14" [dir=back tooltip="include"]
    "31" -> "35" [dir=back tooltip="include"]
    "31" -> "15" [dir=back tooltip="include"]
    "43" -> "4" [dir=back tooltip="include"]
    "43" -> "44" [dir=back tooltip="include"]
    "43" -> "12" [dir=back tooltip="include"]
    "43" -> "23" [dir=back tooltip="include"]
    "43" -> "6" [dir=back tooltip="include"]
    "43" -> "24" [dir=back tooltip="include"]
    "43" -> "22" [dir=back tooltip="include"]
    "43" -> "13" [dir=back tooltip="include"]
    "43" -> "14" [dir=back tooltip="include"]
    "43" -> "36" [dir=back tooltip="include"]
    "43" -> "37" [dir=back tooltip="include"]
    "43" -> "15" [dir=back tooltip="include"]
    "43" -> "17" [dir=back tooltip="include"]
    "43" -> "29" [dir=back tooltip="include"]
    "2" -> "3" [dir=back tooltip="include"]
    "2" -> "7" [dir=back tooltip="include"]
    "2" -> "8" [dir=back tooltip="include"]
    "2" -> "11" [dir=back tooltip="include"]
    "2" -> "18" [dir=back tooltip="include"]
    "2" -> "12" [dir=back tooltip="include"]
    "2" -> "19" [dir=back tooltip="include"]
    "2" -> "10" [dir=back tooltip="include"]
    "2" -> "5" [dir=back tooltip="include"]
    "2" -> "26" [dir=back tooltip="include"]
    "2" -> "6" [dir=back tooltip="include"]
    "2" -> "31" [dir=back tooltip="include"]
    "2" -> "24" [dir=back tooltip="include"]
    "2" -> "22" [dir=back tooltip="include"]
    "2" -> "13" [dir=back tooltip="include"]
    "2" -> "14" [dir=back tooltip="include"]
    "2" -> "36" [dir=back tooltip="include"]
    "2" -> "37" [dir=back tooltip="include"]
    "2" -> "16" [dir=back tooltip="include"]
    "2" -> "17" [dir=back tooltip="include"]
    "2" -> "38" [dir=back tooltip="include"]
    "2" -> "28" [dir=back tooltip="include"]
    "2" -> "25" [dir=back tooltip="include"]
    "3" -> "4" [dir=back tooltip="include"]
    "3" -> "5" [dir=back tooltip="include"]
    "3" -> "6" [dir=back tooltip="include"]
    "32" -> "24" [dir=back tooltip="include"]
    "30" -> "7" [dir=back tooltip="include"]
    "30" -> "12" [dir=back tooltip="include"]
    "30" -> "5" [dir=back tooltip="include"]
    "30" -> "6" [dir=back tooltip="include"]
    "30" -> "13" [dir=back tooltip="include"]
    "30" -> "17" [dir=back tooltip="include"]
    "26" -> "3" [dir=back tooltip="include"]
    "26" -> "5" [dir=back tooltip="include"]
    "26" -> "6" [dir=back tooltip="include"]
    "26" -> "27" [dir=back tooltip="include"]
    "26" -> "28" [dir=back tooltip="include"]
    "26" -> "30" [dir=back tooltip="include"]
    "26" -> "25" [dir=back tooltip="include"]
    "33" -> "22" [dir=back tooltip="include"]
    "20" -> "21" [dir=back tooltip="include"]
    "20" -> "22" [dir=back tooltip="include"]
    "20" -> "13" [dir=back tooltip="include"]
    "20" -> "14" [dir=back tooltip="include"]
    "8" -> "9" [dir=back tooltip="include"]
    "8" -> "10" [dir=back tooltip="include"]
    "41" -> "42" [dir=back tooltip="include"]
    "41" -> "12" [dir=back tooltip="include"]
    "41" -> "6" [dir=back tooltip="include"]
    "40" -> "41" [dir=back tooltip="include"]
    "40" -> "7" [dir=back tooltip="include"]
    "40" -> "2" [dir=back tooltip="include"]
    "40" -> "43" [dir=back tooltip="include"]
    "40" -> "12" [dir=back tooltip="include"]
    "40" -> "10" [dir=back tooltip="include"]
    "40" -> "5" [dir=back tooltip="include"]
    "40" -> "26" [dir=back tooltip="include"]
    "40" -> "6" [dir=back tooltip="include"]
    "40" -> "24" [dir=back tooltip="include"]
    "40" -> "22" [dir=back tooltip="include"]
    "40" -> "33" [dir=back tooltip="include"]
    "40" -> "13" [dir=back tooltip="include"]
    "40" -> "34" [dir=back tooltip="include"]
    "40" -> "14" [dir=back tooltip="include"]
    "40" -> "35" [dir=back tooltip="include"]
    "40" -> "36" [dir=back tooltip="include"]
    "40" -> "37" [dir=back tooltip="include"]
    "40" -> "15" [dir=back tooltip="include"]
    "40" -> "45" [dir=back tooltip="include"]
    "40" -> "38" [dir=back tooltip="include"]
    "40" -> "29" [dir=back tooltip="include"]
    "40" -> "30" [dir=back tooltip="include"]
    "27" -> "6" [dir=back tooltip="include"]
    "38" -> "12" [dir=back tooltip="include"]
    "38" -> "39" [dir=back tooltip="include"]
    "38" -> "6" [dir=back tooltip="include"]
    "38" -> "13" [dir=back tooltip="include"]
    "34" -> "13" [dir=back tooltip="include"]
    "34" -> "14" [dir=back tooltip="include"]
    "28" -> "29" [dir=back tooltip="include"]
    "35" -> "14" [dir=back tooltip="include"]
    "1" -> "2" [dir=back tooltip="include"]
    "1" -> "40" [dir=back tooltip="include"]
    "1" -> "46" [dir=back tooltip="include"]
    "45" -> "12" [dir=back tooltip="include"]
    "45" -> "6" [dir=back tooltip="include"]
    "45" -> "13" [dir=back tooltip="include"]
    "45" -> "15" [dir=back tooltip="include"]
    "37" -> "21" [dir=back tooltip="include"]
    "37" -> "6" [dir=back tooltip="include"]
    "37" -> "22" [dir=back tooltip="include"]
    "37" -> "13" [dir=back tooltip="include"]
    "37" -> "14" [dir=back tooltip="include"]
    "37" -> "36" [dir=back tooltip="include"]
}

Typedefs

void() timer_list_callback_t (struct TimerListItem *)

Functions

static inline void timer_list_init(struct TimerList *tw)
static inline void timer_list_insert(struct TimerList *tw, struct TimerListItem *item)
static inline void timer_list_remove(struct TimerList *tw, struct TimerListItem *item)
static inline bool timer_list_is_empty(const struct TimerList *tw)
static inline int timer_list_timers_count(const struct TimerList *tw)
static inline void timer_list_item_init(struct TimerListItem *it, uint64_t expiry)
void timer_list_next(struct TimerList *tw, uint64_t now, timer_list_callback_t cb)

process the timer wheel, calling cb for every item that should be fired (for which expiry_time <= now).

The current algorithm is very basic. Under heavy load, two processes scheduled for different timers might be triggered (same seems to be true with BEAM). The only optimization is the next time is saved so the function doesn’t run every timer on every call.

Parameters:
  • tw – the timer wheel

  • now – the current monotonic date

  • cb – the callback

struct TimerList
#include <timer_list.h>

Collaboration diagram for TimerList:

digraph {
    graph [bgcolor="#00000000"]
    node [shape=rectangle style=filled fillcolor="#FFFFFF" font=Helvetica padding=2]
    edge [color="#1414CE"]
    "2" [label="ListHead" tooltip="ListHead"]
    "1" [label="TimerList" tooltip="TimerList" fillcolor="#BFBFBF"]
    "2" -> "2" [dir=forward tooltip="usage"]
    "1" -> "2" [dir=forward tooltip="usage"]
}

Public Members

struct ListHead head
int timers
uint64_t next_timer
struct TimerListItem
#include <timer_list.h>

Collaboration diagram for TimerListItem:

digraph {
    graph [bgcolor="#00000000"]
    node [shape=rectangle style=filled fillcolor="#FFFFFF" font=Helvetica padding=2]
    edge [color="#1414CE"]
    "2" [label="ListHead" tooltip="ListHead"]
    "1" [label="TimerListItem" tooltip="TimerListItem" fillcolor="#BFBFBF"]
    "2" -> "2" [dir=forward tooltip="usage"]
    "1" -> "2" [dir=forward tooltip="usage"]
}

Public Members

uint64_t expiry_time
struct ListHead head