1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2025-12-24 22:13:52 +01:00

1101 Commits

Author SHA1 Message Date
crasbe
ba6c53e93b
Merge pull request #21903 from maribu/core/spdx
core: use SPDX copyright tags
2025-11-23 21:24:10 +00:00
Marian Buschsieweke
bd43254702
core: use SPDX copyright tags
Co-authored-by: crasbe <crasbe@gmail.com>
2025-11-23 21:07:35 +01:00
Marian Buschsieweke
2c815f837d
Merge pull request #21895 from maribu/core/thread_flags_group/fix
core/thread_flags_group: use portable implementation
2025-11-21 16:33:38 +00:00
Marian Buschsieweke
f396456423
core/thread_flags_group: use portable implementation
The previous implementation relied on `thread_flag_set()` to defer the
context switch when called with IRQs disabled until `irq_restore()` is
called. This however can only be the case when `thread_yield_higher`
triggers an IRQ and performs the context switch within the ISR. This
allowed the previous implementation to continue calling
`thread_flag_set()` for the remaining group members.

This however is an implementation detail that is not part of the API
contract. Platforms that do not have a service request IRQ may have to
use other means for context switching that do not get deferred until
an `irq_restore()` is called. In that case, the first call to
`thread_flags_set()` even with IRQs disabled may directly trigger a
context switch to the unblocked thread, even if other group members
would also be unblocked and have a higher priority.

This changes the implementation to manually set the flags and update
the thread status without yielding and keep track whether any thread
has been awoken. Only once the states of all threads have been updated,
the adapted implementation will now call `thread_yield()` (unless no
thread was awoken).
2025-11-21 15:21:25 +01:00
Marian Buschsieweke
50a1d28b47
core/thread_flags: change internal API
All uses of thread_flags_wake() also had to set the flags anyway, so
we can just combine those operations into a new
thread_flags_set_internal() and update the users to use that instead.
2025-11-21 15:21:22 +01:00
benpicco
250758c67c
Merge pull request #21883 from maribu/core/lib/atomics
core/lib/atomic_c11: Add __atomic_test_and_set()
2025-11-19 12:31:35 +00:00
Marian Buschsieweke
a32e108f2e
core/lib/atomic_c11: Fix compatibility with GCC
GCC requires symbols to first be declared before they can be renamed.
So we move the `#pragma redefine_extname` just to the bottom of the
compilation unit.

Co-authored-by: crasbe <crasbe@gmail.com>
Co-authored-by: Mikolai Gütschow <mikolai.guetschow@tu-dresden.de>
2025-11-18 10:21:23 +01:00
Marian Buschsieweke
0998112524
core/lib/compiler_hints: Make NONSTRING CLANG compatible
Starting from clang 21 (see [release notes][1]) clang also supports
`-Wunterminated-string-initialization` and the corresponding
`__attribute__((nonstring))`. Hence, also provide `NONSTRING` as the
corresponding `__attribute__((nonstring))` for clang starting with
clang version 21.

[1]: https://releases.llvm.org/21.1.0/tools/clang/docs/ReleaseNotes.html
2025-11-16 21:06:21 +01:00
Marian Buschsieweke
4588b67fb8
core/lib/atomic_c11: Add __atomic_test_and_set()
This adds a previously missing library implementation for
`__atomic_test_and_set()`.
2025-11-16 20:52:18 +01:00
Leandro Lanzieri
79a54c5741 core/lib/clist: fix example of clist_foreach usage
Also fix some doxygen rendering issues.
2025-11-05 16:32:37 +01:00
Marian Buschsieweke
64c76246c5
core/assert: always declare _assert_panic() / _assert_failure()
That way users can rely on elimation of dead code from the optimizer
instead of having to use preprocessor conditionals when feature-gating
assert implementations behind `!NDEBUG`.

Co-authored-by: benpicco <benpicco@googlemail.com>
Co-authored-by: crasbe <crasbe@gmail.com>
Co-authored-by: mguetschow <mikolai.guetschow@tu-dresden.de>
2025-08-21 12:08:09 +02:00
Mihai Renea
23d02583e4 core/log: add optional log unit prefix 2025-07-16 14:49:35 +02:00
crasbe
d732bd053d
Merge pull request #21254 from derMihai/mir/tflags_group
core/thread_flags: add thread flags group
2025-07-10 11:48:29 +00:00
Mihai Renea
eb3c8c3f3f core/thread_flags: add thread flags group 2025-05-28 21:02:27 +02:00
chrysn
79071b10f2 core/doc: Thread names are expected to be long-lived 2025-05-19 15:55:05 +02:00
Marian Buschsieweke
0b01fa0025
core/compiler_hints: Add NONSTRING attribute
This adds the `NONSTRING` attribute that is defined as either
`__attribute__((nonstring))` or as empty, depending on whether the
toolchain understands the `nonstring` attribute.

