Mutex.inc 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. C_ASSERT(sizeof(data_) == sizeof(CRITICAL_SECTION));
  24. // data_ = new CRITICAL_SECTION; // HLSL Change
  25. InitializeCriticalSection((LPCRITICAL_SECTION)data_);
  26. }
  27. MutexImpl::~MutexImpl()
  28. {
  29. DeleteCriticalSection((LPCRITICAL_SECTION)data_);
  30. // delete (LPCRITICAL_SECTION)data_; // HLSL Change
  31. // data_ = 0; // HLSL Change
  32. }
  33. bool
  34. MutexImpl::acquire()
  35. {
  36. EnterCriticalSection((LPCRITICAL_SECTION)data_);
  37. return true;
  38. }
  39. bool
  40. MutexImpl::release()
  41. {
  42. LeaveCriticalSection((LPCRITICAL_SECTION)data_);
  43. return true;
  44. }
  45. bool
  46. MutexImpl::tryacquire()
  47. {
  48. return TryEnterCriticalSection((LPCRITICAL_SECTION)data_);
  49. }
  50. }