Serene Runtime 1.0.0-dev
C runtime for the Serene programming language
Loading...
Searching...
No Matches
runtime.h File Reference
Include dependency graph for runtime.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define SERENE_RUNTIME_INIT(engine, config)
 Declare engine and bring the runtime up, the memory manager first, then the engine over it, both reading config (a const srn_configuration_t *; null means the defaults).
#define SERENE_RUNTIME_INIT_WITH_SCHED(engine, sched, config)
 SERENE_RUNTIME_INIT plus a sched variable bound to the engine's scheduler, which every run and fiber call wants at hand.
#define SERENE_RUNTIME_SHUTDOWN(engine)
 Tear down what SERENE_RUNTIME_INIT brought up, in reverse order, the engine (reactor, scheduler, jit) and then the memory manager it lives in.
#define SERENE_MAIN(f)

Typedefs

typedef int(* srn_main_t) (srn_context_t *ctx, int argc, char *argv[])

Functions

int srn_run_fiber_main (srn_main_t m, int argc, char *argv[])

Macro Definition Documentation

◆ SERENE_MAIN

#define SERENE_MAIN ( f)
Value:
int main(int argc, char *argv[]) { return srn_run_fiber_main(&(f), argc, argv); }
int main(void)
Definition 01_hello.c:41
int srn_run_fiber_main(srn_main_t m, int argc, char *argv[])
Definition runtime.c:35

Definition at line 65 of file runtime.h.

65#define SERENE_MAIN(f) \
66 int main(int argc, char *argv[]) { return srn_run_fiber_main(&(f), argc, argv); }

◆ SERENE_RUNTIME_INIT

#define SERENE_RUNTIME_INIT ( engine,
config )
Value:
srn_engine_t *engine = srn_engine_make(srn_mm_init(config), (config)); \
PANIC_IF_NULL(engine)
srn_mm_t * srn_mm_init(const srn_configuration_t *config)
Initialize the memory manager, this function will panic on error.
Definition default.c:332
srn_engine_t * srn_engine_make(srn_mm_t *mm, const srn_configuration_t *config)
Create the engine over mm, copying config (the runtime's knobs) into it.
Definition engine.c:101
Engine is a structure to own the long living and main pieces of the compiler.
Definition engine.h:51

Declare engine and bring the runtime up, the memory manager first, then the engine over it, both reading config (a const srn_configuration_t *; null means the defaults).

config is evaluated more than once, so pass a plain pointer, not an expression with effects. Panics on failure.

Definition at line 38 of file runtime.h.

38#define SERENE_RUNTIME_INIT(engine, config) \
39 srn_engine_t *engine = srn_engine_make(srn_mm_init(config), (config)); \
40 PANIC_IF_NULL(engine)

◆ SERENE_RUNTIME_INIT_WITH_SCHED

#define SERENE_RUNTIME_INIT_WITH_SCHED ( engine,
sched,
config )
Value:
SERENE_RUNTIME_INIT(engine, config); \
srn_scheduler_t *sched = (engine)->scheduler; \
PANIC_IF_NULL(sched)
#define SERENE_RUNTIME_INIT(engine, config)
Declare engine and bring the runtime up, the memory manager first, then the engine over it,...
Definition runtime.h:38

SERENE_RUNTIME_INIT plus a sched variable bound to the engine's scheduler, which every run and fiber call wants at hand.

Definition at line 46 of file runtime.h.

46#define SERENE_RUNTIME_INIT_WITH_SCHED(engine, sched, config) \
47 SERENE_RUNTIME_INIT(engine, config); \
48 srn_scheduler_t *sched = (engine)->scheduler; \
49 PANIC_IF_NULL(sched)

◆ SERENE_RUNTIME_SHUTDOWN

#define SERENE_RUNTIME_SHUTDOWN ( engine)
Value:
do { \
srn_mm_t *serene_mm_ = (engine)->mm; \
srn_engine_shutdown(engine); \
srn_mm_shutdown(serene_mm_); \
} while (0)
Main memory manager structure that will own all the allocated blocks and data.
Definition interface.h:110

Tear down what SERENE_RUNTIME_INIT brought up, in reverse order, the engine (reactor, scheduler, jit) and then the memory manager it lives in.

Contexts need no separate release beforehand; the manager reclaims every chain. Release a context earlier only to reclaim its memory early, and only when no unreaped fiber lives in it.

Definition at line 58 of file runtime.h.

58#define SERENE_RUNTIME_SHUTDOWN(engine) \
59 do { \
60 srn_mm_t *serene_mm_ = (engine)->mm; \
61 srn_engine_shutdown(engine); \
62 srn_mm_shutdown(serene_mm_); \
63 } while (0)

Typedef Documentation

◆ srn_main_t

typedef int(* srn_main_t) (srn_context_t *ctx, int argc, char *argv[])

Definition at line 68 of file runtime.h.

Function Documentation

◆ srn_run_fiber_main()

int srn_run_fiber_main ( srn_main_t m,
int argc,
char * argv[] )

Definition at line 35 of file runtime.c.

35 {
36 SERENE_RUNTIME_INIT_WITH_SCHED(engine, sched, nullptr);
37 srn_context_t *ctx = srn_context_make(engine);
38
40 .main_f = m,
41 .out = 0,
42 .argc = argc,
43 .argv = argv,
44
45 };
46
47 SRN_TRACEPOINT(serene_main_start);
49 srn_sched_run(sched, 0);
50 SRN_TRACEPOINT(serene_main_end);
51
54 return args.out;
55}
va_list args
Definition acutest.h:876
srn_context_t * srn_context_make(srn_engine_t *engine)
Make an empty context, by allocating a new memory block.
Definition context.c:39
int srn_context_release(srn_context_t *ctx)
Definition context.c:64
srn_fiber_t * srn_fiber_spawn(srn_context_t *ctx, srn_fiber_entry_t entry, void *arg)
Make and schedule a fiber with every default, the engine's scheduler, the configured stack size,...
Definition fiber.c:245
static srn_fiber_result_t main_fiber_wrapper(srn_context_t *ctx, void *args)
Definition runtime.c:28
#define SERENE_RUNTIME_SHUTDOWN(engine)
Tear down what SERENE_RUNTIME_INIT brought up, in reverse order, the engine (reactor,...
Definition runtime.h:58
#define SERENE_RUNTIME_INIT_WITH_SCHED(engine, sched, config)
SERENE_RUNTIME_INIT plus a sched variable bound to the engine's scheduler, which every run and fiber ...
Definition runtime.h:46
void srn_sched_run(srn_scheduler_t *sched, size_t nworkers)
Run the scheduler with nworkers os threads draining it, returning once the pool goes quiescent (every...
Definition scheduler.c:875
#define SRN_TRACEPOINT(name,...)
Placement matters.
Definition trace.h:79
Here is the call graph for this function: