]> bbs.cooldavid.org Git - net-next-2.6.git/blame - include/linux/semaphore.h
Merge branch 'fix/asoc' into for-linus
[net-next-2.6.git] / include / linux / semaphore.h
CommitLineData
64ac24e7
MW
1/*
2 * Copyright (c) 2008 Intel Corporation
3 * Author: Matthew Wilcox <willy@linux.intel.com>
4 *
5 * Distributed under the terms of the GNU GPL, version 2
6 *
714493cd 7 * Please see kernel/semaphore.c for documentation of these functions
64ac24e7
MW
8 */
9#ifndef __LINUX_SEMAPHORE_H
10#define __LINUX_SEMAPHORE_H
11
12#include <linux/list.h>
13#include <linux/spinlock.h>
14
714493cd 15/* Please don't access any members of this structure directly */
64ac24e7
MW
16struct semaphore {
17 spinlock_t lock;
b17170b2 18 unsigned int count;
64ac24e7
MW
19 struct list_head wait_list;
20};
21
22#define __SEMAPHORE_INITIALIZER(name, n) \
23{ \
24 .lock = __SPIN_LOCK_UNLOCKED((name).lock), \
25 .count = n, \
26 .wait_list = LIST_HEAD_INIT((name).wait_list), \
27}
28
febc88c5
TG
29#define DEFINE_SEMAPHORE(name) \
30 struct semaphore name = __SEMAPHORE_INITIALIZER(name, 1)
31
b5520689
MW
32#define DECLARE_MUTEX(name) \
33 struct semaphore name = __SEMAPHORE_INITIALIZER(name, 1)
64ac24e7
MW
34
35static inline void sema_init(struct semaphore *sem, int val)
36{
37 static struct lock_class_key __key;
38 *sem = (struct semaphore) __SEMAPHORE_INITIALIZER(*sem, val);
39 lockdep_init_map(&sem->lock.dep_map, "semaphore->lock", &__key, 0);
40}
41
42#define init_MUTEX(sem) sema_init(sem, 1)
43#define init_MUTEX_LOCKED(sem) sema_init(sem, 0)
44
64ac24e7 45extern void down(struct semaphore *sem);
64ac24e7 46extern int __must_check down_interruptible(struct semaphore *sem);
f06d9686 47extern int __must_check down_killable(struct semaphore *sem);
64ac24e7 48extern int __must_check down_trylock(struct semaphore *sem);
f1241c87 49extern int __must_check down_timeout(struct semaphore *sem, long jiffies);
64ac24e7
MW
50extern void up(struct semaphore *sem);
51
52#endif /* __LINUX_SEMAPHORE_H */