Serene Runtime 1.0.0-dev
C runtime for the Serene programming language
Loading...
Searching...
No Matches
runtime.c
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#include "serene/runtime.h"
20
27
29
30 srn_main_args_t *main_args = args;
31 main_args->out = main_args->main_f(ctx, main_args->argc, main_args->argv);
32 return nullptr;
33}
34
35int srn_run_fiber_main(srn_main_t m, int argc, char *argv[]) {
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
void * srn_fiber_result_t
What a fiber's entry produces, type-erased.
Definition fiber.h:161
int srn_run_fiber_main(srn_main_t m, int argc, char *argv[])
Definition runtime.c:35
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
int(* srn_main_t)(srn_context_t *ctx, int argc, char *argv[])
Definition runtime.h:68
#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
srn_main_t main_f
Definition runtime.c:22
char ** argv
Definition runtime.c:25
#define SRN_TRACEPOINT(name,...)
Placement matters.
Definition trace.h:79