相关话题:SMP和cpu。多个cpu和单个cpu。很多书说自旋锁只能在多处理机中使用,这是不正确的。
首先定义
Spinlock_t lock;
对不起,我只能找到arm平台的锁了
/*
* ARMv6 Spin-locking.
*
* We (exclusively) read the old value, and decrement it. If it
* hits zero, we may have won the lock, so we try (exclusively)
* storing it.
*
* Unlocked value: 0
* Locked value: 1
*/
typedef struct {
volatile unsigned int lock;
#ifdef CONFIG_PREEMPT
unsigned int break_lock;
#endif
} spinlock_t;
补上x86平台
#define SPINLOCK_MAGIC 0x1D244B3C
typedef struct {
unsigned long magic;
volatile unsigned long lock;
volatile unsigned int babble;
const char *module; // 所属模块
char *owner;
int oline;
} spinlock_t;