Leaked source code of windows server 2003
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.

51 lines
1.1 KiB

  1. /* xmtx.c -- mutex support for VC++ */
  2. #include "xmtx.h"
  3. #if !_MULTI_THREAD
  4. #else /* !_MULTI_THREAD */
  5. /* Win32 critical sections are recursive, but
  6. Win32 does not have once-function */
  7. void _Once(_Once_t *_Cntrl, void (*_Func)(void))
  8. { /* execute _Func exactly one time */
  9. _Once_t old;
  10. if (*_Cntrl == 2)
  11. ;
  12. else if ((old = InterlockedExchange(_Cntrl, 1)) == 0)
  13. { /* execute _Func, mark as executed */
  14. _Func();
  15. *_Cntrl = 2;
  16. }
  17. else if (old == 2)
  18. *_Cntrl = 2;
  19. else
  20. while (*_Cntrl != 2)
  21. Sleep(1);
  22. }
  23. void _Mtxinit(_Rmtx *_Mtx)
  24. { /* initialize mutex */
  25. InitializeCriticalSection(_Mtx);
  26. }
  27. void _Mtxdst(_Rmtx *_Mtx)
  28. { /* delete mutex */
  29. DeleteCriticalSection(_Mtx);
  30. }
  31. void _Mtxlock(_Rmtx *_Mtx)
  32. { /* lock mutex */
  33. EnterCriticalSection(_Mtx);
  34. }
  35. void _Mtxunlock(_Rmtx *_Mtx)
  36. { /* unlock mutex */
  37. LeaveCriticalSection(_Mtx);
  38. }
  39. #endif /* !_MULTI_THREAD */
  40. /*
  41. * Copyright (c) 1992-2001 by P.J. Plauger. ALL RIGHTS RESERVED.
  42. * Consult your license regarding permissions and restrictions.
  43. V3.10:0009 */