summaryrefslogtreecommitdiff
path: root/datapath/linux-2.6/compat-2.6/include/linux/mutex.h
blob: 93dfa3b2b46374e8031f74d9d23bec2c51e7234d (plain)
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
#ifndef __LINUX_MUTEX_WRAPPER_H
#define __LINUX_MUTEX_WRAPPER_H


#include <linux/version.h>
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,16)

#include <asm/semaphore.h>

struct mutex {
	struct semaphore sema;
};

#define mutex_init(mutex) init_MUTEX(&(mutex)->sema)
#define mutex_destroy(mutex) do { } while (0)

#define __MUTEX_INITIALIZER(name) \
			__SEMAPHORE_INITIALIZER(name,1)

#define DEFINE_MUTEX(mutexname) \
	struct mutex mutexname = { __MUTEX_INITIALIZER(mutexname.sema) }

/*
 * See kernel/mutex.c for detailed documentation of these APIs.
 * Also see Documentation/mutex-design.txt.
 */
static inline void mutex_lock(struct mutex *lock)
{
	down(&lock->sema);
}

static inline int mutex_lock_interruptible(struct mutex *lock)
{
	return down_interruptible(&lock->sema);
}

#define mutex_lock_nested(lock, subclass) mutex_lock(lock)
#define mutex_lock_interruptible_nested(lock, subclass) mutex_lock_interruptible(lock)

/*
 * NOTE: mutex_trylock() follows the spin_trylock() convention,
 *       not the down_trylock() convention!
 */
static inline int mutex_trylock(struct mutex *lock)
{
	return !down_trylock(&lock->sema);
}

static inline void mutex_unlock(struct mutex *lock)
{
	up(&lock->sema);
}
#else 

#include_next <linux/mutex.h>

#endif /* linux version < 2.6.16 */

#endif