Skip to content

Symmetric fibers #8

@dhil

Description

@dhil

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**);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions