spinlock_up.h
上传用户:szlgq88
上传日期:2009-04-28
资源大小:48287k
文件大小:2k
源码类别:

嵌入式Linux

开发平台:

Unix_Linux

  1. #ifndef __LINUX_SPINLOCK_UP_H
  2. #define __LINUX_SPINLOCK_UP_H
  3. #ifndef __LINUX_SPINLOCK_H
  4. # error "please don't include this file directly"
  5. #endif
  6. /*
  7.  * include/linux/spinlock_up.h - UP-debug version of spinlocks.
  8.  *
  9.  * portions Copyright 2005, Red Hat, Inc., Ingo Molnar
  10.  * Released under the General Public License (GPL).
  11.  *
  12.  * In the debug case, 1 means unlocked, 0 means locked. (the values
  13.  * are inverted, to catch initialization bugs)
  14.  *
  15.  * No atomicity anywhere, we are on UP.
  16.  */
  17. #ifdef CONFIG_DEBUG_SPINLOCK
  18. #define __raw_spin_is_locked(x) ((x)->slock == 0)
  19. static inline void __raw_spin_lock(raw_spinlock_t *lock)
  20. {
  21. lock->slock = 0;
  22. }
  23. static inline void
  24. __raw_spin_lock_flags(raw_spinlock_t *lock, unsigned long flags)
  25. {
  26. local_irq_save(flags);
  27. lock->slock = 0;
  28. }
  29. static inline int __raw_spin_trylock(raw_spinlock_t *lock)
  30. {
  31. char oldval = lock->slock;
  32. lock->slock = 0;
  33. return oldval > 0;
  34. }
  35. static inline void __raw_spin_unlock(raw_spinlock_t *lock)
  36. {
  37. lock->slock = 1;
  38. }
  39. /*
  40.  * Read-write spinlocks. No debug version.
  41.  */
  42. #define __raw_read_lock(lock) do { (void)(lock); } while (0)
  43. #define __raw_write_lock(lock) do { (void)(lock); } while (0)
  44. #define __raw_read_trylock(lock) ({ (void)(lock); 1; })
  45. #define __raw_write_trylock(lock) ({ (void)(lock); 1; })
  46. #define __raw_read_unlock(lock) do { (void)(lock); } while (0)
  47. #define __raw_write_unlock(lock) do { (void)(lock); } while (0)
  48. #else /* DEBUG_SPINLOCK */
  49. #define __raw_spin_is_locked(lock) ((void)(lock), 0)
  50. /* for sched.c and kernel_lock.c: */
  51. # define __raw_spin_lock(lock) do { (void)(lock); } while (0)
  52. # define __raw_spin_unlock(lock) do { (void)(lock); } while (0)
  53. # define __raw_spin_trylock(lock) ({ (void)(lock); 1; })
  54. #endif /* DEBUG_SPINLOCK */
  55. #define __raw_read_can_lock(lock) (((void)(lock), 1))
  56. #define __raw_write_can_lock(lock) (((void)(lock), 1))
  57. #define __raw_spin_unlock_wait(lock) 
  58. do { cpu_relax(); } while (__raw_spin_is_locked(lock))
  59. #endif /* __LINUX_SPINLOCK_UP_H */