-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathlock.h
93 lines (76 loc) · 2.78 KB
/
lock.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */
#ifndef __LOCK_H__
#define __LOCK_H__
#ifdef __KERNEL__
#include <linux/spinlock.h>
#define spin_lock_destroy(x)
#define rwlock_destroy(x)
#else
#include <pthread.h>
typedef pthread_mutex_t spinlock_t;
#define SPIN_LOCK_UNLOCKED PTHREAD_MUTEX_INITIALIZER
#define DEFINE_SPINLOCK(x) spinlock_t x = PTHREAD_MUTEX_INITIALIZER
#define spin_lock_init(x) pthread_mutex_init(x, NULL)
#define spin_lock_init_recursive(x) { \
pthread_mutexattr_t attr; \
pthread_mutexattr_init(&attr); \
pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE); \
pthread_mutex_init(&mutex, &attr); \
pthread_mutexattr_destroy(&attr); }
/*
#define spin_lock_destroy(x) pthread_mutex_destroy(x)
#define spin_lock(x) pthread_mutex_lock(x)
#define spin_trylock(x) pthread_mutex_trylock(x)
#define spin_unlock(x) pthread_mutex_unlock(x)
#define spin_lock_bh(x) pthread_mutex_lock(x)
#define spin_trylock_bh(x) pthread_mutex_trylock(x)
#define spin_unlock_bh(x) pthread_mutex_unlock(x)
#define spin_lock_irqsave(x, flags) pthread_mutex_lock(x)
#define spin_unlock_irqrestore(x, flags) pthread_mutex_unlock(x)
*/
#define spin_lock_destroy(x)
#define spin_lock(x)
#define spin_trylock(x)
#define spin_unlock(x)
#define spin_lock_bh(x)
#define spin_trylock_bh(x)
#define spin_unlock_bh(x)
#define spin_lock_irqsave(x, flags)
#define spin_unlock_irqrestore(x, flags)
typedef pthread_mutex_t rwlock_t;
#define __RW_LOCK_UNLOCKED(x) PTHREAD_MUTEX_INITIALIZER
#define DEFINE_RWLOCK(x) rwlock_t x = PTHREAD_MUTEX_INITIALIZER
/*
#define rwlock_init(x) pthread_mutex_init(x, NULL)
#define rwlock_destroy(x) pthread_mutex_destroy(x)
#define write_lock(x) pthread_mutex_lock(x)
#define read_lock(x) pthread_mutex_lock(x)
#define write_lock_bh(x) pthread_mutex_lock(x)
#define read_lock_bh(x) pthread_mutex_lock(x)
#define write_trylock(x) pthread_mutex_trylock(x)
#define read_trylock(x) pthread_mutex_trylock(x)
#define write_trylock_bh(x) pthread_mutex_trylock(x)
#define read_trylock_bh(x) pthread_mutex_trylock(x)
#define write_unlock(x) pthread_mutex_unlock(x)
#define read_unlock(x) pthread_mutex_unlock(x)
#define write_unlock_bh(x) pthread_mutex_unlock(x)
#define read_unlock_bh(x) pthread_mutex_unlock(x)
*/
#define rwlock_init(x)
#define rwlock_destroy(x)
#define write_lock(x)
#define read_lock(x)
#define write_lock_bh(x)
#define read_lock_bh(x)
#define write_trylock(x)
#define read_trylock(x)
#define write_trylock_bh(x)
#define read_trylock_bh(x)
#define write_unlock(x)
#define read_unlock(x)
#define write_unlock_bh(x)
#define read_unlock_bh(x)
#define local_bh_disable()
#define local_bh_enable()
#endif /* __KERNEL__ */
#endif /* __LOCK_H__ */