2008-03-07 19:55:58 -07:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2008 Intel Corporation
|
|
|
|
* Author: Matthew Wilcox <willy@linux.intel.com>
|
|
|
|
*
|
|
|
|
* Distributed under the terms of the GNU GPL, version 2
|
|
|
|
*
|
2008-04-11 13:23:52 -06:00
|
|
|
* Please see kernel/semaphore.c for documentation of these functions
|
2008-03-07 19:55:58 -07:00
|
|
|
*/
|
|
|
|
#ifndef __LINUX_SEMAPHORE_H
|
|
|
|
#define __LINUX_SEMAPHORE_H
|
|
|
|
|
|
|
|
#include <linux/list.h>
|
|
|
|
#include <linux/spinlock.h>
|
|
|
|
|
2008-04-11 13:23:52 -06:00
|
|
|
/* Please don't access any members of this structure directly */
|
2008-03-07 19:55:58 -07:00
|
|
|
struct semaphore {
|
|
|
|
spinlock_t lock;
|
2008-03-14 12:35:22 -06:00
|
|
|
unsigned int count;
|
2008-03-07 19:55:58 -07:00
|
|
|
struct list_head wait_list;
|
|
|
|
};
|
|
|
|
|
|
|
|
#define __SEMAPHORE_INITIALIZER(name, n) \
|
|
|
|
{ \
|
|
|
|
.lock = __SPIN_LOCK_UNLOCKED((name).lock), \
|
|
|
|
.count = n, \
|
|
|
|
.wait_list = LIST_HEAD_INIT((name).wait_list), \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define __DECLARE_SEMAPHORE_GENERIC(name, count) \
|
|
|
|
struct semaphore name = __SEMAPHORE_INITIALIZER(name, count)
|
|
|
|
|
|
|
|
#define DECLARE_MUTEX(name) __DECLARE_SEMAPHORE_GENERIC(name, 1)
|
|
|
|
|
|
|
|
static inline void sema_init(struct semaphore *sem, int val)
|
|
|
|
{
|
|
|
|
static struct lock_class_key __key;
|
|
|
|
*sem = (struct semaphore) __SEMAPHORE_INITIALIZER(*sem, val);
|
|
|
|
lockdep_init_map(&sem->lock.dep_map, "semaphore->lock", &__key, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
#define init_MUTEX(sem) sema_init(sem, 1)
|
|
|
|
#define init_MUTEX_LOCKED(sem) sema_init(sem, 0)
|
|
|
|
|
|
|
|
extern void down(struct semaphore *sem);
|
|
|
|
extern int __must_check down_interruptible(struct semaphore *sem);
|
2008-03-14 11:19:33 -06:00
|
|
|
extern int __must_check down_killable(struct semaphore *sem);
|
2008-03-07 19:55:58 -07:00
|
|
|
extern int __must_check down_trylock(struct semaphore *sem);
|
2008-03-14 11:43:13 -06:00
|
|
|
extern int __must_check down_timeout(struct semaphore *sem, long jiffies);
|
2008-03-07 19:55:58 -07:00
|
|
|
extern void up(struct semaphore *sem);
|
|
|
|
|
|
|
|
#endif /* __LINUX_SEMAPHORE_H */
|