2019-06-01 16:08:50 +08:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0-only */
|
2008-03-08 10:55:58 +08:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2008 Intel Corporation
|
|
|
|
* Author: Matthew Wilcox <willy@linux.intel.com>
|
|
|
|
*
|
2018-02-01 19:41:19 +08:00
|
|
|
* Please see kernel/locking/semaphore.c for documentation of these functions
|
2008-03-08 10:55:58 +08:00
|
|
|
*/
|
|
|
|
#ifndef __LINUX_SEMAPHORE_H
|
|
|
|
#define __LINUX_SEMAPHORE_H
|
|
|
|
|
|
|
|
#include <linux/list.h>
|
|
|
|
#include <linux/spinlock.h>
|
|
|
|
|
2008-04-12 03:23:52 +08:00
|
|
|
/* Please don't access any members of this structure directly */
|
2008-03-08 10:55:58 +08:00
|
|
|
struct semaphore {
|
2010-02-24 16:50:22 +08:00
|
|
|
raw_spinlock_t lock;
|
2008-03-15 02:35:22 +08:00
|
|
|
unsigned int count;
|
2008-03-08 10:55:58 +08:00
|
|
|
struct list_head wait_list;
|
|
|
|
};
|
|
|
|
|
|
|
|
#define __SEMAPHORE_INITIALIZER(name, n) \
|
|
|
|
{ \
|
2010-02-24 16:50:22 +08:00
|
|
|
.lock = __RAW_SPIN_LOCK_UNLOCKED((name).lock), \
|
2008-03-08 10:55:58 +08:00
|
|
|
.count = n, \
|
|
|
|
.wait_list = LIST_HEAD_INIT((name).wait_list), \
|
|
|
|
}
|
|
|
|
|
2010-09-07 20:46:37 +08:00
|
|
|
#define DEFINE_SEMAPHORE(name) \
|
|
|
|
struct semaphore name = __SEMAPHORE_INITIALIZER(name, 1)
|
|
|
|
|
2008-03-08 10:55:58 +08:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
extern void down(struct semaphore *sem);
|
|
|
|
extern int __must_check down_interruptible(struct semaphore *sem);
|
2008-03-15 01:19:33 +08:00
|
|
|
extern int __must_check down_killable(struct semaphore *sem);
|
2008-03-08 10:55:58 +08:00
|
|
|
extern int __must_check down_trylock(struct semaphore *sem);
|
2008-03-15 01:43:13 +08:00
|
|
|
extern int __must_check down_timeout(struct semaphore *sem, long jiffies);
|
2008-03-08 10:55:58 +08:00
|
|
|
extern void up(struct semaphore *sem);
|
|
|
|
|
|
|
|
#endif /* __LINUX_SEMAPHORE_H */
|