cclock.hpp 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. //-------------------------------------------------------------------------------------------------------
  2. // ChakraCore/Pal
  3. // Contains portions (c) copyright Microsoft, portions copyright (c) the .NET Foundation and Contributors
  4. // and edits (c) copyright the ChakraCore Contributors.
  5. // See THIRD-PARTY-NOTICES.txt in the project root for .NET Foundation license
  6. // Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
  7. //-------------------------------------------------------------------------------------------------------
  8. #ifndef CC_PAL_INC_CCLOCK_H
  9. #define CC_PAL_INC_CCLOCK_H
  10. #if defined(_M_ARM64)
  11. #define CCLOCK_ALIGN __declspec(align(8))
  12. #else
  13. #define CCLOCK_ALIGN
  14. #endif
  15. class CCLOCK_ALIGN CCLock
  16. {
  17. char mutexPtr[64]; // keep mutex implementation opaque to consumer (PAL vs non-PAL)
  18. public:
  19. void Reset(bool shouldTrackThreadId = false);
  20. CCLock(bool shouldTrackThreadId = false)
  21. {
  22. *((size_t*)mutexPtr) = 0;
  23. Reset(shouldTrackThreadId);
  24. }
  25. ~CCLock();
  26. void Enter();
  27. bool TryEnter();
  28. void Leave();
  29. bool IsLocked() const;
  30. };
  31. #endif // CC_PAL_INC_CCLOCK_H