Version
menu_open
link
Target Platform(s):
Wwise SDK 2019.1.11
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  Version: <VERSION> Build: <BUILDNUMBER>
25  Copyright (c) <COPYRIGHTYEAR> Audiokinetic Inc.
26 *******************************************************************************/
27 
28 #pragma once
29 
30 #include <AK/Tools/Common/AkAssert.h>
31 #include <AK/SoundEngine/Common/AkTypes.h>
32 
33 //#include <sys/atomics.h>
34 #include <time.h>
35 #include <stdlib.h>
36 #include <stdio.h>
37 #include <sched.h>
38 
39 #define AK_THREAD_INIT_CODE(_threadProperties) \
40  if (_threadProperties.dwAffinityMask != AK_THREAD_AFFINITY_DEFAULT) \
41  { \
42  cpu_set_t affinity; \
43  CPU_ZERO(&affinity); \
44  for (AkUInt32 i = 0; i < 32; ++i) { \
45  if (_threadProperties.dwAffinityMask & ( 1 << i )){\
46  CPU_SET(i, &affinity); \
47  } \
48  } \
49  sched_setaffinity(0, sizeof(cpu_set_t), &affinity); \
50  }
51 
52 namespace AKPLATFORM
53 {
54  // Atomic Operations
55  // ------------------------------------------------------------------
56 
57  /// Platform Independent Helper
58  inline AkInt32 AkInterlockedIncrement(AkAtomic32 * pValue)
59  {
60  return __sync_add_and_fetch(pValue,1);
61  }
62 
63  /// Platform Independent Helper
64  inline AkInt32 AkInterlockedDecrement(AkAtomic32 * pValue)
65  {
66  return __sync_sub_and_fetch(pValue,1);
67  }
68 
69  AkForceInline bool AkInterlockedCompareExchange(volatile AkAtomic32* io_pDest, AkInt32 in_newValue, AkInt32 in_expectedOldVal)
70  {
71  return __sync_bool_compare_and_swap(io_pDest, in_expectedOldVal, in_newValue);
72  }
73 
74  AkForceInline bool AkInterlockedCompareExchange(volatile AkAtomic64* io_pDest, AkInt64 in_newValue, AkInt64 in_expectedOldVal)
75  {
76  return __sync_bool_compare_and_swap(io_pDest, in_expectedOldVal, in_newValue);
77  }
78 
79  inline void AkMemoryBarrier()
80  {
81  __sync_synchronize();
82  }
83 
84  // Time functions
85  // ------------------------------------------------------------------
86 
87  /// Platform Independent Helper
88  inline void PerformanceCounter( AkInt64 * out_piLastTime )
89  {
90  struct timespec clockNow;
91  clock_gettime(CLOCK_MONOTONIC, &clockNow);
92  *out_piLastTime = ((clockNow.tv_sec + clockNow.tv_nsec/ 1000000000.0) * CLOCKS_PER_SEC);
93  }
94 
95  /// Platform Independent Helper
96  inline void PerformanceFrequency( AkInt64 * out_piFreq )
97  {
98  // TO DO ANDROID ... is there something better
99  *out_piFreq = CLOCKS_PER_SEC;
100  }
101 
102  template<class destType, class srcType>
103  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 *) )
104  {
105  size_t i;
106  size_t lenToCopy = srcStrLen(in_pSrc);
107 
108  lenToCopy = (lenToCopy > in_MaxSize-1) ? in_MaxSize-1 : lenToCopy;
109  for(i = 0; i < lenToCopy; i++)
110  {
111  in_pdDest[i] = (destType) in_pSrc[i];
112  }
113  in_pdDest[lenToCopy] = (destType)0;
114 
115  return lenToCopy;
116  }
117 
118  #define CONVERT_UTF16_TO_CHAR( _astring_, _charstring_ ) \
119  _charstring_ = (char*)AkAlloca( (1 + AKPLATFORM::AkUtf16StrLen((const AkUtf16*)_astring_)) * sizeof(char) ); \
120  AK_UTF16_TO_CHAR( _charstring_, (const AkUtf16*)_astring_, AKPLATFORM::AkUtf16StrLen((const AkUtf16*)_astring_)+1 )
121 
122  #define AK_UTF16_TO_CHAR( in_pdDest, in_pSrc, in_MaxSize ) AKPLATFORM::AkSimpleConvertString( in_pdDest, in_pSrc, in_MaxSize, strlen, AKPLATFORM::AkUtf16StrLen )
123  #define AK_UTF16_TO_OSCHAR( in_pdDest, in_pSrc, in_MaxSize ) AKPLATFORM::AkSimpleConvertString( in_pdDest, in_pSrc, in_MaxSize, strlen, AKPLATFORM::AkUtf16StrLen )
124  #define AK_UTF16_TO_WCHAR( in_pdDest, in_pSrc, in_MaxSize ) AKPLATFORM::AkSimpleConvertString( in_pdDest, in_pSrc, in_MaxSize, wcslen, AKPLATFORM::AkUtf16StrLen )
125  #define AK_CHAR_TO_UTF16( in_pdDest, in_pSrc, in_MaxSize ) AKPLATFORM::AkSimpleConvertString( in_pdDest, in_pSrc, in_MaxSize, AKPLATFORM::AkUtf16StrLen, strlen )
126  #define AK_OSCHAR_TO_UTF16( in_pdDest, in_pSrc, in_MaxSize ) AKPLATFORM::AkSimpleConvertString( in_pdDest, in_pSrc, in_MaxSize, AKPLATFORM::AkUtf16StrLen, strlen )
127  #define AK_WCHAR_TO_UTF16( in_pdDest, in_pSrc, in_MaxSize ) AKPLATFORM::AkSimpleConvertString( in_pdDest, in_pSrc, in_MaxSize, AKPLATFORM::AkUtf16StrLen, wcslen )
128 
129  /// Stack allocations.
130  #define AkAlloca( _size_ ) __builtin_alloca( _size_ )
131 }
void AkMemoryBarrier()
Definition: AkPlatformFuncs.h:91
AkInt32 AkInterlockedIncrement(AkAtomic32 *pValue)
Platform Independent Helper.
Definition: AkPlatformFuncs.h:70
AkInt32 AkInterlockedDecrement(AkAtomic32 *pValue)
Platform Independent Helper.
Definition: AkPlatformFuncs.h:76
void PerformanceCounter(AkInt64 *out_piLastTime)
Platform Independent Helper.
Definition: AkPlatformFuncs.h:106
void PerformanceFrequency(AkInt64 *out_piFreq)
Platform Independent Helper.
Definition: AkPlatformFuncs.h:43
bool AkInterlockedCompareExchange(volatile AkAtomic32 *io_pDest, AkInt32 in_newValue, AkInt32 in_expectedOldVal)
Definition: AkPlatformFuncs.h:81
size_t AkSimpleConvertString(destType *in_pdDest, const srcType *in_pSrc, size_t in_MaxSize, size_t destStrLen(const destType *), size_t srcStrLen(const srcType *))
Definition: AkPlatformFuncs.h:113

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