1 #ifndef _ASM_IA64_SEMAPHORE_H
2 #define _ASM_IA64_SEMAPHORE_H
5 * Copyright (C) 1998-2000 Hewlett-Packard Co
6 * Copyright (C) 1998-2000 David Mosberger-Tang <davidm@hpl.hp.com>
9 #include <linux/wait.h>
10 #include <linux/rwsem.h>
12 #include <asm/atomic.h>
17 wait_queue_head_t wait;
19 long __magic; /* initialized by __SEM_DEBUG_INIT() */
24 # define __SEM_DEBUG_INIT(name) , (long) &(name).__magic
26 # define __SEM_DEBUG_INIT(name)
29 #define __SEMAPHORE_INITIALIZER(name,count) \
31 ATOMIC_INIT(count), 0, __WAIT_QUEUE_HEAD_INITIALIZER((name).wait) \
32 __SEM_DEBUG_INIT(name) \
35 #define __MUTEX_INITIALIZER(name) __SEMAPHORE_INITIALIZER(name,1)
37 #define __DECLARE_SEMAPHORE_GENERIC(name,count) \
38 struct semaphore name = __SEMAPHORE_INITIALIZER(name, count)
40 #define DECLARE_MUTEX(name) __DECLARE_SEMAPHORE_GENERIC(name, 1)
41 #define DECLARE_MUTEX_LOCKED(name) __DECLARE_SEMAPHORE_GENERIC(name, 0)
44 sema_init (struct semaphore *sem, int val)
46 *sem = (struct semaphore) __SEMAPHORE_INITIALIZER(*sem, val);
50 init_MUTEX (struct semaphore *sem)
56 init_MUTEX_LOCKED (struct semaphore *sem)
61 extern void __down (struct semaphore * sem);
62 extern int __down_interruptible (struct semaphore * sem);
63 extern int __down_trylock (struct semaphore * sem);
64 extern void __up (struct semaphore * sem);
67 * Atomically decrement the semaphore's count. If it goes negative,
68 * block the calling thread in the TASK_UNINTERRUPTIBLE state.
71 down (struct semaphore *sem)
74 CHECK_MAGIC(sem->__magic);
77 if (atomic_dec_return(&sem->count) < 0)
82 * Atomically decrement the semaphore's count. If it goes negative,
83 * block the calling thread in the TASK_INTERRUPTIBLE state.
86 down_interruptible (struct semaphore * sem)
91 CHECK_MAGIC(sem->__magic);
94 if (atomic_dec_return(&sem->count) < 0)
95 ret = __down_interruptible(sem);
100 down_trylock (struct semaphore *sem)
105 CHECK_MAGIC(sem->__magic);
107 if (atomic_dec_return(&sem->count) < 0)
108 ret = __down_trylock(sem);
113 up (struct semaphore * sem)
116 CHECK_MAGIC(sem->__magic);
118 if (atomic_inc_return(&sem->count) <= 0)
122 #endif /* _ASM_IA64_SEMAPHORE_H */