home *** CD-ROM | disk | FTP | other *** search
/ PC Welt 2006 November (DVD) / PCWELT_11_2006.ISO / casper / filesystem.squashfs / usr / src / linux-headers-2.6.17-6 / include / asm-sparc64 / semaphore.h < prev    next >
Encoding:
C/C++ Source or Header  |  2006-08-11  |  1.3 KB  |  55 lines

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