aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/semaphore.h
diff options
context:
space:
mode:
authorMatthew Wilcox <matthew@wil.cx>2008-04-11 15:23:52 -0400
committerMatthew Wilcox <willy@linux.intel.com>2008-04-17 10:43:01 -0400
commit714493cd5468f42ca3c4f730a9c17c203abd5059 (patch)
tree9d087ad3b74cb1bd6fbd9be486fc2b361c6407dd /include/linux/semaphore.h
parentb17170b2fac96705db3188f093f89e8e838418e4 (diff)
Improve semaphore documentation
Move documentation from semaphore.h to semaphore.c as requested by Andrew Morton. Also reformat to kernel-doc style and add some more notes about the implementation. Signed-off-by: Matthew Wilcox <willy@linux.intel.com>
Diffstat (limited to 'include/linux/semaphore.h')
-rw-r--r--include/linux/semaphore.h39
1 files changed, 2 insertions, 37 deletions
diff --git a/include/linux/semaphore.h b/include/linux/semaphore.h
index a7125daaff9..9cae64b00d6 100644
--- a/include/linux/semaphore.h
+++ b/include/linux/semaphore.h
@@ -4,8 +4,7 @@
4 * 4 *
5 * Distributed under the terms of the GNU GPL, version 2 5 * Distributed under the terms of the GNU GPL, version 2
6 * 6 *
7 * Counting semaphores allow up to <n> tasks to acquire the semaphore 7 * Please see kernel/semaphore.c for documentation of these functions
8 * simultaneously.
9 */ 8 */
10#ifndef __LINUX_SEMAPHORE_H 9#ifndef __LINUX_SEMAPHORE_H
11#define __LINUX_SEMAPHORE_H 10#define __LINUX_SEMAPHORE_H
@@ -13,11 +12,7 @@
13#include <linux/list.h> 12#include <linux/list.h>
14#include <linux/spinlock.h> 13#include <linux/spinlock.h>
15 14
16/* 15/* Please don't access any members of this structure directly */
17 * The spinlock controls access to the other members of the semaphore.
18 * 'count' represents how many more tasks can acquire this semaphore.
19 * Tasks waiting for the lock are kept on the wait_list.
20 */
21struct semaphore { 16struct semaphore {
22 spinlock_t lock; 17 spinlock_t lock;
23 unsigned int count; 18 unsigned int count;
@@ -46,41 +41,11 @@ static inline void sema_init(struct semaphore *sem, int val)
46#define init_MUTEX(sem) sema_init(sem, 1) 41#define init_MUTEX(sem) sema_init(sem, 1)
47#define init_MUTEX_LOCKED(sem) sema_init(sem, 0) 42#define init_MUTEX_LOCKED(sem) sema_init(sem, 0)
48 43
49/*
50 * Attempt to acquire the semaphore. If another task is already holding the
51 * semaphore, sleep until the semaphore is released.
52 */
53extern void down(struct semaphore *sem); 44extern void down(struct semaphore *sem);
54
55/*
56 * As down(), except the sleep may be interrupted by a signal. If it is,
57 * this function will return -EINTR.
58 */
59extern int __must_check down_interruptible(struct semaphore *sem); 45extern int __must_check down_interruptible(struct semaphore *sem);
60
61/*
62 * As down_interruptible(), except the sleep may only be interrupted by
63 * signals which are fatal to this process.
64 */
65extern int __must_check down_killable(struct semaphore *sem); 46extern int __must_check down_killable(struct semaphore *sem);
66
67/*
68 * As down(), except this function will not sleep. It will return 0 if it
69 * acquired the semaphore and 1 if the semaphore was contended. This
70 * function may be called from any context, including interrupt and softirq.
71 */
72extern int __must_check down_trylock(struct semaphore *sem); 47extern int __must_check down_trylock(struct semaphore *sem);
73
74/*
75 * As down(), except this function will return -ETIME if it fails to
76 * acquire the semaphore within the specified number of jiffies.
77 */
78extern int __must_check down_timeout(struct semaphore *sem, long jiffies); 48extern int __must_check down_timeout(struct semaphore *sem, long jiffies);
79
80/*
81 * Release the semaphore. Unlike mutexes, up() may be called from any
82 * context and even by tasks which have never called down().
83 */
84extern void up(struct semaphore *sem); 49extern void up(struct semaphore *sem);
85 50
86#endif /* __LINUX_SEMAPHORE_H */ 51#endif /* __LINUX_SEMAPHORE_H */