diff options
| author | FluorescentCIAAfricanAmerican <[email protected]> | 2020-04-22 12:56:21 -0400 |
|---|---|---|
| committer | FluorescentCIAAfricanAmerican <[email protected]> | 2020-04-22 12:56:21 -0400 |
| commit | 3bf9df6b2785fa6d951086978a3e66f49427166a (patch) | |
| tree | 2c0f1f0c63c4832882bc93814ebd2c2b1c6224e5 /utils/vmpi/threadhelpers.h | |
| download | archived-source-engine-2018-hl2-src-master.tar.xz archived-source-engine-2018-hl2-src-master.zip | |
Diffstat (limited to 'utils/vmpi/threadhelpers.h')
| -rw-r--r-- | utils/vmpi/threadhelpers.h | 110 |
1 files changed, 110 insertions, 0 deletions
diff --git a/utils/vmpi/threadhelpers.h b/utils/vmpi/threadhelpers.h new file mode 100644 index 0000000..bfba74f --- /dev/null +++ b/utils/vmpi/threadhelpers.h @@ -0,0 +1,110 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $NoKeywords: $ +//=============================================================================// + +#ifndef THREADHELPERS_H +#define THREADHELPERS_H +#ifdef _WIN32 +#pragma once +#endif + + +#include "tier1/utllinkedlist.h" + + +#define SIZEOF_CS 24 // sizeof( CRITICAL_SECTION ) + + +class CCriticalSection +{ +public: + CCriticalSection(); + ~CCriticalSection(); + + +protected: + + friend class CCriticalSectionLock; + + void Lock(); + void Unlock(); + + +public: + char m_CS[SIZEOF_CS]; + + // Used to protect against deadlock in debug mode. +//#if defined( _DEBUG ) + CUtlLinkedList<unsigned long,int> m_Locks; + char m_DeadlockProtect[SIZEOF_CS]; +//#endif +}; + + +// Use this to lock a critical section. +class CCriticalSectionLock +{ +public: + CCriticalSectionLock( CCriticalSection *pCS ); + ~CCriticalSectionLock(); + void Lock(); + void Unlock(); + +private: + CCriticalSection *m_pCS; + bool m_bLocked; +}; + + +template< class T > +class CCriticalSectionData : private CCriticalSection +{ +public: + // You only have access to the data between Lock() and Unlock(). + T* Lock() + { + CCriticalSection::Lock(); + return &m_Data; + } + + void Unlock() + { + CCriticalSection::Unlock(); + } + +private: + T m_Data; +}; + + + +// ------------------------------------------------------------------------------------------------ // +// CEvent. +// ------------------------------------------------------------------------------------------------ // +class CEvent +{ +public: + CEvent(); + ~CEvent(); + + bool Init( bool bManualReset, bool bInitialState ); + void Term(); + + void* GetEventHandle() const; + + // Signal the event. + bool SetEvent(); + + // Unset the event's signalled status. + bool ResetEvent(); + + +private: + void *m_hEvent; +}; + + +#endif // THREADHELPERS_H |