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

Symmetric fibers #8

Open
dhil opened this issue Feb 28, 2025 · 0 comments
Open

Symmetric fibers #8

dhil opened this issue Feb 28, 2025 · 0 comments

Comments

@dhil
Copy link
Member

dhil commented Feb 28, 2025

Implement a variation of the fiber interface that offers symmetric switching. The WasmFX instantiation of the interface should take advantage of the switch instruction.

I think something like the following will do:

/** The abstract type of a fiber object. **/
typedef struct fiber* fiber_t;

/** The signature of a fiber entry point. **/
typedef void* (*fiber_entry_point_t)(fiber_t, void*);

/** Allocates a new fiber with the default stack size. **/
export("fiber_alloc")
fiber_t fiber_alloc(fiber_entry_point_t entry);

/** Reclaims the memory occupied by the fiber object. **/
export("fiber_free")
void fiber_free(fiber_t fiber);

/** Possible status codes for `fiber_resume`. **/
typedef enum { FIBER_OK = 0, FIBER_YIELD = 1, FIBER_ERROR = 2 } fiber_result_t;

/** Yields control to the given target. This function must be called
    from within a fiber context. **/
export("fiber_switch")
fiber_result_t fiber_switch(fiber_t target, void *arg);

/** Initialises the fiber runtime context. **/
export("fiber_main")
int fiber_main(int (*main)(int, char**), int, char**);
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

1 participant