Local tick

5 views
Skip to first unread message

Denis

unread,
Mar 5, 2026, 4:42:41 AMMar 5
to tinymux
Hi Brazil an everyone else

Does TinyMUX have a way to define a local timer/tick in a simple way similar to how PennMUSH handles it in local.c :
...
void local_startup(void) {

/* Register local_timer to be called once a second. You can also
 * register other callbacks to run at other intervals. See local_timer()
 * below for an example of what the callback function needs to do if it
 * should be run more than once.
 *
 * Arguments are: Number of seconds from now to run, the callback function,
 * a data argument to pass to it, and a softcoded event name to run at the same
 * time. The latter two can be null pointers. The callback function returns true
 * if the softcode event should be triggered, false if it shouldn't.
 *
 * You can also register call backs in milliseconds, see below for example.

 */
#if 0 /* Change to 1 if you need local_timer functionality. */
  sq_register_loop(1, local_timer, NULL, NULL);
#endif
#if 0 /* As above, but in milliseconds */
sq_register_loop_msec(250, local_timer, NULL, NULL);
#endif
}
...

thanks
Denis

Stephen Dennis

unread,
Mar 5, 2026, 8:51:17 AMMar 5
to tin...@googlegroups.com
Hi Denis,

TinyMUX has local.cpp (inspired by Penn's local.c), which gives you hooks for startup, shutdown, connect/disconnect, object creation/destruction, and database dump events. You can add hardcoded commands and functions there too.

For a repeating timer specifically, TinyMUX uses its internal task scheduler. In local_startup(), you'd register a recurring task like this:

static void my_local_timer(void *pUnused, int iUnused)
{
    UNUSED_PARAMETER(pUnused);
    UNUSED_PARAMETER(iUnused);

    // Your periodic work here.

    // Re-schedule ourselves.
    CLinearTimeAbsolute ltaNow;
    ltaNow.GetUTC();
    CLinearTimeDelta ltd;
    ltd.SetSeconds(1);  // Run again in 1 second.
    scheduler.DeferTask(ltaNow + ltd, PRIORITY_OBJECT,
        my_local_timer, 0, 0);
}

void local_startup(void)
{
    // ... existing function/command registration ...

    // Start the timer.
    CLinearTimeAbsolute ltaNow;
    ltaNow.GetUTC();
    CLinearTimeDelta ltd;
    ltd.SetSeconds(1);
    scheduler.DeferTask(ltaNow + ltd, PRIORITY_OBJECT,
        my_local_timer, 0, 0);
}

This is the same pattern used internally for database checkpoints, idle checks, @daily, and keepalives — see timer.cpp for examples. The task re-schedules itself at the end of each invocation.

The scheduler works with CLinearTimeAbsolute/CLinearTimeDelta which support sub-second precision. There's no fixed tick rate — GANL blocks until either network I/O arrives or the next scheduled task is due, so timer resolution is limited only by the OS, not by polling.

  — Brazil

--

---
You received this message because you are subscribed to the Google Groups "tinymux" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tinymux+u...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/tinymux/9fa3d289-11a7-4f0b-a366-e74f65376444n%40googlegroups.com.

Denis Kaledin

unread,
Mar 5, 2026, 8:59:19 AMMar 5
to tin...@googlegroups.com
Thank you. I was digging through timer.cpp for that, but easier to inject into the local.cpp for sure.

Denis



--
Denis A. Kaledin
kaledin at gmail dot com
Reply all
Reply to author
Forward
0 new messages