This allows declaring char arrays as not being a zero-terminated
c-string without cluttering the code with preprocessor conditinational
to ensure backward compatibility with compilers that do not support
`-Wunterminated-string-initialization` yet.
2025-04-27 22:49:22 +02:00
Marian Buschsieweke
914429c5f5
core/lib/include/compiler_hints.h: fix style
This adds indent to make reading preprocessor conditionals easier, as
is recommended by our coding convention.
2025-04-27 22:49:22 +02:00
Marian Buschsieweke
0069a6bf9a
build system: enable support for static analysis
Modules can now add the following snipped to their `Makefile`:

    MODULE_SUPPORTS_STATIC_ANALYSIS := 1

When the application is then build with `make STATIC_ANALYSIS=1`, all
modules that opted in to static analysis get build with static analysis.
2025-04-18 09:36:31 +02:00
Marian Buschsieweke
16c24a43e9
Merge pull request #21414 from maribu/core/thread/thread_msg_has_queue
core/thread: fix thread_has_msg_queue()
2025-04-17 20:41:30 +00:00
Marian Buschsieweke
87ff0d550d
core/thread_get_unchecked(): fix doc
This fixes the API doc for thread_get_unchecked()
2025-04-17 18:49:49 +02:00
Marian Buschsieweke
2a65b9cfa5
core/thread: fix thread_has_msg_queue()
This fixes compilation with `-fanalyzer`. We use `assume()` to signal
GCC that `thread` must not be null in `NDEBUG` mode, and `assert()` it
in with enabled assertions.

This also drops the `volatile` qualifier from the function argument and
changes the return value to `bool`.
2025-04-17 18:47:39 +02:00
Marian Buschsieweke
d36465d532
core/msg: handle error in msg_queue_capacity()
Rather than using an `assert()` on `thread_get()`, check for the thread
to exist and return a capacity of `0` if it does not.

This fixes compilation with `-fanalyzer` with `NDEBUG` defined, is more
consistent with other core APIs, and makes the API usable for threads
with a dynamic life cycle.

Co-authored-by: crasbe <crasbe@gmail.com>
2025-04-17 07:55:13 +02:00
Marian Buschsieweke
55f9d1c930
Merge pull request #21405 from JerelJr/fix-core-headers
core: replace header guards with #pragma once
2025-04-16 05:30:21 +00:00
JerelJr
04dafd5618 core: replace header guards with #pragma once
core/lib/include/ringbuffer.h: removed trailing newline

core/lib/include/irq.h: restored header guard for irq.h to resolve build errors

core/lib/include/irq.h: added trailing newline to irq.h
2025-04-15 14:55:38 -04:00
Marian Buschsieweke
a605d05eca
Merge pull request #21400 from maribu/core/msg-avail
core/msg: fix `msg_avail_thread()` and `msg_avail()`
2025-04-15 13:20:26 +00:00
Marian Buschsieweke
caa5561667
core/msg: fix msg_avail_thread() and msg_avail()
This now ensures race-free access to the CIB tracking the number
of messages queued in the ringbuffer for a given thread.

In addition, `msg_avail_thread()` now checks if the provided pid refers
to a thread that is currently existing.

Co-authored-by: Mikolai Gütschow <mikolai.guetschow@tu-dresden.de>
2025-04-15 15:07:11 +02:00
Marian Buschsieweke
dcd3ee74ae
core/cib: Add a prominent warning about thread safety
Users of CIB may easily be mislead to believing that it is generally
thread safe, or at least thread safe as long as there is a single
consumer and producer. Neither is the case, which now is clearly
communicated in the API doc.

