Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Request: function to get active coroutine #3

Open
andrewwade opened this issue Jun 20, 2019 · 2 comments
Open

Request: function to get active coroutine #3

andrewwade opened this issue Jun 20, 2019 · 2 comments

Comments

@andrewwade
Copy link

Would be nice to get access to the active coroutine with a function call. Then using container_of will allow you to get the container struct.

New Function:

coru_t *coru_active(void) {
    return active_coru;
}

Helper macro:

#define container_of(ptr, type, member) ({  \
        const typeof( ((type *)0)->member ) *__mptr = (ptr); \
        (type *)( (char *)__mptr - offsetof(type,member) );})

Example:

struct task {
    int wait_time_ms;
    coru_t coru;
} my_task;

void task_wait(int ms) {
    coru_t *co = coru_active();
    if(co) {
        struct task * t = container_of(co, struct task, coru);
        t->wait_time_ms = ms;
        coru_yield();
    }
}
@geky
Copy link
Owner

geky commented Jul 21, 2019

Hi @andrewwade, thanks for creating an issue, sorry it's taken me so long to get to this. This is a good idea 👍 It can also be used as a general test if you're in a coroutine.

I'll see if I can add this next chance I get, but feel free to try to beat me to it.

@lygstate
Copy link

lygstate commented Jun 6, 2020

I wanna bite you for implement this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants