Version

menu_open
Wwise SDK 2024.1.4
AkPlatformFuncs.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  Copyright (c) 2025 Audiokinetic Inc.
25 *******************************************************************************/
26 
27 // AkPlatformFuncs.h
28 
29 /// \file
30 /// Platform-dependent functions definition.
31 
32 #ifndef _AK_TOOLS_COMMON_AKPLATFORMFUNCS_H
33 #define _AK_TOOLS_COMMON_AKPLATFORMFUNCS_H
34 
37 
38 // Uncomment the following to enable built-in platform profiler markers in the sound engine
39 //#define AK_ENABLE_INSTRUMENT
40 
41 #if defined(AK_NULL_PLATFORM)
42 // null platform has no funcs
43 struct AkThreadProperties {};
44 #elif defined(AK_WIN)
46 
47 #elif defined (AK_XBOX)
49 
50 #elif defined (AK_APPLE)
52 #include <AK/Tools/POSIX/AkPlatformFuncs.h>
53 
54 #elif defined( AK_ANDROID ) || defined ( AK_LINUX_AOSP )
56 
57 #elif defined ( AK_HARMONY )
59 
60 #elif defined (AK_PS4)
62 
63 #elif defined (AK_PS5)
65 
66 #elif defined (AK_EMSCRIPTEN)
68 
69 #elif defined (AK_LINUX)
71 #include <AK/Tools/POSIX/AkPlatformFuncs.h>
72 
73 #elif defined (AK_QNX)
74 #include <AK/Tools/QNX/AkPlatformFuncs.h>
75 #include <AK/Tools/POSIX/AkPlatformFuncs.h>
76 
77 #elif defined (AK_NX)
79 
80 #else
81 #error AkPlatformFuncs.h: Undefined platform
82 #endif
83 
84 #ifndef AkPrefetchZero
85 #define AkPrefetchZero(___Dest, ___Size)
86 #endif
87 
88 #ifndef AkPrefetchZeroAligned
89 #define AkPrefetchZeroAligned(___Dest, ___Size)
90 #endif
91 
92 #ifndef AkZeroMemAligned
93 #define AkZeroMemAligned(___Dest, ___Size) AKPLATFORM::AkMemSet(___Dest, 0, ___Size);
94 #endif
95 #ifndef AkZeroMemLarge
96 #define AkZeroMemLarge(___Dest, ___Size) AKPLATFORM::AkMemSet(___Dest, 0, ___Size);
97 #endif
98 #ifndef AkZeroMemSmall
99 #define AkZeroMemSmall(___Dest, ___Size) AKPLATFORM::AkMemSet(___Dest, 0, ___Size);
100 #endif
101 
102 #ifndef AkAllocaSIMD
103 #if defined (__clang__)
104 #if __has_builtin( __builtin_alloca_with_align )
105 #define AkAllocaSIMD( _size_ ) __builtin_alloca_with_align( _size_, 128 )
106 #else
107 // work around alloca alignment issues in versions of clang before 4.0
108 #define AkAllocaSIMD( _size_ ) (void*)( ( ( uintptr_t )AkAlloca( _size_ + 16 ) + 0xF ) & ~0xF )
109 #endif
110 #else
111 #define AkAllocaSIMD( _size_ ) AkAlloca( _size_ )
112 #endif
113 #endif
114 
115 #ifndef AkAllocaTypedArray
116 #define AkAllocaTypedArray(_type_, _count_) ( (_type_*)AkAlloca(sizeof(_type_) * _count_) )
117 #endif
118 
119 #ifndef AK_THREAD_INIT_CODE
120 #define AK_THREAD_INIT_CODE(_threadProperties)
121 #endif
122 
123 #ifndef AK_PLATFORM_MEMCPY
124 namespace AKPLATFORM
125 {
126  /// Platform Independent Helper for memcpy/memmove/memset
127  AkForceInline void AkMemCpy(void* pDest, const void* pSrc, AkUInt32 uSize)
128  {
129  memcpy(pDest, pSrc, uSize);
130  }
131 
132  AkForceInline void AkMemMove(void* pDest, const void* pSrc, AkUInt32 uSize)
133  {
134  memmove(pDest, pSrc, uSize);
135  }
136 
137  AkForceInline void AkMemSet(void* pDest, AkInt32 iVal, AkUInt32 uSize)
138  {
139  memset(pDest, iVal, uSize);
140  }
141 }
142 #endif // AK_PLATFORM_MEMCPY
143 
144 #if !defined(AK_NULL_PLATFORM)
145 /// Platform-dependent helpers
146 namespace AKPLATFORM
147 {
149  {
150  AkGetDefaultThreadProperties(out_threadProperties);
151  out_threadProperties.nPriority = AK_THREAD_PRIORITY_ABOVE_NORMAL;
152  }
153 
154 }
155 #endif
156 
157 namespace AKPLATFORM
158 {
159  // to be used to unequivocally cause a crash for scenarios that are critical failures that we cannot hope to recover from
161  {
162  // We don't want to simply abort() the program; we want a real SIGSEGV happening on *this* thread
163  // This convoluted way of crashing is necessary to avoid compilers optimizing out invalid code
164  // By calling PerformanceCounter, which is inherently non-deterministic, the compiler must generate code as-is
165  AkInt64 one, two;
166  PerformanceCounter(&one);
167  PerformanceCounter(&two);
168  AkUIntPtr ptr = (AkUIntPtr)two - (AkUIntPtr)one;
169  ((void(*)())ptr)();
170  }
171 }
172 
173 #ifndef AK_FORCE_CRASH
174 #define AK_FORCE_CRASH AKPLATFORM::AkForceCrash()
175 #endif
176 
177 #endif // _AK_TOOLS_COMMON_AKPLATFORMFUNCS_H
AkForceInline void AkMemMove(void *pDest, const void *pSrc, AkUInt32 uSize)
int nPriority
Thread priority.
Platform-dependent helpers.
#define AK_THREAD_PRIORITY_ABOVE_NORMAL
int32_t AkInt32
Signed 32-bit integer.
uintptr_t AkUIntPtr
Integer (unsigned) type for pointers.
void PerformanceCounter(AkInt64 *out_piLastTime)
Platform Independent Helper.
AkForceInline void AkMemCpy(void *pDest, const void *pSrc, AkUInt32 uSize)
Platform Independent Helper for memcpy/memmove/memset.
AkForceInline void AkGetDefaultThreadProperties(AkThreadProperties &out_threadProperties)
Platform Independent Helper.
AkForceInline void AkForceCrash()
void AkGetDefaultHighPriorityThreadProperties(AkThreadProperties &out_threadProperties)
int64_t AkInt64
Signed 64-bit integer.
uint32_t AkUInt32
Unsigned 32-bit integer.
AkForceInline void AkMemSet(void *pDest, AkInt32 iVal, AkUInt32 uSize)
#define AkForceInline
Definition: AkTypes.h:63

Was this page helpful?

Need Support?

Questions? Problems? Need more info? Contact us, and we can help!

Visit our Support page

Tell us about your project. We're here to help.

Register your project and we'll help you get started with no strings attached!

Get started with Wwise