Commit graph

15 commits

Author SHA1 Message Date
frei tycho 8124d064e9 include: zephyr: coding guidelines: add explicit cast to void
- added explicit cast to void when returned value is expectedly ignored

Signed-off-by: frei tycho <tfrei@baumer.com>
2024-06-07 16:46:32 +03:00
frei tycho 4c2938a295 kernel: added missing parenthesis
- added missing parenthesis around macro argument expansion

Signed-off-by: frei tycho <tfrei@baumer.com>
2024-06-07 12:59:46 +02:00
Alexander Razinkov 4664813a12 kernel: spinlock: Ticket spinlocks
Basic spinlock implementation is based on single
atomic variable and doesn't guarantee locking fairness
across multiple CPUs. It's even possible that single CPU
will win the contention every time which will result
in a live-lock.

Ticket spinlocks provide a FIFO order of lock aquisition
which resolves such unfairness issue at the cost of slightly
increased memory footprint.

Signed-off-by: Alexander Razinkov <alexander.razinkov@syntacore.com>
2023-11-04 07:38:39 -04:00
Alexander Razinkov 9ae9df8b6f kernel: spinlock: k_spin_is_locked introduction
Currently spinlock internals are directly accessed from the tests.
This way the test becomes bound to the particular spinlock implementation.
To remove this unnecessary dependency the distinct API to check if spinlock
is locked is introduced.

k_spin_is_locked should be used for the spinlock testing only,
so the scope of this API is intentionally restricted.

Signed-off-by: Alexander Razinkov <alexander.razinkov@syntacore.com>
2023-09-07 14:26:55 +02:00
Prashanth S 76663444c1 include: zephyr: Fix build error in spinlock.h
In function z_spin_onexit, when CONFIG_FORCE_NO_ASSERT=y
and CONFIG_SPIN_VALIDATE=y the function parameter becomes unused.
This generates a build error (unused parameter 'k').

Add __maybe_unused to fix this error.

Signed-off-by: Prashanth S <slpp95prashanth@yahoo.com>
2023-07-14 16:50:44 +00:00
Florian Grandel 5132022a3c kernel: spinlock: add assertion to protect K_SPINLOCK
Adds an assertion for the GCC toolchain to check whether the K_SPINLOCK
block was left without unlocking the spinlock, e.g. by calling break,
return or goto.

Signed-off-by: Florian Grandel <fgrandel@code-for-humans.de>
2023-07-10 09:27:21 +02:00
Florian Grandel 816d09c453 kernel: spinlock: expose LOCKED macro as public API
While the LOCKED pattern is universally useful it can be misused. This
change therefore exposes the LOCKED pattern with extensive usage
documentation to reduce the risk of abuse or unintended deadlock.

Signed-off-by: Florian Grandel <fgrandel@code-for-humans.de>
2023-07-10 09:27:21 +02:00
Florian Grandel 244c33549f kernel: spinlock: remove internal function from docs
Hides a function marked internal from the documentation.

Signed-off-by: Florian Grandel <fgrandel@code-for-humans.de>
2023-07-10 09:27:21 +02:00
Christopher Friedt ac2b9928f6 kernel: spinlock: add k_spin_trylock()
To satisfy the requirements of POSIX spinlocks, we need a common
way to attempt to lock a spinlock that will return an error if
unsuccessful.

Signed-off-by: Christopher Friedt <cfriedt@meta.com>
2023-07-05 21:06:55 -04:00
Nicolas Pitre e2d0d1a801 kernel: allow for arch specific processing within busy loops
Give architectures that need it the ability to perform special checks
while e.g. waiting for a spinlock to become available.

Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
2023-05-25 08:25:11 +00:00
Stephanos Ioannidis 4a64bfe351 treewide: Use CONFIG_CPP instead of CONFIG_CPLUSPLUS
This commit updates all in-tree code to use `CONFIG_CPP` instead of
`CONFIG_CPLUSPLUS`, which is now deprecated.

Signed-off-by: Stephanos Ioannidis <stephanos.ioannidis@nordicsemi.no>
2023-01-13 17:42:55 -05:00
Kumar Gala 4f458ba8de kernel: Convert away from CONFIG_MP_NUM_CPUS
Move runtime code to use arch_num_cpus() instead of CONFIG_MP_NUM_CPUS
and use CONFIG_MP_MAX_NUM_CPUS for ifdef and BUILD_ASSERT macros.

Signed-off-by: Kumar Gala <kumar.gala@intel.com>
2022-10-31 17:09:14 +01:00
Tom Burdick 872e3553f9 kernel: Option to assert on spin lock time
Spin locks held for any lengthy duration prevent interrupts and
in a real time system where interrupts drive tasks this can be
problematic. Add an option to assert if a spin lock is held for
a duration longer than the configurable number of microseconds.

Signed-off-by: Tom Burdick <thomas.burdick@intel.com>
2022-10-18 14:14:12 +02:00
Gerard Marull-Paretas fb9b3bcd93 include: migrate includes to <zephyr/...>
In order to bring consistency in-tree, migrate all includes within
include directory to the new prefix <zephyr/...>. Note that the
conversion has been scripted, refer to zephyrproject-rtos#45388 for more
details.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-05-06 20:03:00 +02:00
Yuval Peress 53ef68d459 include: Prefix includes to use a scope
Move include paths and add new target_include_directories to support
backwards compatibility:
* /include -> /include/zephyr
  example: <irq.h> -> <zephyr/irq.h>

Issue #41543

Signed-off-by: Yuval Peress <peress@google.com>
2022-04-08 19:03:32 +02:00
Renamed from include/spinlock.h (Browse further)