Commit graph

8 commits

Author SHA1 Message Date
Andrei Alexeyev
10ecc9ff42
coroutine/cotask: add cotask_get_name() API 2023-03-30 04:31:22 +02:00
Andrei Alexeyev
a13e6ae7a3
coroutine/cotask: make cotask_active safe to call outside of task context
Returns NULL in main context. Still not entirely safe to call on
non-main thread.

The slightly faster "unsafe" version is available as cotask_active_unsafe.
The new cotask_active is currently not used by anything; it's intended
for a logging system update later.
2023-03-30 04:31:22 +02:00
Andrei Alexeyev
aca615f2a6
coroutine/taskdsl: remove NO_ARGS 2023-02-24 18:13:09 +01:00
Andrei Alexeyev
7d57eb0937
coroutine: fix bug in rare WAIT_EVENT use edge case
Using WAIT_EVENT_OR_DIE in an infinite loop on a task-hosted event would
result in a false UNREACHABLE in cotask_wait_event_or_die() after a
cosched_finish() call.

Using just WAIT_EVENT instead would result in a deadlock, though it
should be noted that using WAIT_EVENT without checking for cancellation
is erroneous in itself.
2023-02-15 22:43:39 +01:00
Andrei Alexeyev
b6978178b1
memory: use custom memory allocation wrappers
Introduces wrappers around memory allocation functions in `memory.h`
that should be used instead of the standard C ones.

These never return NULL and, with the exception of `mem_realloc()`,
zero-initialize the allocated memory like `calloc()` does.

All allocations made with the memory.h API must be deallocated with
`mem_free()`. Although standard `free()` will work on some platforms,
it's not portable (currently it won't work on Windows). Likewise,
`mem_free()` must not be used to free foreign allocations.

The standard C allocation functions are now diagnosed as deprecated.
They are, however, available with the `libc_` prefix in case interfacing
with foreign APIs is required. So far they are only used to implement
`memory.h`.

Perhaps the most important change is the introduction of the `ALLOC()`,
`ALLOC_ARRAY()`, and `ALLOC_FLEX()` macros. They take a type as a
parameter, and allocate enough memory with the correct alignment for
that type. That includes overaligned types as well. In most
circumstances you should prefer to use these macros. See the `memory.h`
header for some usage examples.
2023-01-18 13:23:22 +01:00
Andrei Alexeyev
a025ea5251
compat: bless C23-style auto for type inference
C23 auto standardizes GCC's __auto_type semantics, so we can start using
it already.
2023-01-08 23:48:14 +01:00
Andrei Alexeyev
072a9823f9
coroutine: fix missing license header 2023-01-05 04:25:21 +01:00
Andrei Alexeyev
da67472719
coroutine: break down into smaller sub-modules 2022-12-28 23:47:48 +01:00