LCOV - code coverage report
Current view: top level - /home/ubuntu/zephyrproject/zephyr/kernel/include - kspinlock.h (source / functions) Coverage Total Hit
Test: lcov.info Lines: 100.0 % 5 5
Test Date: 2026-11-06 14:43:19 Functions: 100.0 % 2 2
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: - 0 0

             Branch data     Line data    Source code
       1                 :             : /*
       2                 :             :  * Copyright The Zephyr Project Contributors
       3                 :             :  * SPDX-License-Identifier: Apache-2.0
       4                 :             :  */
       5                 :             : 
       6                 :             : #ifndef ZEPHYR_KERNEL_INCLUDE_KSPINLOCK_H_
       7                 :             : #define ZEPHYR_KERNEL_INCLUDE_KSPINLOCK_H_
       8                 :             : 
       9                 :             : #include <zephyr/spinlock.h>
      10                 :             : #include <stdbool.h>
      11                 :             : 
      12                 :             : extern struct k_spinlock _sched_spinlock;
      13                 :             : 
      14                 :             : /**
      15                 :             :  * The intent of LOCK_SCHED_SPINLOCK is to lock the scheduler's spinlock for
      16                 :             :  * the scope that follows (e.g. LOCK_SCHED_SPINLOCK { ... }). However, on
      17                 :             :  * single core systems, the scheduler's spinlock is not needed when the locked
      18                 :             :  * region would otherwise be encapsulated by another spinlock (as that spinlock
      19                 :             :  * would degenerate into an IRQ lock). For that degenerate case, this macro
      20                 :             :  * will expand to nothing.
      21                 :             :  */
      22                 :             : #if (CONFIG_MP_MAX_NUM_CPUS == 1)
      23                 :             : #define LOCK_SCHED_SPINLOCK
      24                 :             : #else
      25                 :             : #define LOCK_SCHED_SPINLOCK   K_SPINLOCK(&_sched_spinlock)
      26                 :             : #endif
      27                 :             : 
      28                 :             : /**
      29                 :             :  * @brief Always lock the scheduler's spinlock for the scope that follows
      30                 :             :  *
      31                 :             :  * Unlike LOCK_SCHED_SPINLOCK, this macro will always lock the scheduler's
      32                 :             :  * spinlock--even on single core systems.
      33                 :             :  */
      34                 :             : #define Z_SCHED_SPINLOCK K_SPINLOCK(&_sched_spinlock)
      35                 :             : 
      36                 :             : 
      37                 :             : /**
      38                 :             :  * @brief Check if a spinlock is the scheduler's spinlock
      39                 :             :  *
      40                 :             :  * @retval true if is, false otherwise
      41                 :             :  */
      42                 :             : static ALWAYS_INLINE bool z_is_sched_spinlock(struct k_spinlock *lock)
      43                 :             : {
      44                 :             :         return (lock == &_sched_spinlock);
      45                 :             : }
      46                 :             : 
      47                 :             : /**
      48                 :             :  * @brief Transfer ownership of the scheduler's spinlock
      49                 :             :  */
      50                 :             : static ALWAYS_INLINE void z_sched_spinlock_transfer_owner(struct k_thread *thread)
      51                 :             : {
      52                 :             : #ifdef CONFIG_SPIN_VALIDATE
      53                 :             :         z_spin_lock_transfer_owner(&_sched_spinlock, thread);
      54                 :             : #else
      55                 :             :         ARG_UNUSED(thread);
      56                 :             : #endif
      57                 :             : }
      58                 :             : 
      59                 :             : 
      60                 :             : /**
      61                 :             :  * @brief Release the scheduler's spinlock without restoring interrupts
      62                 :             :  */
      63                 :             : static ALWAYS_INLINE void z_sched_spinlock_release(void)
      64                 :             : {
      65                 :             :         k_spin_release(&_sched_spinlock);
      66                 :             : }
      67                 :             : 
      68                 :             : /**
      69                 :             :  * @brief Lock the scheduler's spinlock
      70                 :             :  */
      71                 :         221 : static ALWAYS_INLINE k_spinlock_key_t z_sched_spinlock_lock(void)
      72                 :             : {
      73                 :         221 :         return k_spin_lock(&_sched_spinlock);
      74                 :             : }
      75                 :             : 
      76                 :             : /**
      77                 :             :  * @brief Unlock the scheduler's spinlock
      78                 :             :  */
      79                 :         102 : static ALWAYS_INLINE void z_sched_spinlock_unlock(k_spinlock_key_t key)
      80                 :             : {
      81                 :         102 :         k_spin_unlock(&_sched_spinlock, key);
      82                 :         102 : }
      83                 :             : 
      84                 :             : #endif /* ZEPHYR_KERNEL_INCLUDE_KSPINLOCK_H_ */
        

Generated by: LCOV version 2.0-1