Version

menu_open
Wwise SDK 2024.1.5
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 #elif defined (AK_OUNCE)
82 
83 #else
84 #error AkPlatformFuncs.h: Undefined platform
85 #endif
86 
87 #ifndef AkPrefetchZero
88 #define AkPrefetchZero(___Dest, ___Size)
89 #endif
90 
91 #ifndef AkPrefetchZeroAligned
92 #define AkPrefetchZeroAligned(___Dest, ___Size)
93 #endif
94 
95 #ifndef AkZeroMemAligned
96 #define AkZeroMemAligned(___Dest, ___Size) AKPLATFORM::AkMemSet(___Dest, 0, ___Size);
97 #endif
98 #ifndef AkZeroMemLarge
99 #define AkZeroMemLarge(___Dest, ___Size) AKPLATFORM::AkMemSet(___Dest, 0, ___Size);
100 #endif
101 #ifndef AkZeroMemSmall
102 #define AkZeroMemSmall(___Dest, ___Size) AKPLATFORM::AkMemSet(___Dest, 0, ___Size);
103 #endif
104 
105 #ifndef AkAllocaSIMD
106 #if defined (__clang__)
107 #if __has_builtin( __builtin_alloca_with_align )
108 #define AkAllocaSIMD( _size_ ) __builtin_alloca_with_align( _size_, 128 )
109 #else
110 // work around alloca alignment issues in versions of clang before 4.0
111 #define AkAllocaSIMD( _size_ ) (void*)( ( ( uintptr_t )AkAlloca( _size_ + 16 ) + 0xF ) & ~0xF )
112 #endif
113 #else
114 #define AkAllocaSIMD( _size_ ) AkAlloca( _size_ )
115 #endif
116 #endif
117 
118 #ifndef AkAllocaTypedArray
119 #define AkAllocaTypedArray(_type_, _count_) ( (_type_*)AkAlloca(sizeof(_type_) * _count_) )
120 #endif
121 
122 #ifndef AK_THREAD_INIT_CODE
123 #define AK_THREAD_INIT_CODE(_threadProperties)
124 #endif
125 
126 #ifndef AK_PLATFORM_MEMCPY
127 namespace AKPLATFORM
128 {
129  /// Platform Independent Helper for memcpy/memmove/memset
130  AkForceInline void AkMemCpy(void* pDest, const void* pSrc, AkUInt32 uSize)
131  {
132  memcpy(pDest, pSrc, uSize);
133  }
134 
135  AkForceInline void AkMemMove(void* pDest, const void* pSrc, AkUInt32 uSize)
136  {
137  memmove(pDest, pSrc, uSize);
138  }
139 
140  AkForceInline void AkMemSet(void* pDest, AkInt32 iVal, AkUInt32 uSize)
141  {
142  memset(pDest, iVal, uSize);
143  }
144 }
145 #endif // AK_PLATFORM_MEMCPY
146 
147 #if !defined(AK_NULL_PLATFORM)
148 /// Platform-dependent helpers
149 namespace AKPLATFORM
150 {
152  {
153  AkGetDefaultThreadProperties(out_threadProperties);
154  out_threadProperties.nPriority = AK_THREAD_PRIORITY_ABOVE_NORMAL;
155  }
156 
157 }
158 #endif
159 
160 namespace AKPLATFORM
161 {
162  // to be used to unequivocally cause a crash for scenarios that are critical failures that we cannot hope to recover from
164  {
165  // We don't want to simply abort() the program; we want a real SIGSEGV happening on *this* thread
166  // This convoluted way of crashing is necessary to avoid compilers optimizing out invalid code
167  // By calling PerformanceCounter, which is inherently non-deterministic, the compiler must generate code as-is
168  AkInt64 one, two;
169  PerformanceCounter(&one);
170  PerformanceCounter(&two);
171  AkUIntPtr ptr = (AkUIntPtr)two - (AkUIntPtr)one;
172  ((void(*)())ptr)();
173  }
174 }
175 
176 #ifndef AK_FORCE_CRASH
177 #define AK_FORCE_CRASH AKPLATFORM::AkForceCrash()
178 #endif
179 
180 #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