iv_timer(3)

✨ iv_timer β€” the ivykis programmer's manual, but make it cute ✨

okay bestie, welcome to iv_timer(3) πŸ’– this is the page where we learn how ivykis does timers β€” the little clock gremlins that go off when the system clock says it's time. no cap.


🌸 NAME 🌸

iv_timer_register, iv_timer_unregister, iv_timer_registered β€” deal with ivykis timers πŸŽ€


πŸ¦‹ SYNOPSIS πŸ¦‹

#include <iv.h>

struct iv_timer {
        struct timespec         expires;
        void                    *cookie;
        void                    (*handler)(void *);
};

void IV_TIMER_INIT(struct iv_timer *timer);
void iv_timer_register(struct iv_timer *timer);
void iv_timer_unregister(struct iv_timer *timer);
int iv_timer_registered(const struct iv_timer *timer);

πŸ’… DESCRIPTION πŸ’…

so here's the tea πŸ“. iv_timer_register registers a timer with the current thread's ivykis event loop, and iv_timer_unregister unregisters it. iconic duo, fr fr. and iv_timer_registered? that one just looks at a timer and tells you true if it's currently registered with ivykis. vibe check passed βœ….


now the main character moment πŸ‘‘: when a registered timer becomes 'ready' β€” which happens when the current system clock value becomes greater than or equal to the timer's ->expires member field β€” the callback function you put in ->handler gets called. it runs in the thread that the timer was registered in, and it gets ->cookie as its first and sole argument 🫢.

and then? the timer is transparently unregistered. it unregisters itself, no drama, no follow-up needed. it's giving self-sufficient queen πŸ’….


okay so ground rules πŸ“‹:

  • the application is allowed to change the ->cookie and ->handler members at any time ✨
  • the application is NOT allowed to change the ->expires member while the timer is registered 🚫
bestie this one matters. ->expires stays put while registered. don't touch it. i'm serious. πŸ™ˆ

more rules, because of course there are πŸ“œ:

  • a given struct iv_timer can only be registered in one thread at a time
  • a timer can only be unregistered in the thread that it was registered from β€” no cross-thread shenanigans, bestie πŸ’€

and the best part? there is no limit on the number of timers registered at once 🌈 register a thousand. register a million. slay ⭐

want actual programming examples? go see iv_examples(3) 🧚


πŸŽ€ SEE ALSO πŸŽ€


k byeeee, go write some timers bestie πŸ’–βœ¨πŸ¦‹πŸŒΈ

this page came from ivykis, dated 2010-08-15, and lives at iv_timer(3) β€” mwah, periodt πŸ’