버전
menu_open
알림: 고객님의 주요 출시 버전( 2023.1.6.8555 )에 해당하는 최신 설명서로 이동했습니다. 특정 버전의 설명서를 보시려면 Audiokinetic 런처에서 오프라인 설명서를 다운로드하고 Wwise Authoring의 Offline Documentation을 확인하세요.
Wwise SDK 2023.1.6
AkPlatformFuncs.h
이 파일의 문서화 페이지로 가기
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) 2024 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 #ifdef __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 AK_THREAD_INIT_CODE
116 #define AK_THREAD_INIT_CODE(_threadProperties)
117 #endif
118 
119 // to be used to unequivocally cause a crash for scenarios that are critical failures that we cannot hope to recover from
120 #ifndef AK_FORCE_CRASH
121 #define AK_FORCE_CRASH \
122  ((void(*)())0)(); \
123  *((char*)-1) = 'x';
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  // fallback implementations for when platform don't have their own implementation
158 #if !defined(AK_LIMITEDSPINFORZERO)
159  // Waits for a limited amount of time for in_pVal to hit zero (without yielding the thread)
160  inline void AkLimitedSpinForZero(AkAtomic32* in_pVal)
161  {
162  AkInt64 endSpinTime = 0;
163  AkInt64 currentTime = 0;
164  PerformanceCounter(&endSpinTime);
165  endSpinTime += AkInt64(AK::g_fFreqRatio * 0.01); // only spin for about 10us
166  while (true)
167  {
168  // if pval is zero, skip out
169  if (AkAtomicLoad32(in_pVal) == 0)
170  {
171  break;
172  }
173  AkSpinHint();
174 
175  // Check if we've hit the deadline for the timeout
176  PerformanceCounter(&currentTime);
177  if (currentTime > endSpinTime)
178  {
179  break;
180  }
181  }
182  }
183 
184  // Waits for a limited amount of time for in_pVal to get atomically shift from the expected value to the proposed one
185  // returns true if acquisition succeeded
186  inline bool AkLimitedSpinToAcquire(AkAtomic32* in_pVal, AkInt32 in_proposed, AkInt32 in_expected)
187  {
188  if (AkAtomicCas32(in_pVal, in_proposed, in_expected))
189  {
190  return true;
191  }
192 
193  // Cas failed, start the slower evaluation
194  AkInt64 endSpinTime = 0;
195  AkInt64 currentTime = 0;
196  PerformanceCounter(&endSpinTime);
197  endSpinTime += AkInt64(AK::g_fFreqRatio * 0.01); // only spin for about 10us
198  while (true)
199  {
200  // attempt cas to acquire and if successful, skip out
201  if (AkAtomicCas32(in_pVal, in_proposed, in_expected))
202  {
203  return true;
204  }
205  AkSpinHint();
206 
207  // Check if we've hit the deadline for the timeout
208  PerformanceCounter(&currentTime);
209  if (currentTime > endSpinTime)
210  {
211  return false;
212  }
213  }
214  }
215 #endif // !defined(AK_LIMITEDSPINFORZERO)
216 
217  inline void AkSpinWaitForZero(AkAtomic32* in_pVal)
218  {
219  if (AkAtomicLoad32(in_pVal) == 0)
220  {
221  return;
222  }
223 
224  // do a limited spin on-the-spot until in_pVal hits zero
225  AkLimitedSpinForZero(in_pVal);
226 
227  // if in_pVal is still non-zero, then the other thread is either blocked or waiting for us. Yield for real.
228  while (AkAtomicLoad32(in_pVal))
229  AkThreadYield();
230  }
231 
232  // Waits for a limited amount of time for in_pVal to get atomically shift from 0 to 1
233  inline void AkSpinToAcquire(AkAtomic32* in_pVal, AkInt32 in_proposed, AkInt32 in_expected)
234  {
235  // do a limited spin on-the-spot until in_pVal can successfully hit 1
236  // or if it fails, then the other thread is either blocked or waiting for us. Yield for real.
237  while (!AkLimitedSpinToAcquire(in_pVal, in_proposed, in_expected))
238  {
239  AkThreadYield();
240  }
241  }
242 }
243 #endif
244 
245 #ifndef AK_PERF_RECORDING_RESET
246 #define AK_PERF_RECORDING_RESET()
247 #endif
248 #ifndef AK_PERF_RECORDING_START
249 #define AK_PERF_RECORDING_START( __StorageName__, __uExecutionCountStart__, __uExecutionCountStop__ )
250 #endif
251 #ifndef AK_PERF_RECORDING_STOP
252 #define AK_PERF_RECORDING_STOP( __StorageName__, __uExecutionCountStart__, __uExecutionCountStop__ )
253 #endif
254 
255 #endif // _AK_TOOLS_COMMON_AKPLATFORMFUNCS_H
void AkSpinHint()
Definition: AkAtomic.h:36
AkForceInline void AkMemMove(void *pDest, const void *pSrc, AkUInt32 uSize)
int nPriority
Thread priority
Platform-dependent helpers
Definition: AkBitFuncs.h:43
__forceinline int AkAtomicCas32(AkAtomic32 *pDest, long proposed, long expected)
Definition: AkAtomic.h:68
#define AK_THREAD_PRIORITY_ABOVE_NORMAL
int32_t AkInt32
Signed 32-bit integer
void PerformanceCounter(AkInt64 *out_piLastTime)
Platform Independent Helper
volatile uint32_t AkAtomic32
Definition: AkAtomic.h:45
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
void AkLimitedSpinForZero(AkAtomic32 *in_pVal)
bool AkLimitedSpinToAcquire(AkAtomic32 *in_pVal, AkInt32 in_proposed, AkInt32 in_expected)
AkReal32 g_fFreqRatio
void AkGetDefaultHighPriorityThreadProperties(AkThreadProperties &out_threadProperties)
int64_t AkInt64
Signed 64-bit integer
void AkSpinToAcquire(AkAtomic32 *in_pVal, AkInt32 in_proposed, AkInt32 in_expected)
#define AkThreadYield()
Definition: AkAtomic.h:34
void AkSpinWaitForZero(AkAtomic32 *in_pVal)
uint32_t AkUInt32
Unsigned 32-bit integer
AkForceInline void AkMemSet(void *pDest, AkInt32 iVal, AkUInt32 uSize)
#define AkForceInline
Definition: AkTypes.h:63
__forceinline long AkAtomicLoad32(AkAtomic32 *pSrc)
Definition: AkAtomic.h:58

이 페이지가 도움이 되었나요?

지원이 필요하신가요?

질문이 있으신가요? 문제를 겪고 계신가요? 더 많은 정보가 필요하신가요? 저희에게 문의해주시면 도와드리겠습니다!

지원 페이지를 방문해 주세요

작업하는 프로젝트에 대해 알려주세요. 언제든지 도와드릴 준비가 되어 있습니다.

프로젝트를 등록하세요. 아무런 조건이나 의무 사항 없이 빠른 시작을 도와드리겠습니다.

Wwise를 시작해 보세요