SLikeNet 0.1.3

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
LocklessTypes.h
Go to the documentation of this file.
1 /*
2 * Original work: 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 * RakNet License.txt file in the licenses directory of this source tree. An additional grant
7 * of patent rights can be found in the RakNet Patents.txt file in the same directory.
8 *
9 *
10 * Modified work: Copyright (c) 2017, SLikeSoft UG (haftungsbeschränkt)
11 *
12 * This source code was modified by SLikeSoft. Modifications are licensed under the MIT-style
13 * license found in the license.txt file in the root directory of this source tree.
14 */
15
16 #ifndef __LOCKLESS_TYPES_H
17 #define __LOCKLESS_TYPES_H
18
19 #include "Export.h"
20 #include "NativeTypes.h"
21 #include "WindowsIncludes.h"
22 #if defined(ANDROID) || defined(__S3E__) || defined(__APPLE__)
23 // __sync_fetch_and_add not supported apparently
24 #include "SimpleMutex.h"
25 #endif
26
27 namespace SLNet
28 {
29
30 class RAK_DLL_EXPORT LocklessUint32_t
31 {
32 public:
33 LocklessUint32_t();
34 explicit LocklessUint32_t(uint32_t initial);
35 // Returns variable value after changing it
36 uint32_t Increment(void);
37 // Returns variable value after changing it
38 uint32_t Decrement(void);
39 uint32_t GetValue(void) const {return value;}
40
41 protected:
42 #ifdef _WIN32
43 volatile LONG value;
44 #elif defined(ANDROID) || defined(__S3E__) || defined(__APPLE__)
45 // __sync_fetch_and_add not supported apparently
46 SimpleMutex mutex;
47 uint32_t value;
48 #else
49 volatile uint32_t value;
50 #endif
51 };
52
53 }
54
55 #endif