Serene Runtime 1.0.0
C runtime for the Serene programming language
Loading...
Searching...
No Matches
01_hello.c File Reference
#include <stdio.h>
#include <serene/runtime.h>
Include dependency graph for 01_hello.c:

Go to the source code of this file.

Functions

static srn_fiber_result_t say_hello (srn_context_t *ctx, void *arg)
 
int main (void)
 

Variables

static int ok
 

Function Documentation

◆ main()

int main ( void )

Definition at line 45 of file 01_hello.c.

45 {
46 srn_mm_t *mm = srn_mm_init();
47 srn_engine_t *engine = srn_engine_make(mm);
48 srn_context_t *ctx = srn_context_make(engine);
49
50 // The engine creates one scheduler at startup and keeps it on `scheduler`.
51 srn_scheduler_t *sched = engine->scheduler;
52
53 // Create the fiber. It is registered and made ready, but nothing runs until
54 // the scheduler does.
55 srn_fiber_t *fiber = srn_fiber_make(ctx, sched, say_hello, nullptr, 0);
56
57 // Drive the scheduler on this one thread. It returns once the fiber has run
58 // and the ready queue is empty.
59 srn_sched_run(sched, 1);
60
61 printf("fiber finished in state %d\n", (int)fiber->state);
62
64 srn_engine_shutdown(engine);
66 return 0;
67}
static srn_fiber_result_t say_hello(srn_context_t *ctx, void *arg)
Definition 01_hello.c:38
srn_context_t * srn_context_make(srn_engine_t *engine)
Make an empty context, by allocating a new memory block.
Definition context.c:38
int srn_context_release(srn_context_t *ctx)
Definition context.c:63
srn_mm_t * srn_mm_init()
Initialize the memory manager, this function will panic on error.
Definition default.c:294
void srn_mm_shutdown(srn_mm_t *mm)
Shut down the memory manager and release the resources.
Definition default.c:325
srn_engine_t * srn_engine_make(srn_mm_t *mm)
Definition engine.c:92
void srn_engine_shutdown(srn_engine_t *engine)
Definition engine.c:123
srn_fiber_t * srn_fiber_make(srn_context_t *ctx, srn_scheduler_t *sched, srn_fiber_entry_t entry, void *arg, size_t stack_size)
Create a fiber that will run entry(ctx, arg).
Definition fiber.c:169
void srn_sched_run(srn_scheduler_t *sched, int nworkers)
Run the scheduler with nworkers os threads draining it, returning once the pool goes quiescent (every...
Definition scheduler.c:784
Engine is a structure to own the long living and main pieces of the compiler.
Definition engine.h:49
srn_scheduler_t * scheduler
The fiber scheduler, set by srn_sched_init.
Definition engine.h:67
_Atomic srn_fiber_state_t state
The lifecycle state.
Definition fiber.h:217
Main memory manager structure that will own all the allocated blocks and data.
Definition interface.h:112
Here is the call graph for this function:

◆ say_hello()

static srn_fiber_result_t say_hello ( srn_context_t * ctx,
void * arg )
static

Definition at line 38 of file 01_hello.c.

38 {
39 (void)ctx;
40 (void)arg;
41 printf("hello from a fiber\n");
42 return &ok;
43}
static int ok
Definition 01_hello.c:36
Here is the caller graph for this function:

Variable Documentation

◆ ok

int ok
static

Definition at line 36 of file 01_hello.c.