Serene Runtime
1.0.0-dev
C runtime for the Serene programming language
Loading...
Searching...
No Matches
runtime.h
Go to the documentation of this file.
1
/* -*- C -*-
2
* Serene programming language
3
* Copyright (C) 2019-2026 Sameer Rahmani <
[email protected]
>
4
*
5
* This library is free software: you can redistribute it and/or modify
6
* it under the terms of the GNU Lesser General Public License as published by
7
* the Free Software Foundation, either version 3 of the License, or
8
* (at your option) any later version.
9
*
10
* This library is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU Lesser General Public License for more details.
14
*
15
* You should have received a copy of the GNU Lesser General Public License
16
* along with this library. If not, see <https://www.gnu.org/licenses/>.
17
*/
18
19
// This header file suppose to be a simple way for client programs
20
// to include the runtime
21
#pragma once
22
23
#include <
serene/rt/context.h
>
24
#include <
serene/rt/engine.h
>
25
#include <
serene/rt/fiber.h
>
26
#include <
serene/rt/mm/interface.h
>
27
#include <
serene/utils.h
>
28
29
// -----------------------------------------------------------------------------
30
// Bootstrapping helpers
31
// -----------------------------------------------------------------------------
32
/**
33
* Declare `engine` and bring the runtime up, the memory manager first, then
34
* the engine over it, both reading `config` (a `const srn_configuration_t
35
* *`; null means the defaults). `config` is evaluated more than once, so
36
* pass a plain pointer, not an expression with effects. Panics on failure.
37
*/
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)
41
42
/**
43
* SERENE_RUNTIME_INIT plus a `sched` variable bound to the engine's
44
* scheduler, which every run and fiber call wants at hand.
45
*/
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)
50
51
/**
52
* Tear down what SERENE_RUNTIME_INIT brought up, in reverse order, the
53
* engine (reactor, scheduler, jit) and then the memory manager it lives in.
54
* Contexts need no separate release beforehand; the manager reclaims every
55
* chain. Release a context earlier only to reclaim its memory early, and
56
* only when no unreaped fiber lives in it.
57
*/
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)
context.h
engine.h
fiber.h
AI Generated (🤦) Fiber subsystem overview.
interface.h
Notes:
utils.h
serene
runtime.h
Serene Runtime is free software, licensed under the
GNU LGPL v3
License.