-
Notifications
You must be signed in to change notification settings - Fork 0
/
spinlock.h
51 lines (40 loc) · 1009 Bytes
/
spinlock.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#ifndef OSP_SPINLOCK_H
#define OSP_SPINLOCK_H
#define CONFIG_OSP_SPINLOCK !(defined(CONFIG_SMP) || defined(CONFIG_PREEMPT))
#if CONFIG_OSP_SPINLOCK
#include <linux/kernel.h> /* printk() */
typedef struct osp_spinlock {
int lock;
} osp_spinlock_t;
static void osp_spin_lock_init(osp_spinlock_t *lock)
{
lock->lock = 0;
}
static void osp_spin_lock(osp_spinlock_t *lock)
{
if (lock->lock-- < 0)
{
printk(KERN_EMERG "spin_lock() on a locked lock! Run \"dmesg\" to see a stack trace.\n");
dump_stack();
if (current)
{
printk(KERN_EMERG "Killing your process because it would have deadlocked!\n");
send_sig(SIGKILL, current, 0);
}
}
}
static void osp_spin_unlock(osp_spinlock_t *lock)
{
if (++lock->lock > 0)
{
printk(KERN_EMERG "spin_unlock() on an unlocked lock!\n");
dump_stack();
}
}
#else
#define osp_spinlock_t spinlock_t
#define osp_spin_lock_init spin_lock_init
#define osp_spin_lock spin_lock
#define osp_spin_unlock spin_unlock
#endif
#endif /* OSP_SPINLOCK_H */