在 ASMx86(x86 架构)程序集上搜索一些 test&set 和 test&test&set LOCK 实现以用于我的 C 代码。我不想要 C 中的实现,而是简单的汇编。
请给我指出一些有用的。
提前致谢!
最佳答案
你有一个在 IA32 x86 下测试和设置的简单实现吗
//eax = pointer on 32 bit lock variable
//Variable must be 4 byte aligned
//edx = bit test and set number from 0..31
lock bts dword ptr [eax], edx
setnc al //al is 1 if bts instruction was successful
你有一个循环测试和设置的简单实现吗
//eax = pointer on 32 bit lock variable
//Variable must be 4 byte aligned
//edx = bit test and set number from 0..31
@wait:
pause //CPU hint for waiting in loop
lock bts dword ptr [eax], edx
jc @wait //waiting in loop!!!
请记住,在循环中等待会卡住应用程序线程,因此设置最大等待循环时间也是明智的做法。
关于c - ASM for C 中的 test&set 和 test&test&set LOCK 实现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4209636/