semaphore.h 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #ifndef _SPARC64_SEMAPHORE_H
  2. #define _SPARC64_SEMAPHORE_H
  3. /* These are actually reasonable on the V9.
  4. *
  5. * See asm-ppc/semaphore.h for implementation commentary,
  6. * only sparc64 specific issues are commented here.
  7. */
  8. #ifdef __KERNEL__
  9. #include <asm/atomic.h>
  10. #include <asm/system.h>
  11. #include <linux/wait.h>
  12. #include <linux/rwsem.h>
  13. struct semaphore {
  14. atomic_t count;
  15. wait_queue_head_t wait;
  16. };
  17. #define __SEMAPHORE_INITIALIZER(name, count) \
  18. { ATOMIC_INIT(count), \
  19. __WAIT_QUEUE_HEAD_INITIALIZER((name).wait) }
  20. #define __DECLARE_SEMAPHORE_GENERIC(name, count) \
  21. struct semaphore name = __SEMAPHORE_INITIALIZER(name,count)
  22. #define DECLARE_MUTEX(name) __DECLARE_SEMAPHORE_GENERIC(name, 1)
  23. #define DECLARE_MUTEX_LOCKED(name) __DECLARE_SEMAPHORE_GENERIC(name, 0)
  24. static inline void sema_init (struct semaphore *sem, int val)
  25. {
  26. atomic_set(&sem->count, val);
  27. init_waitqueue_head(&sem->wait);
  28. }
  29. static inline void init_MUTEX (struct semaphore *sem)
  30. {
  31. sema_init(sem, 1);
  32. }
  33. static inline void init_MUTEX_LOCKED (struct semaphore *sem)
  34. {
  35. sema_init(sem, 0);
  36. }
  37. extern void up(struct semaphore *sem);
  38. extern void down(struct semaphore *sem);
  39. extern int down_trylock(struct semaphore *sem);
  40. extern int down_interruptible(struct semaphore *sem);
  41. #endif /* __KERNEL__ */
  42. #endif /* !(_SPARC64_SEMAPHORE_H) */