Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

35 lines
656 B

  1. /* SPINLOCK.H -- This file is the include file for spinlocks
  2. **
  3. ** Created 04/20/93 by LaleD
  4. **
  5. */
  6. #ifdef DEBUG
  7. void free_spinlock(long *);
  8. #else
  9. #define free_spinlock(a) *(a) = 0 ;
  10. #endif
  11. /*
  12. ** When /Ogb1 or /Ogb2 flag is used in the compiler, this function will
  13. ** be expanded in line
  14. */
  15. __inline int get_spinlock(long VOLATILE *plock, int b)
  16. {
  17. # ifdef _X86_
  18. _asm // Use bit test and set instruction
  19. {
  20. mov eax, plock
  21. lock bts [eax], 0x0
  22. jc bsy // If already set go to busy, otherwise return TRUE
  23. } ;
  24. #else
  25. if (InterlockedExchange(plock, 1) == 0)
  26. #endif
  27. {
  28. return(TRUE);
  29. }
  30. bsy:
  31. return(get_spinlockfn(plock, b, c));
  32. }