1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00
Commit Graph

80 Commits

Author SHA1 Message Date
Marian Buschsieweke
3e86e39646
core: add core_mutex_debug to aid debugging deadlocks
Adding `USEMODULE += core_mutex_debug` to your `Makefile` results in
on log messages such as

    [mutex] waiting for thread 1 (pc = 0x800024d)

being added whenever `mutex_lock()` blocks. This makes tracing down
deadlocks easier.
2023-04-25 15:10:34 +02:00
Marian Buschsieweke
2d2bb4b308
core/mutex: clean up
This restores a pre-existing design decision to implement both
blocking and non-blocking mutex locking with the same code. Those
implementations have been split prior to the introduction of
the `core_mutex_priority_inheritance` module when `mutex_trylock()`
indeed was trivial. This decision didn't age well, so undo it.
2022-09-29 13:12:33 +02:00
Marian Buschsieweke
c07181c1c4
core/mutex: fix priority inheritance on AVR
This fixes https://github.com/RIOT-OS/RIOT/issues/18545 as the code
previously relied on `sched_change_priority()` not directly scheduling
a new thread while IRQs are disabled, but rather later when IRQs are
restored. This is true for Cortex-M MCUs (where the PendSV IRQ is used
to trigger the scheduler), but not e.g. for AVR.
2022-09-12 21:40:54 +02:00
Marian Buschsieweke
8be03dc055
core: implement core_mutex_mitigate_priority_inversion 2022-08-05 13:08:52 +02:00
Benjamin Valentin
8100203e95 core/thread, mutex: provide dummy implementation for riotboot
This is intended for the bootloader module where we don't enter thread
mode, so mutex must never attempt to switch context.

Instead use a simple busy wait that is enough to make the possible mutex
users (e.g. interrupt based SPI) in bootloader mode work.
2022-05-02 13:18:39 +02:00
Jan Romann
3c86b74dc6
core: uncrustify 2021-11-18 15:44:00 +01:00
chrysn
6145949f88 core/mutex: Add assert guard against usage without threads 2021-02-15 06:01:01 +01:00
Martine Lenders
9b40bb63c2
core: apply uncrustify patches 2021-02-02 22:21:14 +01:00
Marian Buschsieweke
8bbe56c302
core/mutex: compatibility with non-C languages
Due to limited compatibility with C, we cannot use the inline mutex_trylock
implementation for C++. Instead, we provide a mutex_trylock_ffi() intended for
foreign function interfaces. This should also benefit rust users.
2020-12-09 11:53:48 +01:00
Marian Buschsieweke
e348407888
core/mutex: Add mutex_cancel() & mutex_lock_cancelable()
Add a version of `mutex_lock()` that can be canceled with the obvious name
`mutex_lock_cancelable()`. This function returns `0` on success, and
`-ECANCELED` when the calling thread was unblocked via a call to
`mutex_cancel()` (and hence without obtaining the mutex).

This is intended to simplify the implementation of `xtimer_mutex_lock_timeout()`
and to implement `ztimer_mutex_lock_timeout()`.
2020-12-08 14:50:49 +01:00
Marian Buschsieweke
a06a7978d3
core/mutex: clean up mutex_lock()
- Split out handling of the blocking code path of mutex_lock() into a static
  `_block()` function. This improves readability a bit and will ease review of
  a follow up PR.
- Return `void` instead of `int`.
2020-11-18 11:58:49 +01:00
Marian Buschsieweke
90103f2a6a
core/mutex: consistent debug output 2020-11-18 09:13:00 +01:00
Marian Buschsieweke
d760e931ae
core/mutex: Cleanup
- Use static inline function for `mutex_try_lock()`
    - The implementation is trivial enough with the inline-able IRQ API to just
      always be inline-ed
- Rename `_mutex_lock()` to `mutex_lock()` and drop the blocking parameter
    - This was possible to the stand-alone `mutex_try_lock()` implementation
    - This yields a measurable performance bump
