cclock.hpp 859 B

1234567891011121314151617181920212223242526272829
  1. //-------------------------------------------------------------------------------------------------------
  2. // Copyright (C) Microsoft. All rights reserved.
  3. // Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
  4. //-------------------------------------------------------------------------------------------------------
  5. #ifndef CC_PAL_INC_CCLOCK_H
  6. #define CC_PAL_INC_CCLOCK_H
  7. class CCLock
  8. {
  9. char mutexPtr[64]; // keep mutex implementation opaque to consumer (PAL vs non-PAL)
  10. public:
  11. void Reset(bool shouldTrackThreadId = false);
  12. CCLock(bool shouldTrackThreadId = false)
  13. {
  14. *((size_t*)mutexPtr) = 0;
  15. Reset(shouldTrackThreadId);
  16. }
  17. ~CCLock();
  18. void Enter();
  19. bool TryEnter();
  20. void Leave();
  21. bool IsLocked() const;
  22. };
  23. #endif // CC_PAL_INC_CCLOCK_H