自旋锁 spin_lock 分析

static inline void spin_lock(spinlock_t *lock)
{
raw_spin_lock(&lock->rlock);

}

typedef struct spinlock {
union {
struct raw_spinlock rlock;


#ifdef CONFIG_DEBUG_LOCK_ALLOC
# define LOCK_PADSIZE (offsetof(struct raw_spinlock, dep_map))
struct {
u8 __padding[LOCK_PADSIZE];
struct lockdep_map dep_map;
};
#endif
};
} spinlock_t;

typedef struct raw_spinlock {
arch_spinlock_t raw_lock;
#ifdef CONFIG_GENERIC_LOCKBREAK
unsigned int break_lock;
#endif
#ifdef CONFIG_DEBUG_SPINLOCK
unsigned int magic, owner_cpu;
void *owner;
#endif
#ifdef CONFIG_DEBUG_LOCK_ALLOC
struct lockdep_map dep_map;
#endif
} raw_spinlock_t;



typedef struct {
volatile unsigned int slock;
} arch_spinlock_t;



spin_lock最终调用 

#define __LOCK(lock) \
  do { preempt_disable(); __acquire(lock); (void)(lock); } while (0)

preempt_disable() 禁止内核抢占


__context__  这个没有弄明白。



void __lockfunc _raw_spin_lock(raw_spinlock_t *lock) __acquires(lock);


下面的是最后一个。

void __lockfunc _raw_spin_lock(raw_spinlock_t *lock)
{
__raw_spin_lock(lock);
}




猜你喜欢

转载自blog.csdn.net/haozhenghui10/article/details/40181271