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

Linux/Unix编程

开发平台:

Unix_Linux

  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)nt" 
  23.      "js 2fn" 
  24.      "1:n" 
  25.      LOCK_SECTION_START("") 
  26.      "2:tcall " helper "nt" 
  27.      "jmp 1bn" 
  28.      LOCK_SECTION_END 
  29.      ::"a" (rw) : "memory")
  30. #define __build_read_lock_const(rw, helper)   
  31. asm volatile(LOCK "subl $1,%0nt" 
  32.      "js 2fn" 
  33.      "1:n" 
  34.      LOCK_SECTION_START("") 
  35.      "2:tpushl %%eaxnt" 
  36.      "leal %0,%%eaxnt" 
  37.      "call " helper "nt" 
  38.      "popl %%eaxnt" 
  39.      "jmp 1bn" 
  40.      LOCK_SECTION_END 
  41.      :"=m" (*(volatile int *)rw) : : "memory")
  42. #define __build_read_lock(rw, helper) do { 
  43. if (__builtin_constant_p(rw)) 
  44. __build_read_lock_const(rw, helper); 
  45. else 
  46. __build_read_lock_ptr(rw, helper); 
  47. } while (0)
  48. #define __build_write_lock_ptr(rw, helper) 
  49. asm volatile(LOCK "subl $" RW_LOCK_BIAS_STR ",(%0)nt" 
  50.      "jnz 2fn" 
  51.      "1:n" 
  52.      LOCK_SECTION_START("") 
  53.      "2:tcall " helper "nt" 
  54.      "jmp 1bn" 
  55.      LOCK_SECTION_END 
  56.      ::"a" (rw) : "memory")
  57. #define __build_write_lock_const(rw, helper) 
  58. asm volatile(LOCK "subl $" RW_LOCK_BIAS_STR ",(%0)nt" 
  59.      "jnz 2fn" 
  60.      "1:n" 
  61.      LOCK_SECTION_START("") 
  62.      "2:tpushl %%eaxnt" 
  63.      "leal %0,%%eaxnt" 
  64.      "call " helper "nt" 
  65.      "popl %%eaxnt" 
  66.      "jmp 1bn" 
  67.      LOCK_SECTION_END 
  68.      :"=m" (*(volatile int *)rw) : : "memory")
  69. #define __build_write_lock(rw, helper) do { 
  70. if (__builtin_constant_p(rw)) 
  71. __build_write_lock_const(rw, helper); 
  72. else 
  73. __build_write_lock_ptr(rw, helper); 
  74. } while (0)
  75. #endif