rwsem-spinlock.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /* rwsem-spinlock.h: fallback C implementation
  2. *
  3. * Copyright (c) 2001 David Howells (dhowells@redhat.com).
  4. * - Derived partially from ideas by Andrea Arcangeli <andrea@suse.de>
  5. * - Derived also from comments by Linus
  6. */
  7. #ifndef _LINUX_RWSEM_SPINLOCK_H
  8. #define _LINUX_RWSEM_SPINLOCK_H
  9. #ifndef _LINUX_RWSEM_H
  10. #error "please don't include linux/rwsem-spinlock.h directly, use linux/rwsem.h instead"
  11. #endif
  12. #include <linux/spinlock.h>
  13. #include <linux/list.h>
  14. #ifdef __KERNEL__
  15. #include <linux/types.h>
  16. struct rwsem_waiter;
  17. /*
  18. * the rw-semaphore definition
  19. * - if activity is 0 then there are no active readers or writers
  20. * - if activity is +ve then that is the number of active readers
  21. * - if activity is -1 then there is one active writer
  22. * - if wait_list is not empty, then there are processes waiting for the semaphore
  23. */
  24. struct rw_semaphore {
  25. __s32 activity;
  26. spinlock_t wait_lock;
  27. struct list_head wait_list;
  28. #if RWSEM_DEBUG
  29. int debug;
  30. #endif
  31. };
  32. /*
  33. * initialisation
  34. */
  35. #if RWSEM_DEBUG
  36. #define __RWSEM_DEBUG_INIT , 0
  37. #else
  38. #define __RWSEM_DEBUG_INIT /* */
  39. #endif
  40. #define __RWSEM_INITIALIZER(name) \
  41. { 0, SPIN_LOCK_UNLOCKED, LIST_HEAD_INIT((name).wait_list) __RWSEM_DEBUG_INIT }
  42. #define DECLARE_RWSEM(name) \
  43. struct rw_semaphore name = __RWSEM_INITIALIZER(name)
  44. extern void FASTCALL(init_rwsem(struct rw_semaphore *sem));
  45. extern void FASTCALL(__down_read(struct rw_semaphore *sem));
  46. extern int FASTCALL(__down_read_trylock(struct rw_semaphore *sem));
  47. extern void FASTCALL(__down_write(struct rw_semaphore *sem));
  48. extern int FASTCALL(__down_write_trylock(struct rw_semaphore *sem));
  49. extern void FASTCALL(__up_read(struct rw_semaphore *sem));
  50. extern void FASTCALL(__up_write(struct rw_semaphore *sem));
  51. extern void FASTCALL(__downgrade_write(struct rw_semaphore *sem));
  52. #endif /* __KERNEL__ */
  53. #endif /* _LINUX_RWSEM_SPINLOCK_H */