Team Fortress 2 Source Code as on 22/4/2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

47 lines
1.2 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: Defines a bunch of stuff that would be defined in Steam, but
  4. // isn't in Source.
  5. //
  6. //=============================================================================
  7. #ifndef GCSTEAMDEFINES_H
  8. #define GCSTEAMDEFINES_H
  9. #ifdef _WIN32
  10. #pragma once
  11. #endif
  12. #include "tier0/memalloc.h"
  13. // steam defines some things that games don't
  14. #ifndef STEAM
  15. #define PvAlloc(x) malloc(x)
  16. #define PvRealloc(x, y) realloc(x, y)
  17. #define FreePv(x) free(x)
  18. // auto-lock class for read-write locks
  19. template< class T >
  20. class CRWLockAutoWrite
  21. {
  22. T &m_RWLock;
  23. public:
  24. CRWLockAutoWrite( T &RWLock ) : m_RWLock( RWLock )
  25. {
  26. m_RWLock.LockForWrite();
  27. }
  28. ~CRWLockAutoWrite()
  29. {
  30. m_RWLock.UnlockWrite();
  31. }
  32. };
  33. #define AUTO_LOCK_WRITE( mutex ) CRWLockAutoWrite<CThreadRWLock> UNIQUE_ID( mutex )
  34. #define AUTO_LOCK_SPIN_WRITE( mutex ) CRWLockAutoWrite<CThreadSpinRWLock> UNIQUE_ID( mutex )
  35. inline void *MemAlloc_AllocAligned( size_t size, size_t align, bool bCanFail ) { return MemAlloc_AllocAligned( size, align ); }
  36. inline void MemAlloc_FreeAligned( void *pMemBlock, bool bOperatorNew ) { MemAlloc_FreeAligned( pMemBlock ); }
  37. #endif
  38. #endif // GCSTEAMDEFINES_H