Serene Runtime 1.0.0-dev
C runtime for the Serene programming language
Loading...
Searching...
No Matches
backend.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/** @file
20 Internal reactor backend interface.
21
22 A backend is a set of functions that realises the completion based reactor
23 contract: epoll, or io_uring backends on Linux, kqueue or IOCP and so on. Each
24 backend lives in its own platform specific file under `rt/reactor/backend/` and
25 exposes a single vtable instance. The reactor core selects one at activation.
26*/
27
28#pragma once
29
30#include <stdbool.h>
31#include <stdint.h>
32
33#include "serene/rt/errors.h"
34#include "serene/rt/reactor.h"
35
36/**
37 * No declared capabilities.
38 */
39#define SRN_REACTOR_BACKEND_FEAT_NONE 0
40
41/**
42 * The backend cannot wait on regular file readiness, so the core serves
43 * regular file READ and WRITE off the backend, a synchronous syscall on the
44 * calling worker (a dedicated blocking thread pool is the planned
45 * replacement). Readiness backends
46 * (likes of epoll, kqueue) set this; completion backends (likes of io_uring,
47 * IOCP) submit file IO natively and leave it clear.
48 */
49#define SRN_REACTOR_BACKEND_FEAT_FILE_OFFLOAD 1U
50
51/**
52 * One async system behind the reactor contract. The reactor core drives these
53 * on the reactor thread.
54 */
55typedef struct srn_reactor_backend_t {
56 /// A short name for diagnostics, for example "epoll".
57 const char *name;
58
59 /// Bitmap of SRN_REACTOR_BACKEND_FEAT_* flags this backend requires from the
60 /// reactor.
61 uint32_t features;
62
63 /// Initialize the backend in the given `reactor`.
64 srn_error_t *(*init)(srn_reactor_t *reactor);
65
66 /// Clean up after the backend.
67 void (*shutdown)(srn_reactor_t *reactor);
68
69 /// Submit a new request to the backend. Failures are reported to the waiting
70 /// fiber by posting a completion, not returned, so there is nothing to check.
71 void (*submit)(srn_reactor_t *reactor, size_t channel, const srn_reactor_io_request_t *req);
72
73 /// Wait for readiness and complete any ready operations. Errors here are
74 /// either benign (EINTR) or setup bugs, so nothing is returned.
75 void (*wait)(srn_reactor_t *reactor, int timeout_ms);
76
77 void (*wake)(srn_reactor_t *reactor);
78
80
const srn_reactor_backend_t srn_reactor_backend_epoll
Error handling for the runtime.
Reactor overview.
A runtime error, a tag classifying the failure and a human-readable message.
Definition errors.h:125
One async system behind the reactor contract.
Definition backend.h:55
void(* shutdown)(srn_reactor_t *reactor)
Clean up after the backend.
Definition backend.h:67
void(* wake)(srn_reactor_t *reactor)
Definition backend.h:77
void(* submit)(srn_reactor_t *reactor, size_t channel, const srn_reactor_io_request_t *req)
Submit a new request to the backend.
Definition backend.h:71
const char * name
A short name for diagnostics, for example "epoll".
Definition backend.h:57
uint32_t features
Bitmap of SRN_REACTOR_BACKEND_FEAT_* flags this backend requires from the reactor.
Definition backend.h:61
void(* wait)(srn_reactor_t *reactor, int timeout_ms)
Wait for readiness and complete any ready operations.
Definition backend.h:75
A submission, one request a fiber places on its channel.
Definition reactor.h:113