Co-authored-by: mguetschow <mikolai.guetschow@tu-dresden.de>
2025-04-14 14:29:56 +02:00
Marian Buschsieweke
1ff982a664
tree wide: various doc fixes
This fixes a batch of incorrect Doxygen comments that building with
LLVM/clang and `-Wdocumentation` uncovered.
2025-04-04 11:44:53 +02:00
Marian Buschsieweke
ca781c2f12
Merge pull request #21242 from mguetschow/native-alias
boards: introduce board alias and make native default to host target
2025-04-02 09:14:12 +00:00
benpicco
85dc9be1c9
Merge pull request #20872 from benpicco/stdio_null-frontend
core: add stdio.h to replace stdout functions with stdio_null
2025-04-01 15:30:08 +00:00
Benjamin Valentin
35005c3e85 core: add stdio.h to replace stdout functions with stdio_null 2025-04-01 14:29:28 +02:00
Mikolai Gütschow
69c15e1754
boards: make BOARD=native an alias for BOARD=native32 2025-04-01 12:39:06 +02:00
Karl Fessel
1446aeab24 core/mutex: separate documentation 2025-04-01 11:30:15 +02:00
Marian Buschsieweke
785faa77f7
Merge pull request #21253 from DeJusten/2025-02.thread
core/thread: error in thread.c corrected
2025-03-14 12:26:57 +00:00
DeJusten
2eeb0f7f96
core/thread: document thread_add_to_list()
Adding the task to the linked list is graphically commented
2025-03-14 13:11:09 +01:00
DeJusten
a4ec8e1ebb
core/thread: fix thread_state_to_string()
In thread_state_to_string() it is not checked whether state is within
the valid range, so that in the event of an error an invalid memory
address is returned, which in turn leads to further invalid memory
accesses when the string is output. thread_state_to_string() is used
in particular by ps(). In the case of a corrupt thread context, which
often occurred in my case due to the stack size being too small,
thread_state_to_string() is called with an invalid status.
2025-03-14 13:11:09 +01:00
DeJusten
48f8e618ca
core/thread: fix incorrect thread status after wake up
In thread_wakeup() the status of the function to be woken up is
incorrectly set to TASK_RUNNING. Instead the task should be set
to STATUS_PENDING here, as only sched_run() is allowed to set a
task to TASK_RUNNING.
2025-03-14 11:04:16 +01:00
DeJusten
3cbde6a2ee
core/thread: thread_create(): improve error handling
Return `-EINVAL` when stack is too small in addition to warn when
`ENABLE_DEBUG` is set.
2025-03-14 11:03:58 +01:00
Marian Buschsieweke
ef2d6f8724
core/debug: extend doc about DEBUG() / LOG_DEBUG()
This adds a few lines to explain the difference between the two and
hints when to use which.

Co-authored-by: crasbe <crasbe@gmail.com>
2025-03-06 21:08:46 +01:00
Fabian Hüßler
f7045405c0 core/cib: add const to cib_peek() 2025-01-12 21:09:36 +01:00
Mikolai Gütschow
850a827c24
core/msg: re-enable IRQs before printing for highlevel_stdio
copy message queue information to stack before
2024-11-28 12:49:11 +01:00
benpicco
77c4a24bcf
Merge pull request #20938 from derMihai/mir/fix_runqueue_pop
core/sched.c: fix _runqueue_pop() removing wrong thread
2024-11-14 12:05:45 +00:00
Mihai Renea
ba71ba72a3 core/sched.c: fix _runqueue_pop() removing wrong thread 2024-11-14 11:05:40 +01:00
benpicco
d65dec6ab5
Merge pull request #20960 from maribu/build_system/xfa/fix-alignment
build_system/xfa: change API to fix alignment
2024-11-07 16:16:28 +00:00
Marian Buschsieweke
2b6f65a08a
build_system/xfa: change API to fix alignment
This changes the API of xfa from

    XFA(array_name, prio) type element_name = INITIALIZER;

to

    XFA(type, array_name, prio) element_name = INITIALIZER;

this allows forcing natural alignment of the type, fixing failing tests
on `native64`.
2024-11-07 16:30:01 +01:00
Benjamin Valentin
46ecf82e24 core/mutex: add mutex_init_locked() 2024-11-06 12:53:17 +01:00
mguetschow
a54ba26285
Merge pull request #20893 from benpicco/THREAD_CREATE_STACKTEST-cleanup
treewide: clean up remnants of THREAD_CREATE_STACKTEST
2024-10-08 09:55:52 +00:00
Benjamin Valentin
97128eef48 treewide: clean up remnants of THREAD_CREATE_STACKTEST 2024-10-07 17:31:31 +02:00
Marian Buschsieweke
1d99f4f758
core/mutex: use thread_yield_higher() in mutex_unlock()
Using `sched_switch()` in `mutex_unlock()` can result in crashes when
`mutex_unlock()` is called from IRQ context. This however is a common
pattern in RIOT to wake up a thread from IRQ. The reason for the crash
is that `sched_switch()` assumes `thread_get_active()` to always return
a non-`NULL` value. But when thread-less idle is used, no thread may be
active after the last runnable thread exited. Using
`thread_yield_higher()` instead solves the issue, as
`thread_yield_higher()` is safe to call from IRQ context without an
active thread.

This fixes https://github.com/RIOT-OS/RIOT/issues/20812
2024-10-05 22:02:28 +02:00
benpicco
41204c8b81
Merge pull request #20450 from benpicco/THREAD_CREATE_STACKTEST-delete
core/thread: always use THREAD_CREATE_STACKTEST when DEVELHELP is enabled
2024-07-29 11:52:06 +00:00