Select Git revision
Forked from
Lehrstuhl für Informatik 4 (Systemsoftware) / manycore / mazstab
Source project has a limited visibility.
-
Florian Schmaus authoredFlorian Schmaus authored
fibril.hpp 4.02 KiB
// SPDX-License-Identifier: LGPL-3.0-or-later
// Copyright © 2021 Florian Schmaus
#pragma once
// This is the combination of fibril.h and fibrile.h where fibril_fork
// uses lambda functions instead of inner C functions (which are a GCC
// extension and do not work with C++). Hence part of this is MIT
// licensed.
#ifdef __cplusplus
extern "C" {
#endif
#include "fibril/fibrili.h"
#define FIBRIL_SUCCESS 0
#define FIBRIL_FAILURE -1
/**
* These are special arguments to fibril_rt_init().
* FIBRIL_NPROCS tells the runtime to fetch the number of processors
* from the environment variable FIBRIL_NPROCS (getenv(FIBRIL_NPROCS)).
* FIBRIL_NPROCS_ONLN tells the runtime to use all available processors
* in the system (sysconf(_SC_NPROCESSORS_ONLN)).
*/
#define FIBRIL_NPROCS 0
#define FIBRIL_NPROCS_ONLN -1
/** fibril. */
#define fibril __attribute__((optimize("no-omit-frame-pointer")))
/** fibril_t. */
typedef struct _fibril_t fibril_t;
/** fibril_init. */
__attribute__((always_inline)) extern inline void fibril_init(fibril_t* frptr) {
register void* rbp asm("rbp");
register void* rsp asm("rsp");
frptr->lock = 0;
frptr->unmapped = 0;
frptr->count = -1;
// NOLINTNEXTLINE(clang-analyzer-core.uninitialized.Assign)
frptr->stack.btm = rbp;
frptr->stack.top = rsp;
}
/** fibril_join. */
__attribute__((always_inline)) extern inline void fibril_join(fibril_t* frptr) {
if (frptr->count > -1) {
fibrili_membar(fibrili_join(frptr));
}
}
#include "fibril/fork.h"
/** _fibril_fork_nrt. */
#define fibril_fork_nrt(fp, fn, ag) \
do { \
auto _fibril_##fn##_fork = [](_fibril_defs ag fibril_t* f) \
__attribute__((noinline, hot, optimize(3))) { \
fibrili_push(f); \
fn(_fibril_args ag); \
if (!fibrili_pop()) fibrili_resume(f); \
}; \
fibrili_membar(_fibril_##fn##_fork(_fibril_expand ag fp)); \
} while (0)
/** _fibril_fork_wrt. */
#define fibril_fork_wrt(fp, rtp, fn, ag) \