rwlock.h 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /* include/asm-i386/rwlock.h
  2. *
  3. * Helpers used by both rw spinlocks and rw semaphores.
  4. *
  5. * Based in part on code from semaphore.h and
  6. * spinlock.h Copyright 1996 Linus Torvalds.
  7. *
  8. * Copyright 1999 Red Hat, Inc.
  9. *
  10. * Written by Benjamin LaHaise.
  11. *
  12. * This program is free software; you can redistribute it and/or
  13. * modify it under the terms of the GNU General Public License
  14. * as published by the Free Software Foundation; either version
  15. * 2 of the License, or (at your option) any later version.
  16. */
  17. #ifndef _ASM_I386_RWLOCK_H
  18. #define _ASM_I386_RWLOCK_H
  19. #define RW_LOCK_BIAS 0x01000000
  20. #define RW_LOCK_BIAS_STR "0x01000000"
  21. #define __build_read_lock_ptr(rw, helper) \
  22. asm volatile(LOCK "subl $1,(%0)\n\t" \
  23. "jns 1f\n" \
  24. "call " helper "\n\t" \
  25. "1:\n" \
  26. ::"a" (rw) : "memory")
  27. #define __build_read_lock_const(rw, helper) \
  28. asm volatile(LOCK "subl $1,%0\n\t" \
  29. "jns 1f\n" \
  30. "pushl %%eax\n\t" \
  31. "leal %0,%%eax\n\t" \
  32. "call " helper "\n\t" \
  33. "popl %%eax\n\t" \
  34. "1:\n" \
  35. :"=m" (*(volatile int *)rw) : : "memory")
  36. #define __build_read_lock(rw, helper) do { \
  37. if (__builtin_constant_p(rw)) \
  38. __build_read_lock_const(rw, helper); \
  39. else \
  40. __build_read_lock_ptr(rw, helper); \
  41. } while (0)
  42. #define __build_write_lock_ptr(rw, helper) \
  43. asm volatile(LOCK "subl $" RW_LOCK_BIAS_STR ",(%0)\n\t" \
  44. "jz 1f\n" \
  45. "call " helper "\n\t" \
  46. "1:\n" \
  47. ::"a" (rw) : "memory")
  48. #define __build_write_lock_const(rw, helper) \
  49. asm volatile(LOCK "subl $" RW_LOCK_BIAS_STR ",%0\n\t" \
  50. "jz 1f\n" \
  51. "pushl %%eax\n\t" \
  52. "leal %0,%%eax\n\t" \
  53. "call " helper "\n\t" \
  54. "popl %%eax\n\t" \
  55. "1:\n" \
  56. :"=m" (*(volatile int *)rw) : : "memory")
  57. #define __build_write_lock(rw, helper) do { \
  58. if (__builtin_constant_p(rw)) \
  59. __build_write_lock_const(rw, helper); \
  60. else \
  61. __build_write_lock_ptr(rw, helper); \
  62. } while (0)
  63. #endif