LocklessTypes.h 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /*
  2. * Copyright (c) 2014, Oculus VR, Inc.
  3. * All rights reserved.
  4. *
  5. * This source code is licensed under the BSD-style license found in the
  6. * LICENSE file in the root directory of this source tree. An additional grant
  7. * of patent rights can be found in the PATENTS file in the same directory.
  8. *
  9. */
  10. #ifndef __LOCKLESS_TYPES_H
  11. #define __LOCKLESS_TYPES_H
  12. #include "Export.h"
  13. #include "NativeTypes.h"
  14. #include "WindowsIncludes.h"
  15. #if defined(ANDROID) || defined(__S3E__) || defined(__APPLE__)
  16. // __sync_fetch_and_add not supported apparently
  17. #include "SimpleMutex.h"
  18. #endif
  19. namespace RakNet
  20. {
  21. class RAK_DLL_EXPORT LocklessUint32_t
  22. {
  23. public:
  24. LocklessUint32_t();
  25. explicit LocklessUint32_t(uint32_t initial);
  26. // Returns variable value after changing it
  27. uint32_t Increment(void);
  28. // Returns variable value after changing it
  29. uint32_t Decrement(void);
  30. uint32_t GetValue(void) const {return value;}
  31. protected:
  32. #ifdef _WIN32
  33. volatile LONG value;
  34. #elif defined(ANDROID) || defined(__S3E__) || defined(__APPLE__)
  35. // __sync_fetch_and_add not supported apparently
  36. SimpleMutex mutex;
  37. uint32_t value;
  38. #else
  39. volatile uint32_t value;
  40. #endif
  41. };
  42. }
  43. #endif
粤ICP备19079148号