Mutex.inc 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. //===- llvm/Support/Win32/Mutex.inc - Win32 Mutex Implementation -*- C++ -*-===//
  2. //
  3. // The LLVM Compiler Infrastructure
  4. //
  5. // This file is distributed under the University of Illinois Open Source
  6. // License. See LICENSE.TXT for details.
  7. //
  8. //===----------------------------------------------------------------------===//
  9. //
  10. // This file implements the Win32 specific (non-pthread) Mutex class.
  11. //
  12. //===----------------------------------------------------------------------===//
  13. //===----------------------------------------------------------------------===//
  14. //=== WARNING: Implementation here must contain only generic Win32 code that
  15. //=== is guaranteed to work on *all* Win32 variants.
  16. //===----------------------------------------------------------------------===//
  17. #include "WindowsSupport.h"
  18. #include "llvm/Support/Mutex.h"
  19. namespace llvm {
  20. using namespace sys;
  21. MutexImpl::MutexImpl(bool /*recursive*/)
  22. {
  23. data_ = new CRITICAL_SECTION;
  24. InitializeCriticalSection((LPCRITICAL_SECTION)data_);
  25. }
  26. MutexImpl::~MutexImpl()
  27. {
  28. DeleteCriticalSection((LPCRITICAL_SECTION)data_);
  29. delete (LPCRITICAL_SECTION)data_;
  30. data_ = 0;
  31. }
  32. bool
  33. MutexImpl::acquire()
  34. {
  35. EnterCriticalSection((LPCRITICAL_SECTION)data_);
  36. return true;
  37. }
  38. bool
  39. MutexImpl::release()
  40. {
  41. LeaveCriticalSection((LPCRITICAL_SECTION)data_);
  42. return true;
  43. }
  44. bool
  45. MutexImpl::tryacquire()
  46. {
  47. return TryEnterCriticalSection((LPCRITICAL_SECTION)data_);
  48. }
  49. }