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
;
20 #define __SEMAPHORE_INITIALIZER(name, n) \
22 .count = ATOMIC_INIT(n), \
24 .wait = __WAIT_QUEUE_HEAD_INITIALIZER((name).wait) \
27 #define __DECLARE_SEMAPHORE_GENERIC(name,count) \
28 struct semaphore name = __SEMAPHORE_INITIALIZER(name, count)
30 #define DECLARE_MUTEX(name) __DECLARE_SEMAPHORE_GENERIC(name, 1)
33 sema_init (struct semaphore
*sem
, int val
)
35 *sem
= (struct semaphore
) __SEMAPHORE_INITIALIZER(*sem
, val
);
39 init_MUTEX (struct semaphore
*sem
)
45 init_MUTEX_LOCKED (struct semaphore
*sem
)
50 extern void __down (struct semaphore
* sem
);
51 extern int __down_interruptible (struct semaphore
* sem
);
52 extern int __down_trylock (struct semaphore
* sem
);
53 extern void __up (struct semaphore
* sem
);
56 * Atomically decrement the semaphore's count. If it goes negative,
57 * block the calling thread in the TASK_UNINTERRUPTIBLE state.
60 down (struct semaphore
*sem
)
63 if (ia64_fetchadd(-1, &sem
->count
.counter
, acq
) < 1)
68 * Atomically decrement the semaphore's count. If it goes negative,
69 * block the calling thread in the TASK_INTERRUPTIBLE state.
72 down_interruptible (struct semaphore
* sem
)
77 if (ia64_fetchadd(-1, &sem
->count
.counter
, acq
) < 1)
78 ret
= __down_interruptible(sem
);
83 down_trylock (struct semaphore
*sem
)
87 if (ia64_fetchadd(-1, &sem
->count
.counter
, acq
) < 1)
88 ret
= __down_trylock(sem
);
93 up (struct semaphore
* sem
)
95 if (ia64_fetchadd(1, &sem
->count
.counter
, rel
) <= -1)
99 #endif /* _ASM_IA64_SEMAPHORE_H */