Giter Site home page Giter Site logo

Comments (3)

chrysn avatar chrysn commented on June 18, 2024

A callback in the process context would need a caller in the process context.

ztimer callbacks are a relatively low-level (but thus performant) tool; they are supposed to send messages, unlock mutexes or otherwise interact with atomic data structures.

What do you want to achieve / what do you need an in-process callback for? Depending on your application, it may be suitable to defer work of your application until it has been unblocked by the timer, or to use the event thread.

from riot.

benpicco avatar benpicco commented on June 18, 2024

You might want to look into timeout events.
They are executed in the context of the event thread, e.g.

static void _event_cb(void *ctx)
{
    printf("This is executed in thread %u\n", thread_getpid());
}

int main(void)
{
    static event_timeout_t event_timeout;
    static event_callback_t event_cb = EVENT_CALLBACK_INIT(_event_cb, 0);

    event_timeout_ztimer_init(&event_timeout, ZTIMER_MSEC, EVENT_PRIO_MEDIUM, &event_cb.super);
    event_timeout_set(&event_timeout, 500); /* event will be triggered in 500 ms */
}

from riot.

maribu avatar maribu commented on June 18, 2024

timeout events is implementing the requested feature

from riot.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.