2020-11-06 23:27:13 +01:00
Bas Stottelaar
e675b6379e core/*: realign ENABLE_DEBUG 2020-10-23 00:45:56 +02:00
Marian Buschsieweke
57264c5059
core: Access internal vars via helper funcs
Replace accesses to `sched_active_thread`, `sched_active_pid`, and
`sched_threads` with `thread_get_active()`, `thread_get_active_pid()`, and
`thread_get_unchecked()` where sensible.
2020-08-06 16:47:33 +02:00
8efe5960aa core: uncrustify 2020-03-30 17:02:08 +02:00
JulianHolzwarth
dd6e51b1eb core/mutex.c _mutex_lock uses an int pointer
_mutex_lock uses a volatile int pointer for the parameter blocking instead of an int.
2020-03-26 17:26:07 +01:00
Martine Lenders
28572d7d21 core: mutex: fix DEBUG pointer output 2018-11-09 08:41:50 +01:00
68f13467d3 core: remove redundant includes 2017-08-02 14:27:55 +02:00
Joakim Nohlgård
985afd8d80 core/mutex.c: remove unused #include "atomic.h" 2017-02-08 16:23:47 +01:00
Victor Arino
ea12433a8d core/mutex: support locked initialization 2016-12-14 10:24:45 +01:00
Martine Lenders
1750e1bad8 core: mutex: piggy-back some style fixes 2016-04-18 17:23:55 +02:00
Martine Lenders
ccb4521599 core: allow DEBUG in mutex.c to run without DEVELHELP 2016-04-17 13:38:49 +02:00
f9f6adb48d core: clist: make singly linked 2016-03-30 00:27:49 +02:00
350c341ce1 core: mutex: use of intrusive linked list instead of priority queue 2016-03-29 21:50:17 +02:00
DipSwitch
0bb4748a94 core: Fix/refactor function naming in core/incude/irq.h 2016-03-20 16:47:34 +01:00
2b010b5337 core: rename tcb_t -> thread_t, move into thread.h 2016-03-05 18:20:17 +01:00
9082273746 core: header cleanup 2016-02-28 22:46:28 +01:00
Joakim Nohlgård
98c465008b all: Update @gebart family name, email 2015-09-20 13:47:39 +02:00
Oleg Hahm
ef5a7e7d05 core mutex: use ATOMIC_VALUE for debug output 2015-09-16 03:30:05 +02:00
René Kijewski
c0c2d8660f core: missing restoreIRQ in mutex_unlock
`mutex_unlock()` did not restore IRQsbefore yielding for the woken up
thread.
2015-08-21 09:16:54 +02:00
Joakim Gebart
748499b737 core/mutex: Use atomic_int_t for lock variable. 2015-05-26 21:23:48 +02:00
Joakim Gebart
13832d8e62 everything: Remove filename from @file Doxygen command 2015-05-22 07:34:41 +02:00
Ludwig Ortmann
eceb656c49 core,sys: fix storage types for irq API usage
* should not have any effect as long as `unsigned` and `int` are compatible
* also fix two cosmetic `unsigned int` -> `unsigned` for consistency
2014-10-27 16:25:23 +01:00
René Kijewski
677d690e2b core: introduce thread_yield_higher(), yield less
Fixes #1708.

Currently involuntary preemption causes the current thread not only to
yield for a higher prioritized thread, but all other threads of its own
priority class, too.

This PR adds the function `thread_yield_higher()`, which will yield the
current thread in favor of higher prioritized functions, but not for
threads of its own priority class.

Boards now need to implement `thread_yield_higher()` instead of
`thread_yield()`, but `COREIF_NG` boards are not affected in any way.

`thread_yield()` retains its old meaning: yield for every thread that
has the same or a higher priority.

This PR does not touch the occurrences of `thread_yield()` in the periph
drivers, because the author of this PR did not look into the logic of
the various driver implementations.
2014-10-24 00:09:56 +02:00
Ludwig Ortmann
c2b2e4554b core/queue: queue -> priority_queue
Rename queue to priority queue, because that's what it is.
2014-08-05 17:57:45 +02:00
Oleg Hahm
983d056c75 core: harmonizes the data type for the process ID
Instead of using differing integer types use kernel_pid_t for process
identifier. This type is introduced in a new header file to avoid
circular dependencies.
2014-08-01 12:02:54 +02:00
Ludwig Ortmann
3ca4f18479 doc: use lgplv2.1-short license header instead of lgpl-short-riot 2014-07-31 22:57:20 +02:00
René Kijewski
4032a22719 queue: add queue_t root type 2014-07-30 21:10:22 +02:00
René Kijewski
e03e20b7f6 core: simplify mutex initializer 2014-07-29 09:33:23 +02:00
René Kijewski
e5d6142823 core: simplify mutex signatures 2014-07-29 09:32:16 +02:00
René Kijewski
a6fd5bff92 core: imply current_prio in sched_switch()
There is no need to supply the current priority to `sched_switch()`,
when this function can easily tell the value of
`active_thread->priority` itself.
2014-05-24 16:48:35 +02:00
Oleg Hahm
ef5ec344fd core: prefix API functions correctly
Also changed names for bitarithm functions and rename thread_pid to sched_active_pid.
2014-05-18 08:53:20 +02:00
Martin Lenders
71a632520b Fix documentation for mutex.h 2014-05-13 08:33:38 +02:00
Hauke Petersen
608afc4777 Introduced a cleaned-up cpu/core interface
- Included a collection of cpu-dependent headers in core/include/arch
- Extracted all interfaces that need to be implemented for a cpu
- Created a mapping between those interfaces and the old ones
- added flag for disabling arch interface
- added missing state to lpm_arch interface
- added arch interface for reboot
- fixed newline issues that were pointed out
- documentation fixes to cpu-core interface
2014-05-09 16:01:13 +02:00
Oleg Hahm
58aa0da315 added missing ENABLE_DEBUG define in mutex.c 2014-03-19 16:19:08 +01:00
René Kijewski
e6d8c6bb99 Merge pull request #859 from Kijewski/mutex-trylock-error
core:mutex: allow idle thread to use mutexes
2014-03-19 15:18:15 +01:00
René Kijewski
114eedd764 core:mutex: allow idle thread to use mutexes 2014-03-05 16:46:42 +01:00
René Kijewski
3c65b38881 core:mutex: remove refactor remnant 2014-03-05 01:49:31 +01:00
Martin
35106e3391 add test for mutex_unlock_and_sleep() 2014-03-03 18:48:46 +01:00