Is there any simple way to improve performance of this spinlock function?

久未见 提交于 2019-12-03 21:02:06

How about something like this (I understand this is the KeAcquireSpinLock implementation). My at&t assembly is weak unfortunately.

spin_lock:
    rep; nop
    test lockValue, 1
    jnz spin_lock
    lock bts lockValue
    jc spin_lock
  "movl    $1,%%edx     \n\t"    // edx = 1;
  ".set    lockloop,.   \n\t"    // symbol lockloop set to pc
  "xorl    %%eax,%%eax  \n\t"    // eax = 0;
  "lock cmpxchgl %%edx,(%%ebx)\n\t" // if (*mu_ptr == eax) *mu_ptr = edx;
                                 //    else { eax = *mu_ptr;
  "jnz     lockloop     \n\t"    //           goto lockloop; }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!