Changeset 4777e02 in mainline


Ignore:
Timestamp:
2023-02-12T22:25:23Z (14 months ago)
Author:
Jiří Zárevúcky <zarevucky.jiri@…>
Branches:
master, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
c7326f21
Parents:
111b9b9
git-author:
Jiří Zárevúcky <zarevucky.jiri@…> (2023-02-12 22:11:54)
git-committer:
Jiří Zárevúcky <zarevucky.jiri@…> (2023-02-12 22:25:23)
Message:

Make spinlock functions inlineable in non-SMP case

By popular demand.

Location:
kernel/generic
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • kernel/generic/include/synch/spinlock.h

    r111b9b9 r4777e02  
    117117        SPINLOCK_STATIC_INITIALIZE_NAME(lock_name, #lock_name)
    118118
     119#ifdef CONFIG_SMP
     120
    119121extern void spinlock_initialize(spinlock_t *, const char *);
    120122extern bool spinlock_trylock(spinlock_t *);
     
    122124extern void spinlock_unlock(spinlock_t *);
    123125extern bool spinlock_locked(spinlock_t *);
     126
     127#else
     128
     129#include <preemption.h>
     130
     131static inline void spinlock_initialize(spinlock_t *l, const char *name)
     132{
     133}
     134
     135static inline bool spinlock_trylock(spinlock_t *l)
     136{
     137        return true;
     138}
     139
     140static inline void spinlock_lock(spinlock_t *l)
     141{
     142        preemption_disable();
     143}
     144
     145static inline void spinlock_unlock(spinlock_t *l)
     146{
     147        preemption_enable();
     148}
     149
     150static inline bool spinlock_locked(spinlock_t *l)
     151{
     152        return true;
     153}
     154
     155#endif
    124156
    125157typedef struct {
  • kernel/generic/src/synch/spinlock.c

    r111b9b9 r4777e02  
    3737 */
    3838
     39#ifdef CONFIG_SMP
     40
    3941#include <arch/asm.h>
    4042#include <synch/spinlock.h>
     
    5658void spinlock_initialize(spinlock_t *lock, const char *name)
    5759{
    58 #ifdef CONFIG_SMP
    5960        atomic_flag_clear_explicit(&lock->flag, memory_order_relaxed);
    6061#ifdef CONFIG_DEBUG_SPINLOCK
    6162        lock->name = name;
    62 #endif
    6363#endif
    6464}
     
    7373        preemption_disable();
    7474
    75 #ifdef CONFIG_SMP
    7675        bool deadlock_reported = false;
    7776        size_t i = 0;
     
    120119        if (deadlock_reported)
    121120                printf("cpu%u: not deadlocked\n", CPU->id);
    122 
    123 #endif
    124121}
    125122
     
    130127void spinlock_unlock(spinlock_t *lock)
    131128{
    132 #ifdef CONFIG_SMP
    133129#ifdef CONFIG_DEBUG_SPINLOCK
    134130        ASSERT_SPINLOCK(spinlock_locked(lock), lock);
     
    136132
    137133        atomic_flag_clear_explicit(&lock->flag, memory_order_release);
    138 #endif
    139 
    140134        preemption_enable();
    141135}
     
    154148        preemption_disable();
    155149
    156 #ifdef CONFIG_SMP
    157150        bool ret = !atomic_flag_test_and_set_explicit(&lock->flag, memory_order_acquire);
    158151
     
    161154
    162155        return ret;
    163 #else
    164         return true;
    165 #endif
    166156}
    167157
     
    173163bool spinlock_locked(spinlock_t *lock)
    174164{
    175 #ifdef CONFIG_SMP
    176165        // NOTE: Atomic flag doesn't support simple atomic read (by design),
    177166        //       so instead we test_and_set and then clear if necessary.
     
    183172                atomic_flag_clear_explicit(&lock->flag, memory_order_relaxed);
    184173        return ret;
    185 #else
    186         return true;
    187 #endif
    188174}
     175
     176#endif  /* CONFIG_SMP */
    189177
    190178/** @}
Note: See TracChangeset for help on using the changeset viewer.