semaphore.h 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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 __MUTEX_INITIALIZER(name) \
  21. __SEMAPHORE_INITIALIZER(name, 1)
  22. #define __DECLARE_SEMAPHORE_GENERIC(name, count) \
  23. struct semaphore name = __SEMAPHORE_INITIALIZER(name,count)
  24. #define DECLARE_MUTEX(name) __DECLARE_SEMAPHORE_GENERIC(name, 1)
  25. #define DECLARE_MUTEX_LOCKED(name) __DECLARE_SEMAPHORE_GENERIC(name, 0)
  26. static inline void sema_init (struct semaphore *sem, int val)
  27. {
  28. atomic_set(&sem->count, val);
  29. init_waitqueue_head(&sem->wait);
  30. }
  31. static inline void init_MUTEX (struct semaphore *sem)
  32. {
  33. sema_init(sem, 1);
  34. }
  35. static inline void init_MUTEX_LOCKED (struct semaphore *sem)
  36. {
  37. sema_init(sem, 0);
  38. }
  39. extern void up(struct semaphore *sem);
  40. extern void down(struct semaphore *sem);
  41. extern int down_trylock(struct semaphore *sem);
  42. extern int down_interruptible(struct semaphore *sem);
  43. #endif /* __KERNEL__ */
  44. #endif /* !(_SPARC64_SEMAPHORE_H) */