[PATCH] pcmcia: remove client services version (fix)
[linux-2.6/sactl.git] / include / asm-ia64 / semaphore.h
blob3a2f0f3f78f37255d15a0f364031d519fd8add66
1 #ifndef _ASM_IA64_SEMAPHORE_H
2 #define _ASM_IA64_SEMAPHORE_H
4 /*
5 * Copyright (C) 1998-2000 Hewlett-Packard Co
6 * Copyright (C) 1998-2000 David Mosberger-Tang <davidm@hpl.hp.com>
7 */
9 #include <linux/wait.h>
10 #include <linux/rwsem.h>
12 #include <asm/atomic.h>
14 struct semaphore {
15 atomic_t count;
16 int sleepers;
17 wait_queue_head_t wait;
20 #define __SEMAPHORE_INITIALIZER(name, n) \
21 { \
22 .count = ATOMIC_INIT(n), \
23 .sleepers = 0, \
24 .wait = __WAIT_QUEUE_HEAD_INITIALIZER((name).wait) \
27 #define __MUTEX_INITIALIZER(name) __SEMAPHORE_INITIALIZER(name,1)
29 #define __DECLARE_SEMAPHORE_GENERIC(name,count) \
30 struct semaphore name = __SEMAPHORE_INITIALIZER(name, count)
32 #define DECLARE_MUTEX(name) __DECLARE_SEMAPHORE_GENERIC(name, 1)
33 #define DECLARE_MUTEX_LOCKED(name) __DECLARE_SEMAPHORE_GENERIC(name, 0)
35 static inline void
36 sema_init (struct semaphore *sem, int val)
38 *sem = (struct semaphore) __SEMAPHORE_INITIALIZER(*sem, val);
41 static inline void
42 init_MUTEX (struct semaphore *sem)
44 sema_init(sem, 1);
47 static inline void
48 init_MUTEX_LOCKED (struct semaphore *sem)
50 sema_init(sem, 0);
53 extern void __down (struct semaphore * sem);
54 extern int __down_interruptible (struct semaphore * sem);
55 extern int __down_trylock (struct semaphore * sem);
56 extern void __up (struct semaphore * sem);
59 * Atomically decrement the semaphore's count. If it goes negative,
60 * block the calling thread in the TASK_UNINTERRUPTIBLE state.
62 static inline void
63 down (struct semaphore *sem)
65 might_sleep();
66 if (atomic_dec_return(&sem->count) < 0)
67 __down(sem);
71 * Atomically decrement the semaphore's count. If it goes negative,
72 * block the calling thread in the TASK_INTERRUPTIBLE state.
74 static inline int
75 down_interruptible (struct semaphore * sem)
77 int ret = 0;
79 might_sleep();
80 if (atomic_dec_return(&sem->count) < 0)
81 ret = __down_interruptible(sem);
82 return ret;
85 static inline int
86 down_trylock (struct semaphore *sem)
88 int ret = 0;
90 if (atomic_dec_return(&sem->count) < 0)
91 ret = __down_trylock(sem);
92 return ret;
95 static inline void
96 up (struct semaphore * sem)
98 if (atomic_inc_return(&sem->count) <= 0)
99 __up(sem);
102 #endif /* _ASM_IA64_SEMAPHORE_H */