rwlock.S
上传用户:jlfgdled
上传日期:2013-04-10
资源大小:33168k
文件大小:1k
源码类别:

Linux/Unix编程

开发平台:

Unix_Linux

  1. /* $Id: rwlock.S,v 1.4 2000/09/09 00:00:34 davem Exp $
  2.  * rwlocks.S: These things are too big to do inline.
  3.  *
  4.  * Copyright (C) 1999 David S. Miller (davem@redhat.com)
  5.  */
  6. .text
  7. .align 64
  8. .globl rwlock_impl_begin, rwlock_impl_end
  9. /* The non-contention read lock usage is 2 cache lines. */
  10. .globl __read_lock, __read_unlock
  11. rwlock_impl_begin:
  12. __read_lock: /* %o0 = lock_ptr */
  13. ldsw [%o0], %g5
  14. brlz,pn %g5, __read_wait_for_writer
  15. 4:  add %g5, 1, %g7
  16. cas [%o0], %g5, %g7
  17. cmp %g5, %g7
  18. bne,pn %icc, __read_lock
  19.  membar #StoreLoad | #StoreStore
  20. 99: retl
  21.  nop
  22. __read_unlock: /* %o0 = lock_ptr */
  23. lduw [%o0], %g5
  24. sub %g5, 1, %g7
  25. cas [%o0], %g5, %g7
  26. cmp %g5, %g7
  27. be,pt %xcc, 99b
  28.  membar #StoreLoad | #StoreStore
  29. ba,a,pt %xcc, __read_unlock
  30. __read_wait_for_writer:
  31. ldsw [%o0], %g5
  32. brlz,pt %g5, __read_wait_for_writer
  33.  membar #LoadLoad
  34. ba,a,pt %xcc, 4b
  35. __write_wait_for_any:
  36. lduw [%o0], %g5
  37. brnz,pt %g5, __write_wait_for_any
  38.  membar #LoadLoad
  39. ba,a,pt %xcc, 4f
  40. .align 64
  41. .globl __write_unlock
  42. __write_unlock: /* %o0 = lock_ptr */
  43. membar #LoadStore | #StoreStore
  44. retl
  45.  stw %g0, [%o0]
  46. .globl __write_lock
  47. __write_lock: /* %o0 = lock_ptr */
  48. sethi %hi(0x80000000), %g2
  49. 1: lduw [%o0], %g5
  50. brnz,pn %g5, __write_wait_for_any
  51. 4:  or %g5, %g2, %g7
  52. cas [%o0], %g5, %g7
  53. cmp %g5, %g7
  54. be,pt %icc, 99b
  55.  membar #StoreLoad | #StoreStore
  56. ba,a,pt %xcc, 1b
  57. rwlock_impl_end: