00001
00002
00003
00004
00005
00006
00007
00008
00010
00011 #pragma once
00012
00013 #include <AK/Tools/Common/AkAssert.h>
00014 #include <AK/SoundEngine/Common/AkTypes.h>
00015
00016
00017 #include <time.h>
00018 #include <stdlib.h>
00019 #include <stdio.h>
00020
00021 namespace AKPLATFORM
00022 {
00023
00024
00025
00027 inline AkInt32 AkInterlockedIncrement( AkInt32 * pValue )
00028 {
00029 return __sync_add_and_fetch(pValue,1);
00030 }
00031
00033 inline AkInt32 AkInterlockedDecrement( AkInt32 * pValue )
00034 {
00035 return __sync_sub_and_fetch(pValue,1);
00036 }
00037
00038 AkForceInline bool AkInterlockedCompareExchange( volatile AkInt32* io_pDest, AkInt32 in_newValue, AkInt32 in_expectedOldVal )
00039 {
00040 return __sync_bool_compare_and_swap(io_pDest, in_expectedOldVal, in_newValue);
00041 }
00042
00043 AkForceInline bool AkInterlockedCompareExchange( volatile AkInt64* io_pDest, AkInt64 in_newValue, AkInt64 in_expectedOldVal )
00044 {
00045 return __sync_bool_compare_and_swap(io_pDest, in_expectedOldVal, in_newValue);
00046 }
00047
00048 inline void AkMemoryBarrier()
00049 {
00050 __sync_synchronize();
00051 }
00052
00053
00054
00055
00057 inline void PerformanceCounter( AkInt64 * out_piLastTime )
00058 {
00059 *out_piLastTime = clock();
00060 }
00061
00063 inline void PerformanceFrequency( AkInt64 * out_piFreq )
00064 {
00065
00066 *out_piFreq = CLOCKS_PER_SEC;
00067 }
00068
00069 template<class destType, class srcType>
00070 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 *) )
00071 {
00072 size_t i;
00073 size_t lenToCopy = srcStrLen(in_pSrc);
00074
00075 lenToCopy = (lenToCopy > in_MaxSize-1) ? in_MaxSize-1 : lenToCopy;
00076 for(i = 0; i < lenToCopy; i++)
00077 {
00078 in_pdDest[i] = (destType) in_pSrc[i];
00079 }
00080 in_pdDest[lenToCopy] = (destType)0;
00081
00082 return lenToCopy;
00083 }
00084
00085 #define CONVERT_UTF16_TO_CHAR( _astring_, _charstring_ ) \
00086 _charstring_ = (char*)AkAlloca( (1 + AKPLATFORM::AkUtf16StrLen((const AkUtf16*)_astring_)) * sizeof(char) ); \
00087 AK_UTF16_TO_CHAR( _charstring_, (const AkUtf16*)_astring_, AKPLATFORM::AkUtf16StrLen((const AkUtf16*)_astring_)+1 )
00088
00089 #define AK_UTF16_TO_CHAR( in_pdDest, in_pSrc, in_MaxSize ) AKPLATFORM::AkSimpleConvertString( in_pdDest, in_pSrc, in_MaxSize, strlen, AKPLATFORM::AkUtf16StrLen )
00090 #define AK_UTF16_TO_OSCHAR( in_pdDest, in_pSrc, in_MaxSize ) AKPLATFORM::AkSimpleConvertString( in_pdDest, in_pSrc, in_MaxSize, strlen, AKPLATFORM::AkUtf16StrLen )
00091 #define AK_UTF16_TO_WCHAR( in_pdDest, in_pSrc, in_MaxSize ) AKPLATFORM::AkSimpleConvertString( in_pdDest, in_pSrc, in_MaxSize, wcslen, AKPLATFORM::AkUtf16StrLen )
00092 #define AK_CHAR_TO_UTF16( in_pdDest, in_pSrc, in_MaxSize ) AKPLATFORM::AkSimpleConvertString( in_pdDest, in_pSrc, in_MaxSize, AKPLATFORM::AkUtf16StrLen, strlen )
00093 #define AK_OSCHAR_TO_UTF16( in_pdDest, in_pSrc, in_MaxSize ) AKPLATFORM::AkSimpleConvertString( in_pdDest, in_pSrc, in_MaxSize, AKPLATFORM::AkUtf16StrLen, strlen )
00094 #define AK_WCHAR_TO_UTF16( in_pdDest, in_pSrc, in_MaxSize ) AKPLATFORM::AkSimpleConvertString( in_pdDest, in_pSrc, in_MaxSize, AKPLATFORM::AkUtf16StrLen, wcslen )
00095
00097 #define AkAlloca( _size_ ) __builtin_alloca( _size_ )
00098 }