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.

52 lines
1.1 KiB

  1. // xlock.cpp -- global lock for locales, etc.
  2. #include <stdlib.h>
  3. #include <yvals.h>
  4. #if _MULTI_THREAD
  5. #include "xmtx.h"
  6. _STD_BEGIN
  7. #define MAX_LOCK 4 /* must be power of two */
  8. static _Rmtx mtx[MAX_LOCK];
  9. static long init = -1;
  10. _Init_locks::_Init_locks()
  11. { // initialize locks
  12. if (InterlockedIncrement(&init) == 0)
  13. for (int count = 0; count < MAX_LOCK; ++count)
  14. _Mtxinit(&mtx[count]);
  15. }
  16. _Init_locks::~_Init_locks()
  17. { // clean up locks
  18. if (InterlockedDecrement(&init) < 0)
  19. for (int count = 0; count < MAX_LOCK; ++count)
  20. _Mtxdst(&mtx[count]);
  21. }
  22. static _Init_locks initlocks;
  23. _Lockit::_Lockit()
  24. : _Locktype(0)
  25. { // lock default mutex
  26. _Mtxlock(&mtx[0]);
  27. }
  28. _Lockit::_Lockit(int kind)
  29. : _Locktype(kind & (MAX_LOCK - 1))
  30. { // lock the mutex
  31. _Mtxlock(&mtx[_Locktype]);
  32. }
  33. _Lockit::~_Lockit()
  34. { // unlock the mutex
  35. _Mtxunlock(&mtx[_Locktype]);
  36. }
  37. _STD_END
  38. #endif // _MULTI_THREAD
  39. /*
  40. * Copyright (c) 1992-2001 by P.J. Plauger. ALL RIGHTS RESERVED.
  41. * Consult your license regarding permissions and restrictions.
  42. V3.10:0009 */