Go to the documentation of this file.
32 #include <nn/os/os_EventApi.h>
33 #include <nn/os/os_SemaphoreApi.h>
34 #include <nn/os/os_ThreadApi.h>
35 #include <nn/os/os_TickApi.h>
36 #include <nn/os/os_TickTypes.h>
37 #include <nn/os/os_MemoryHeapCommon.h>
38 #include <nn/nn_TimeSpan.h>
45 #define AkMax(x1, x2) (((x1) > (x2))? (x1): (x2))
46 #define AkMin(x1, x2) (((x1) < (x2))? (x1): (x2))
47 #define AkClamp(x, min, max) ((x) < (min)) ? (min) : (((x) > (max) ? (max) : (x)))
70 #define AK_DECLARE_THREAD_ROUTINE( FuncName ) void FuncName(void* lpParameter)
71 #define AK_THREAD_RETURN( _param_ ) return // (_param_)
72 #define AK_THREAD_ROUTINE_PARAMETER lpParameter
73 #define AK_GET_THREAD_ROUTINE_PARAMETER_PTR(type) reinterpret_cast<type*>( AK_THREAD_ROUTINE_PARAMETER )
75 #define AK_NULL_THREAD nullptr
77 #define AK_DEFAULT_STACK_SIZE (128*1024)
78 #define AK_THREAD_PRIORITY_NORMAL (nn::os::DefaultThreadPriority)
79 #define AK_THREAD_PRIORITY_ABOVE_NORMAL (nn::os::DefaultThreadPriority-1)
80 #define AK_THREAD_PRIORITY_BELOW_NORMAL (nn::os::LowestThreadPriority)
81 #define AK_THREAD_PRIORITY_TIME_CRITICAL (nn::os::HighestThreadPriority+1)
84 #define AK_THREAD_AFFINITY_ALL 7 // from binary 0b0111 setting the 3 available cores to available
85 #define AK_THREAD_AFFINITY_DEFAULT AK_THREAD_AFFINITY_ALL
87 #define AK_INFINITE (-1)
95 wprintf(L
"%ls", in_pszMsg);
100 printf(
"%s", in_pszMsg);
104 template <
int MaxSize = 0>
108 va_start(args, in_pszFmt);
109 vwprintf(in_pszFmt, args);
114 template <
int MaxSize = 0>
118 va_start(args, in_pszFmt);
119 vprintf(in_pszFmt, args);
126 template <
int MaxSize = 0>
129 template <
int MaxSize = 0>
139 memset(&out_event, 0,
sizeof(out_event));
145 nn::os::InitializeEvent(&out_event,
false, nn::os::EventClearMode_AutoClear);
152 if (io_event._state == nn::os::EventType::State_Initialized)
153 nn::os::FinalizeEvent(&io_event);
159 AKASSERT(in_event._state == nn::os::EventType::State_Initialized);
160 nn::os::WaitEvent(&in_event);
166 AKASSERT(in_event._state == nn::os::EventType::State_Initialized);
167 nn::os::SignalEvent(&in_event);
179 nn::os::InitializeSemaphore(
189 AKASSERT(io_semaphore._state == nn::os::SemaphoreType::State_Initialized);
190 nn::os::FinalizeSemaphore(&io_semaphore);
196 AKASSERT(in_semaphore._state == nn::os::SemaphoreType::State_Initialized);
197 nn::os::AcquireSemaphore(&in_semaphore);
203 AKASSERT(in_semaphore._state == nn::os::SemaphoreType::State_Initialized);
204 nn::os::ReleaseSemaphore(&in_semaphore, in_count);
213 return in_pThread->
thread._state != nn::os::ThreadType::State_NotInitialized;
219 in_pThread->
thread._state = nn::os::ThreadType::State_NotInitialized;
225 nn::os::DestroyThread(&in_pThread->
thread);
230 #define AkExitThread( _result ) return
237 out_threadProperties.
iIdealCore = nn::os::IdealCoreUseDefaultValue;
247 const char * in_szThreadName)
251 AKASSERT(in_threadProperties.
nPriority >= nn::os::HighestThreadPriority && in_threadProperties.
nPriority <= nn::os::LowestThreadPriority);
262 if (!result.IsSuccess())
271 nn::os::SetThreadName(&out_pThread->
thread, in_szThreadName);
276 nn::os::StartThread(&out_pThread->
thread);
282 nn::os::WaitThread(&in_pThread->
thread);
287 return nn::os::GetCurrentThread();
293 nn::os::SleepThread(nn::TimeSpan::FromMilliSeconds(in_ulMilliseconds));
302 *out_piLastTime = nn::os::GetSystemTick().GetInt64Value();
308 *out_piFreq = nn::os::GetSystemTickFrequency();
327 #define AK_PATH_SEPARATOR "/"
332 char* io_pszAnsiString)
337 memset(&state,
'\0',
sizeof(state));
339 return wcsrtombs(io_pszAnsiString,
340 &in_pszUnicodeString,
349 void* io_pvUnicodeStringBuffer)
354 memset(&state,
'\0',
sizeof(state));
356 return mbsrtowcs((
wchar_t*)io_pvUnicodeStringBuffer,
364 void* io_pvUnicodeStringBuffer)
366 return AkCharToWideChar(in_pszUtf8String, in_uiOutBufferSize, io_pvUnicodeStringBuffer);
372 size_t iSizeCopy =
AkMin(in_uDestMaxNumChars - 1, wcslen(in_pSrc) + 1);
373 wcsncpy(in_pDest, in_pSrc, iSizeCopy);
374 in_pDest[iSizeCopy] =
'\0';
380 size_t iSizeCopy =
AkMin(in_uDestMaxNumChars - 1, strlen(in_pSrc) + 1);
381 strncpy(in_pDest, in_pSrc, iSizeCopy);
382 in_pDest[iSizeCopy] =
'\0';
388 size_t iAvailableSize = (int)(in_uDestMaxNumChars - wcslen(in_pDest) - 1);
389 wcsncat(in_pDest, in_pSrc,
AkMin(iAvailableSize, (
int)wcslen(in_pSrc)));
395 size_t iAvailableSize = (int)(in_uDestMaxNumChars - strlen(in_pDest) - 1);
396 strncat(in_pDest, in_pSrc,
AkMin(iAvailableSize, (
int)strlen(in_pSrc)));
399 inline int SafeStrFormat(
wchar_t * in_pDest,
size_t in_uDestMaxNumChars,
const wchar_t* in_pszFmt, ...)
402 va_start(args, in_pszFmt);
403 int r = vswprintf(in_pDest, in_uDestMaxNumChars, in_pszFmt, args);
408 inline int SafeStrFormat(
char * in_pDest,
size_t in_uDestMaxNumChars,
const char* in_pszFmt, ...)
411 va_start(args, in_pszFmt);
412 int r = vsnprintf(in_pDest, in_uDestMaxNumChars, in_pszFmt, args);
418 #define AkAlloca( _size_ ) __builtin_alloca( _size_ )
420 #if __BIGGEST_ALIGNMENT__ < AK_SIMD_ALIGNMENT
421 #define AkAllocaSIMD( _size_ ) __builtin_alloca_with_align( _size_, AK_SIMD_ALIGNMENT*8 )
432 #define CONVERT_WIDE_TO_OSCHAR( _wstring_, _oscharstring_ ) \
433 _oscharstring_ = (AkOSChar*)AkAlloca( (1 + wcslen( _wstring_ )) * sizeof(AkOSChar) ); \
434 AKPLATFORM::AkWideCharToChar( _wstring_ , (AkUInt32)(1 + wcslen( _wstring_ )), (AkOSChar*)( _oscharstring_ ) )
444 #define CONVERT_CHAR_TO_OSCHAR( _astring_, _oscharstring_ ) ( _oscharstring_ ) = (AkOSChar*)( _astring_ )
454 #define CONVERT_OSCHAR_TO_WIDE( _osstring_, _wstring_ ) \
455 _wstring_ = (wchar_t*)AkAlloca((1+strlen(_osstring_)) * sizeof(wchar_t)); \
456 AKPLATFORM::AkCharToWideChar( _osstring_, (AkUInt32)(1 + strlen(_osstring_ )), _wstring_ )
466 #define CONVERT_OSCHAR_TO_CHAR( _osstring_, _astring_ ) _astring_ = (char*)_osstring_
474 while (*in_pStr != 0)
486 return (strlen(in_pszString));
490 #define AK_OSPRINTF snprintf
495 return (strcmp(in_pszString1, in_pszString2));
506 return (strncmp(in_pszString1, in_pszString2, in_MaxCountSize));
513 return strstr(in_pszPath,
":/") !=
nullptr;
516 template<
class destType,
class srcType>
517 inline size_t AkSimpleConvertString( destType* in_pdDest,
const srcType* in_pSrc,
size_t in_MaxSize,
size_t destStrLen(
const destType *),
size_t srcStrLen(
const srcType *) )
520 size_t lenToCopy = srcStrLen(in_pSrc);
522 lenToCopy = (lenToCopy > in_MaxSize-1) ? in_MaxSize-1 : lenToCopy;
523 for(i = 0; i < lenToCopy; i++)
525 in_pdDest[i] = (destType) in_pSrc[i];
527 in_pdDest[lenToCopy] = (destType)0;
532 #define CONVERT_UTF16_TO_CHAR(_astring_, _charstring_) \
533 _charstring_ = (char*)AkAlloca( (1 + AKPLATFORM::AkUtf16StrLen((const AkUtf16*)_astring_)) * sizeof(char) ); \
534 AK_UTF16_TO_CHAR( _charstring_, (const AkUtf16*)_astring_, AKPLATFORM::AkUtf16StrLen((const AkUtf16*)_astring_)+1 )
536 #define AK_UTF16_TO_WCHAR( in_pdDest, in_pSrc, in_MaxSize ) AKPLATFORM::AkSimpleConvertString( in_pdDest, in_pSrc, in_MaxSize, wcslen, AKPLATFORM::AkUtf16StrLen )
537 #define AK_WCHAR_TO_UTF16( in_pdDest, in_pSrc, in_MaxSize ) AKPLATFORM::AkSimpleConvertString( in_pdDest, in_pSrc, in_MaxSize, AKPLATFORM::AkUtf16StrLen, wcslen )
538 #define AK_UTF8_TO_OSCHAR( in_pdDest, in_pSrc, in_MaxSize ) AKPLATFORM::AkSimpleConvertString( in_pdDest, in_pSrc, in_MaxSize, strlen, strlen )
539 #define AK_UTF16_TO_OSCHAR( in_pdDest, in_pSrc, in_MaxSize ) AKPLATFORM::AkSimpleConvertString( in_pdDest, in_pSrc, in_MaxSize, strlen, AKPLATFORM::AkUtf16StrLen )
540 #define AK_UTF16_TO_CHAR( in_pdDest, in_pSrc, in_MaxSize ) AKPLATFORM::AkSimpleConvertString( in_pdDest, in_pSrc, in_MaxSize, strlen, AKPLATFORM::AkUtf16StrLen )
541 #define AK_CHAR_TO_UTF16( in_pdDest, in_pSrc, in_MaxSize ) AKPLATFORM::AkSimpleConvertString( in_pdDest, in_pSrc, in_MaxSize, AKPLATFORM::AkUtf16StrLen, strlen )
542 #define AK_OSCHAR_TO_UTF16( in_pdDest, in_pSrc, in_MaxSize ) AKPLATFORM::AkSimpleConvertString( in_pdDest, in_pSrc, in_MaxSize, AKPLATFORM::AkUtf16StrLen, strlen )
543 #define AK_PATH_SEPARATOR "/"
544 #define AK_LIBRARY_PREFIX ""
545 #define AK_DYNAMIC_LIBRARY_EXTENSION ""
547 #define AK_FILEHANDLE_TO_UINTPTR(_h) ((AkUIntPtr)_h.handle)
548 #define AK_SET_FILEHANDLE_TO_UINTPTR(_h,_u) _h.handle = (void*)_u
AKRESULT AkCreateSemaphore(AkSemaphore &out_semaphore, AkUInt32 in_initialCount)
Platform Independent Helper.
size_t AkUtf16StrLen(const AkUtf16 *in_pStr)
Definition of data structures for AkAudioObject.
int nPriority
Thread priority.
void AkClearEvent(AkEvent &out_event)
Platform Independent Helper.
AkForceInline void AkClearSemaphore(AkSemaphore &io_semaphore)
Platform Independent Helper.
Platform-dependent helpers.
void AkWaitForEvent(AkEvent &in_event)
Platform Independent Helper.
AkForceInline void UpdatePerformanceFrequency()
Platform Independent Helper.
nn::Bit64 affinityMask
Affinity mask for each core: see nn::os::SetThreadCoreMask documentation.
AKRESULT
Standard function call result.
void OutputDebugMsg(const char *in_pszMsg)
Output a debug message on the console (Ansi string)
uint8_t AkUInt8
Unsigned 8-bit integer.
int SafeStrFormat(wchar_t *in_pDest, size_t in_uDestMaxNumChars, const wchar_t *in_pszFmt,...)
AkThreadID CurrentThread()
Returns the calling thread's ID.
bool IsAbsolutePath(const AkOSChar *in_pszPath, size_t in_pathLen)
Detects whether the string represents an absolute path to a file.
float AkReal32
32-bit floating point
@ AK_Success
The operation was successful.
int32_t AkInt32
Signed 32-bit integer.
void AkCreateThread(AkThreadRoutine pStartRoutine, void *pParams, const AkThreadProperties &in_threadProperties, AkThread *out_pThread, const char *)
Platform Independent Helper.
void OutputDebugMsgV(const char *in_pszFmt,...)
Output a debug message on the console (variadic function).
void PerformanceCounter(AkInt64 *out_piLastTime)
Platform Independent Helper.
void AkDestroySemaphore(AkSemaphore &io_semaphore)
Platform Independent Helper.
void AkDestroyEvent(AkEvent &io_event)
Platform Independent Helper.
AkForceInline bool AkIsValidThread(AkThread *in_pThread)
Platform Independent Helper.
#define AKASSERT(Condition)
AkForceInline void AkSleep(AkUInt32 in_ulMilliseconds)
Platform Independent Helper.
AkForceInline void AkClearThread(AkThread *in_pThread)
Platform Independent Helper.
AkForceInline void AkGetDefaultThreadProperties(AkThreadProperties &out_threadProperties)
Platform Independent Helper.
int OsStrNCmp(const AkOSChar *in_pszString1, const AkOSChar *in_pszString2, size_t in_MaxCountSize)
double AkReal64
64-bit floating point
AKRESULT AkCreateEvent(AkEvent &out_event)
Platform Independent Helper.
int iIdealCore
Preferred core number: see nn::os::SetThreadCoreMask documentation.
AkForceInline void SafeStrCpy(wchar_t *in_pDest, const wchar_t *in_pSrc, size_t in_uDestMaxNumChars)
Safe unicode string copy.
int64_t AkInt64
Signed 64-bit integer.
nn::os::ThreadType thread
void AkWaitForSemaphore(AkSemaphore &in_semaphore)
Platform Independent Helper - Semaphore wait, aka Operation P. Decrements value of semaphore,...
size_t uStackSize
Thread stack size.
void PerformanceFrequency(AkInt64 *out_piFreq)
Platform Independent Helper.
AkForceInline AkInt32 AkCharToWideChar(const char *in_pszAnsiString, AkUInt32 in_uiOutBufferSize, void *io_pvUnicodeStringBuffer)
String conversion helper.
uint32_t AkUInt32
Unsigned 32-bit integer.
void AkReleaseSemaphore(AkSemaphore &in_semaphore, AkUInt32 in_count)
Platform Independent Helper - Semaphore signal, aka Operation V. Increments value of semaphore by an ...
AkForceInline void SafeStrCat(wchar_t *in_pDest, const wchar_t *in_pSrc, size_t in_uDestMaxNumChars)
Safe unicode string concatenation.
AkForceInline AkInt32 AkWideCharToChar(const wchar_t *in_pszUnicodeString, AkUInt32 in_uiOutBufferSize, char *io_pszAnsiString)
String conversion helper.
AkForceInline void AkWaitForSingleThread(AkThread *in_pThread)
Platform Independent Helper.
AkInt32 nPriority
Thread priority. 0=highest, 31=lowest.
void AkSignalEvent(const AkEvent &in_event)
Platform Independent Helper.
size_t AkSimpleConvertString(destType *in_pdDest, const srcType *in_pSrc, size_t in_MaxSize, size_t destStrLen(const destType *), size_t srcStrLen(const srcType *))
AkForceInline AkInt32 AkUtf8ToWideChar(const char *in_pszUtf8String, AkUInt32 in_uiOutBufferSize, void *io_pvUnicodeStringBuffer)
String conversion helper.
AkForceInline void AkCloseThread(AkThread *in_pThread)
Platform Independent Helper.
AkForceInline int OsStrCmp(const AkOSChar *in_pszString1, const AkOSChar *in_pszString2)
AkForceInline size_t OsStrLen(const AkOSChar *in_pszString)
AkForceInline AkReal32 Elapsed(const AkInt64 &in_iNow, const AkInt64 &in_iStart)
Returns a time range in milliseconds, using the sound engine's updated count->milliseconds ratio.
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