BTS 指令,一般用在自旋锁上或者类似概念。自旋锁核心操作就是InterlockedBitTestAndSet。

InterlockedBitTestAndSet有两种实现:

1. ReactOS方法

static __inline__ BOOLEAN 
InterlockedBitTestAndSet(IN LONG volatile *Base, 
                         IN LONG Bit) 
{ 
LONG OldBit;

__asm__ __volatile__("lock "                          // 总线加锁  
                      "btsl %2,%1/n/t" 
                      "sbbl %0,%0/n/t" 
               :"=r" (OldBit),"=m" (*Base) 
               :"Ir" (Bit) 
        : "memory"); 
return OldBit; 
}

2. Windows方法

         BOOLEAN bRet = InterlockedBitTestAndSet(&num,3);
0042F9D5  lea         eax,[num]
0042F9D8  lock bts    dword ptr [eax],3
0042F9DD  setb        cl  
0042F9E0  mov         byte ptr [bRet],cl

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-10-05
  • 2022-02-25
  • 2021-12-19
  • 2021-04-27
  • 2021-10-19
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-08-26
  • 2022-12-23
  • 2021-09-08
  • 2021-10-09
  • 2022-12-23
  • 2021-10-18
相关资源
相似解决方案