cclock.hpp 1.1 KB

123456789101112131415161718192021222324252627282930313233
  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. class CCLock
  11. {
  12. __declspec(align(sizeof(size_t)))
  13. char mutexPtr[64]; // keep mutex implementation opaque to consumer (PAL vs non-PAL)
  14. public:
  15. void Reset(bool shouldTrackThreadId = false);
  16. CCLock(bool shouldTrackThreadId = false)
  17. {
  18. *((size_t*)mutexPtr) = 0;
  19. Reset(shouldTrackThreadId);
  20. }
  21. ~CCLock();
  22. void Enter();
  23. bool TryEnter();
  24. void Leave();
  25. bool IsLocked() const;
  26. };
  27. #endif // CC_PAL_INC_CCLOCK_H