semaphore.h 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. static inline void sema_init (struct semaphore *sem, int val)
  24. {
  25. atomic_set(&sem->count, val);
  26. init_waitqueue_head(&sem->wait);
  27. }
  28. static inline void init_MUTEX (struct semaphore *sem)
  29. {
  30. sema_init(sem, 1);
  31. }
  32. static inline void init_MUTEX_LOCKED (struct semaphore *sem)
  33. {
  34. sema_init(sem, 0);
  35. }
  36. extern void up(struct semaphore *sem);
  37. extern void down(struct semaphore *sem);
  38. extern int down_trylock(struct semaphore *sem);
  39. extern int down_interruptible(struct semaphore *sem);
  40. #endif /* __KERNEL__ */
  41. #endif /* !(_SPARC64_SEMAPHORE_H) */