Table of Contents

Target Platform(s):
Wwise SDK 2019.2.11
AkAtomic.h
Go to the documentation of this file.
1 /*******************************************************************************
2 The content of this file includes portions of the AUDIOKINETIC Wwise Technology
3 released in source code form as part of the SDK installer package.
4 
5 Commercial License Usage
6 
7 Licensees holding valid commercial licenses to the AUDIOKINETIC Wwise Technology
8 may use this file in accordance with the end user license agreement provided
9 with the software or, alternatively, in accordance with the terms contained in a
10 written agreement between you and Audiokinetic Inc.
11 
12 Apache License Usage
13 
14 Alternatively, this file may be used under the Apache License, Version 2.0 (the
15 "Apache License"); you may not use this file except in compliance with the
16 Apache License. You may obtain a copy of the Apache License at
17 http://www.apache.org/licenses/LICENSE-2.0.
18 
19 Unless required by applicable law or agreed to in writing, software distributed
20 under the Apache License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES
21 OR CONDITIONS OF ANY KIND, either express or implied. See the Apache License for
22 the specific language governing permissions and limitations under the License.
23 
24 Version: <VERSION> Build: <BUILDNUMBER>
25 Copyright (c) <COPYRIGHTYEAR> Audiokinetic Inc.
26 *******************************************************************************/
27 
28 // AkAtomic.h
29 
30 #pragma once
31 
32 #ifdef __cplusplus
33 extern "C" {
34 #endif
35 
36 typedef volatile int32_t AkAtomic32;
37 typedef volatile int64_t AkAtomic64;
38 typedef volatile void* AkAtomicPtr;
39 
40 #define AK_ATOMIC_FENCE_FULL_BARRIER() __sync_synchronize();
41 
42 static inline int32_t AkAtomicLoad32( AkAtomic32* pSrc ) { int32_t ret; __atomic_load( ( int32_t* )pSrc, &ret, __ATOMIC_ACQUIRE ); return ret; }
43 static inline void AkAtomicStore32( AkAtomic32* pDest, int32_t value ) { __atomic_store( ( int32_t* )pDest, &value, __ATOMIC_RELEASE ); }
44 static inline int32_t AkAtomicInc32( AkAtomic32* pValue ) { return __sync_add_and_fetch( ( int32_t* )pValue, 1 ); }
45 static inline int32_t AkAtomicDec32( AkAtomic32* pValue ) { return __sync_sub_and_fetch( ( int32_t* )pValue, 1 ); }
46 static inline int32_t AkAtomicExchange32( AkAtomic32* pDest, int32_t value ) { return __sync_lock_test_and_set( ( int32_t* )pDest, value ); }
47 static inline int32_t AkAtomicAdd32( AkAtomic32* pDest, int32_t value ) { return __sync_add_and_fetch( ( int32_t* )pDest, value ); }
48 static inline int32_t AkAtomicSub32( AkAtomic32* pDest, int32_t value ) { return __sync_sub_and_fetch( ( int32_t* )pDest, value ); }
49 static inline int AkAtomicCas32( AkAtomic32* pDest, int32_t proposed, int32_t expected ) { return __sync_bool_compare_and_swap( ( int32_t* )pDest, expected, proposed ); }
50 
51 #if defined( __i386 ) || ( defined( __ARM_ARCH ) && ( __ARM_ARCH <= 7 ) )
52 static inline int64_t AkAtomicLoad64( AkAtomic64* pSrc ) { return __sync_val_compare_and_swap( pSrc, 0, 0 ); }
53 static inline void AkAtomicStore64( AkAtomic64* pDest, int64_t value ) { int64_t tmp; do { tmp = *pDest; } while( __sync_val_compare_and_swap( pDest, tmp, value ) != tmp ); }
54 #else
55 static inline int64_t AkAtomicLoad64( AkAtomic64* pSrc ) { int64_t ret; __atomic_load( ( int64_t* )pSrc, &ret, __ATOMIC_ACQUIRE ); return ret; }
56 static inline void AkAtomicStore64( AkAtomic64* pDest, int64_t value ) { __atomic_store( ( int64_t* )pDest, &value, __ATOMIC_RELEASE ); }
57 #endif
58 
59 static inline int64_t AkAtomicInc64( AkAtomic64* pValue ) { return __sync_add_and_fetch( ( int64_t* )pValue, 1 ); }
60 static inline int64_t AkAtomicDec64( AkAtomic64* pValue ) { return __sync_sub_and_fetch( ( int64_t* )pValue, 1 ); }
61 static inline int64_t AkAtomicExchange64( AkAtomic64* pDest, int64_t value ) { return __sync_lock_test_and_set( ( int64_t* )pDest, value ); }
62 static inline int64_t AkAtomicAdd64( AkAtomic64* pDest, int64_t value ) { return __sync_add_and_fetch( ( int64_t* )pDest, value ); }
63 static inline int64_t AkAtomicSub64( AkAtomic64* pDest, int64_t value ) { return __sync_sub_and_fetch( ( int64_t* )pDest, value ); }
64 static inline int AkAtomicCas64( AkAtomic64* pDest, int64_t proposed, int64_t expected ) { return __sync_bool_compare_and_swap( ( int64_t* )pDest, expected, proposed ); }
65 
66 static inline void* AkAtomicLoadPtr( AkAtomicPtr* pSrc ) { size_t ret; __atomic_load( ( size_t* )pSrc, &ret, __ATOMIC_ACQUIRE ); return ( void* )ret; }
67 static inline void AkAtomicStorePtr( AkAtomicPtr* pDest, void* value ) { __atomic_store( ( size_t* )pDest, ( size_t* )&value, __ATOMIC_RELEASE ); }
68 static inline void* AkAtomicExchangePtr( AkAtomicPtr* pDest, void* value ) { return ( void* )__sync_lock_test_and_set( ( void** )pDest, value ); }
69 static inline int AkAtomicCasPtr( AkAtomicPtr* pDest, void* proposed, void* expected ) { return __sync_bool_compare_and_swap( ( void** )pDest, expected, proposed ); }
70 
71 #ifdef __cplusplus
72 }
73 #endif
__forceinline long AkAtomicAdd32(AkAtomic32 *pDest, long value)
Definition: AkAtomic.h:59
volatile void * AkAtomicPtr
Definition: AkAtomic.h:40
__forceinline int AkAtomicCas64(AkAtomic64 *pDest, long long proposed, long long expected)
Definition: AkAtomic.h:81
__forceinline void * AkAtomicExchangePtr(AkAtomicPtr *pDest, void *value)
Definition: AkAtomic.h:95
__forceinline void AkAtomicStore64(AkAtomic64 *pDest, long long value)
Definition: AkAtomic.h:73
__forceinline int AkAtomicCas32(AkAtomic32 *pDest, long proposed, long expected)
Definition: AkAtomic.h:61
__forceinline long long AkAtomicDec64(AkAtomic64 *pValue)
Definition: AkAtomic.h:77
__forceinline void AkAtomicStorePtr(AkAtomicPtr *pDest, void *value)
Definition: AkAtomic.h:88
__forceinline long AkAtomicDec32(AkAtomic32 *pValue)
Definition: AkAtomic.h:57
__forceinline void AkAtomicStore32(AkAtomic32 *pDest, long value)
Definition: AkAtomic.h:53
__forceinline long long AkAtomicSub64(AkAtomic64 *pDest, long long value)
Definition: AkAtomic.h:80
__forceinline long long AkAtomicExchange64(AkAtomic64 *pDest, long long value)
Definition: AkAtomic.h:78
volatile long long AkAtomic64
Definition: AkAtomic.h:39
__forceinline long AkAtomicInc32(AkAtomic32 *pValue)
Definition: AkAtomic.h:56
__forceinline long long AkAtomicLoad64(AkAtomic64 *pSrc)
Definition: AkAtomic.h:72
__forceinline long long AkAtomicAdd64(AkAtomic64 *pDest, long long value)
Definition: AkAtomic.h:79
__forceinline long long AkAtomicInc64(AkAtomic64 *pValue)
Definition: AkAtomic.h:76
volatile long AkAtomic32
Definition: AkAtomic.h:38
__forceinline long AkAtomicSub32(AkAtomic32 *pDest, long value)
Definition: AkAtomic.h:60
__forceinline void * AkAtomicLoadPtr(AkAtomicPtr *pSrc)
Definition: AkAtomic.h:87
__forceinline long AkAtomicExchange32(AkAtomic32 *pDest, long value)
Definition: AkAtomic.h:58
__forceinline long AkAtomicLoad32(AkAtomic32 *pSrc)
Definition: AkAtomic.h:52
__forceinline int AkAtomicCasPtr(AkAtomicPtr *pDest, void *proposed, void *expected)
Definition: AkAtomic.h:96