AkLock.h 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. Commercial License Usage
  5. Licensees holding valid commercial licenses to the AUDIOKINETIC Wwise Technology
  6. may use this file in accordance with the end user license agreement provided
  7. with the software or, alternatively, in accordance with the terms contained in a
  8. written agreement between you and Audiokinetic Inc.
  9. Apache License Usage
  10. Alternatively, this file may be used under the Apache License, Version 2.0 (the
  11. "Apache License"); you may not use this file except in compliance with the
  12. Apache License. You may obtain a copy of the Apache License at
  13. http://www.apache.org/licenses/LICENSE-2.0.
  14. Unless required by applicable law or agreed to in writing, software distributed
  15. under the Apache License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES
  16. OR CONDITIONS OF ANY KIND, either express or implied. See the Apache License for
  17. the specific language governing permissions and limitations under the License.
  18. Copyright (c) 2023 Audiokinetic Inc.
  19. *******************************************************************************/
  20. #ifndef _AKLOCK_H_
  21. #define _AKLOCK_H_
  22. #include <AK/SoundEngine/Common/AkTypes.h>
  23. #include <windows.h> //For CRITICAL_SECTION
  24. //-----------------------------------------------------------------------------
  25. // CAkLock class
  26. //-----------------------------------------------------------------------------
  27. class CAkLock
  28. {
  29. public:
  30. /// Constructor
  31. CAkLock()
  32. {
  33. ::InitializeCriticalSection( &m_csLock );
  34. }
  35. /// Destructor
  36. ~CAkLock()
  37. {
  38. ::DeleteCriticalSection( &m_csLock );
  39. }
  40. /// Lock
  41. inline AKRESULT Lock( void )
  42. {
  43. ::EnterCriticalSection( &m_csLock );
  44. return AK_Success;
  45. }
  46. /// Unlock
  47. inline AKRESULT Unlock( void )
  48. {
  49. ::LeaveCriticalSection( &m_csLock );
  50. return AK_Success;
  51. }
  52. /* // Returns AK_Success if lock aquired, AK_Fail otherwise.
  53. inline AKRESULT Trylock( void )
  54. {
  55. if ( ::TryEnterCriticalSection( &m_csLock ) )
  56. return AK_Success;
  57. return AK_Fail;
  58. } */
  59. private:
  60. CRITICAL_SECTION m_csLock; ///< Platform specific lock
  61. };
  62. #endif // _AKLOCK_H_