source: cmedia/trunk/Include/Asm/semaphore.h

Last change on this file was 354, checked in by stevenhl, 17 years ago

Import untested baseline cmedia sources, work products and binaries
Binaries and work products should be deleted from repository.
once new builds are verified to work.

File size: 3.2 KB
Line 
1/* $Id: semaphore.h,v 1.1 2000/04/23 14:55:29 ktk 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{ ATOMIC_INIT(count), 0, __WAIT_QUEUE_HEAD_INITIALIZER((name).wait) \
52 __SEM_DEBUG_INIT(name) }
53
54#define __MUTEX_INITIALIZER(name) \
55 __SEMAPHORE_INITIALIZER(name,1)
56
57#define __DECLARE_SEMAPHORE_GENERIC(name,count) \
58 struct semaphore name = __SEMAPHORE_INITIALIZER(name,count)
59
60#define DECLARE_MUTEX(name) __DECLARE_SEMAPHORE_GENERIC(name,1)
61#define DECLARE_MUTEX_LOCKED(name) __DECLARE_SEMAPHORE_GENERIC(name,0)
62
63extern void sema_init (struct semaphore *sem, int val);
64void init_MUTEX (struct semaphore *sem);
65void init_MUTEX_LOCKED (struct semaphore *sem);
66
67 void __down_failed(void /* special register calling convention */);
68 int __down_failed_interruptible(void /* params in registers */);
69 int __down_failed_trylock(void /* params in registers */);
70 void __up_wakeup(void /* special register calling convention */);
71
72 void __down(struct semaphore * sem);
73 int __down_interruptible(struct semaphore * sem);
74 int __down_trylock(struct semaphore * sem);
75 void __up(struct semaphore * sem);
76
77/*
78 * This is ugly, but we want the default case to fall through.
79 * "down_failed" is a special asm handler that calls the C
80 * routine that actually waits. See arch/i386/lib/semaphore.S
81 */
82extern void down(struct semaphore * sem);
83
84extern int down_interruptible(struct semaphore * sem);
85
86extern int down_trylock(struct semaphore * sem);
87
88/*
89 * Note! This is subtle. We jump to wake people up only if
90 * the semaphore was negative (== somebody was waiting on it).
91 * The default case (no contention) will result in NO
92 * jumps for both down() and up().
93 */
94extern void up(struct semaphore * sem);
95
96#endif
Note: See TracBrowser for help on using the repository browser.