spinlock.h
DEFINE_SPINLOCK
在kernel里面找到一个使用他的例子
获取锁
static inline void spin_lock(spinlock_t *lock)
{
raw_spin_lock(&lock->rlock);
}
static DEFINE_SPINLOCK(threads_lock);
struct our_data{
int count1;
int count2;
};
static struct our_data my_data;
#define MAX_KTHREAD 10
static struct task_struct *threads[MAX_KTHREAD];
static int thread_do(void *data)
{
printk("run ...\n");
while(!kthread_should_stop())
{
spin_lock(&threads_lock);
my_data.count1++;
my_data.count2 += 10;
spin_unlock(&threads_lock);
msleep(10);
}
return 0;
}
===============
如果我们不是编译时候初始化spinlock,而是运行时初始化他。
static spinlock_t threads_lock;
static void threads_lock_init(void)
{
//spin_lock_init
spin_lock_init(&threads_lock);
}
static __init int minit(void)
{
// printk("testpar= %#x.\n",testpar);
printk("call %s.\n",__FUNCTION__);
// other_function();
threads_lock_init();
if(create_threads())
{
cleanup_threads();
return -1;
}
return 0;
}