rwlock.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. alternative_smp("lock; subl $1,(%0)\n\t" \
  23. "jns 1f\n" \
  24. "call " helper "\n\t" \
  25. "1:\n", \
  26. "subl $1,(%0)\n\t", \
  27. :"a" (rw) : "memory")
  28. #define __build_read_lock_const(rw, helper) \
  29. alternative_smp("lock; subl $1,%0\n\t" \
  30. "jns 1f\n" \
  31. "pushl %%eax\n\t" \
  32. "leal %0,%%eax\n\t" \
  33. "call " helper "\n\t" \
  34. "popl %%eax\n\t" \
  35. "1:\n", \
  36. "subl $1,%0\n\t", \
  37. "=m" (*(volatile int *)rw) : : "memory")
  38. #define __build_read_lock(rw, helper) do { \
  39. if (__builtin_constant_p(rw)) \
  40. __build_read_lock_const(rw, helper); \
  41. else \
  42. __build_read_lock_ptr(rw, helper); \
  43. } while (0)
  44. #define __build_write_lock_ptr(rw, helper) \
  45. alternative_smp("lock; subl $" RW_LOCK_BIAS_STR ",(%0)\n\t" \
  46. "jz 1f\n" \
  47. "call " helper "\n\t" \
  48. "1:\n", \
  49. "subl $" RW_LOCK_BIAS_STR ",(%0)\n\t", \
  50. :"a" (rw) : "memory")
  51. #define __build_write_lock_const(rw, helper) \
  52. alternative_smp("lock; subl $" RW_LOCK_BIAS_STR ",%0\n\t" \
  53. "jz 1f\n" \
  54. "pushl %%eax\n\t" \
  55. "leal %0,%%eax\n\t" \
  56. "call " helper "\n\t" \
  57. "popl %%eax\n\t" \
  58. "1:\n", \
  59. "subl $" RW_LOCK_BIAS_STR ",%0\n\t", \
  60. "=m" (*(volatile int *)rw) : : "memory")
  61. #define __build_write_lock(rw, helper) do { \
  62. if (__builtin_constant_p(rw)) \
  63. __build_write_lock_const(rw, helper); \
  64. else \
  65. __build_write_lock_ptr(rw, helper); \
  66. } while (0)
  67. #endif