source: GPL/include/asm/semaphore.h@ 18

Last change on this file since 18 was 18, checked in by vladest, 20 years ago

initial import

File size: 3.1 KB
Line 
1/* $Id: semaphore.h,v 1.1.1.1 2003/07/02 13:56:58 eleph Exp $ */
2
3#ifndef _I386_SEMAPHORE_H
4#define _I386_SEMAPHORE_H
5
6/*
7 * SMP- and interrupt-safe semaphores..
8 *
9 * (C) Copyright 1996 Linus Torvalds
10 *
11 * Modified 1996-12-23 by Dave Grothe <dave@gcom.com> to fix bugs in
12 * the original code and to make semaphore waits
13 * interruptible so that processes waiting on
14 * semaphores can be killed.
15 * Modified 1999-02-14 by Andrea Arcangeli, split the sched.c helper
16 * functions in asm/sempahore-helper.h while fixing a
17 * potential and subtle race discovered by Ulrich Schmid
18 * in down_interruptible(). Since I started to play here I
19 * also implemented the `trylock' semaphore operation.
20 * 1999-07-02 Artur Skawina <skawina@geocities.com>
21 * Optimized "0(ecx)" -> "(ecx)" (the assembler does not
22 * do this). Changed calling sequences from push/jmp to
23 * traditional call/ret.
24 *
25 * If you would like to see an analysis of this implementation, please
26 * ftp to gcom.com and download the file
27 * /pub/linux/src/semaphore/semaphore-2.0.24.tar.gz.
28 *
29 */
30
31#include <asm/atomic.h>
32#include <linux/spinlock.h>
33
34struct semaphore {
35 atomic_t count;
36 int sleepers;
37 void * wait;
38#if WAITQUEUE_DEBUG
39 long __magic;
40#endif
41};
42
43#if WAITQUEUE_DEBUG
44# define __SEM_DEBUG_INIT(name) \
45 , (int)&(name).__magic
46#else
47# define __SEM_DEBUG_INIT(name)
48#endif
49
50#define __SEMAPHORE_INITIALIZER(name,count) \
51{ count, 0, NULL }
52
53#define __MUTEX_INITIALIZER(name) \
54 __SEMAPHORE_INITIALIZER(name,1)
55
56#define __DECLARE_SEMAPHORE_GENERIC(name,count) \
57 struct semaphore name = __SEMAPHORE_INITIALIZER(name,count)
58
59#define DECLARE_MUTEX(name) __DECLARE_SEMAPHORE_GENERIC(name,1)
60#define DECLARE_MUTEX_LOCKED(name) __DECLARE_SEMAPHORE_GENERIC(name,0)
61
62extern void sema_init (struct semaphore *sem, int val);
63void init_MUTEX (struct semaphore *sem);
64void init_MUTEX_LOCKED (struct semaphore *sem);
65
66 void __down_failed(void /* special register calling convention */);
67 int __down_failed_interruptible(void /* params in registers */);
68 int __down_failed_trylock(void /* params in registers */);
69 void __up_wakeup(void /* special register calling convention */);
70
71 void __down(struct semaphore * sem);
72 int __down_interruptible(struct semaphore * sem);
73 int __down_trylock(struct semaphore * sem);
74 void __up(struct semaphore * sem);
75
76/*
77 * This is ugly, but we want the default case to fall through.
78 * "down_failed" is a special asm handler that calls the C
79 * routine that actually waits. See arch/i386/lib/semaphore.S
80 */
81extern void down(struct semaphore * sem);
82
83extern int down_interruptible(struct semaphore * sem);
84
85extern int down_trylock(struct semaphore * sem);
86
87/*
88 * Note! This is subtle. We jump to wake people up only if
89 * the semaphore was negative (== somebody was waiting on it).
90 * The default case (no contention) will result in NO
91 * jumps for both down() and up().
92 */
93extern void up(struct semaphore * sem);
94
95#endif
Note: See TracBrowser for help on using the repository browser.