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.cpp
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 #include "slikenet/LocklessTypes.h"
17
18 using namespace SLNet;
19
20 LocklessUint32_t::LocklessUint32_t()
21 {
22 value=0;
23 }
24 LocklessUint32_t::LocklessUint32_t(uint32_t initial)
25 {
26 value=initial;
27 }
28 uint32_t LocklessUint32_t::Increment(void)
29 {
30 #ifdef _WIN32
31 return (uint32_t) InterlockedIncrement(&value);
32 #elif defined(ANDROID) || defined(__S3E__) || defined(__APPLE__)
33 uint32_t v;
34 mutex.Lock();
35 ++value;
36 v=value;
37 mutex.Unlock();
38 return v;
39 #else
40 return __sync_fetch_and_add (&value, (uint32_t) 1);
41 #endif
42 }
43 uint32_t LocklessUint32_t::Decrement(void)
44 {
45 #ifdef _WIN32
46 return (uint32_t) InterlockedDecrement(&value);
47 #elif defined(ANDROID) || defined(__S3E__) || defined(__APPLE__)
48 uint32_t v;
49 mutex.Lock();
50 --value;
51 v=value;
52 mutex.Unlock();
53 return v;
54 #else
55 return __sync_fetch_and_add (&value, (uint32_t) -1);
56 #endif
57 }