MT5APISync.h 1.2 KB

1234567891011121314151617181920212223
  1. //+------------------------------------------------------------------+
  2. //| MetaTrader 5 API |
  3. //| Copyright 2000-2019, MetaQuotes Software Corp. |
  4. //| http://www.metaquotes.net |
  5. //+------------------------------------------------------------------+
  6. #pragma once
  7. //+------------------------------------------------------------------+
  8. //| Thread synchronization class |
  9. //+------------------------------------------------------------------+
  10. class CMTSync
  11. {
  12. private:
  13. CRITICAL_SECTION m_cs;
  14. public:
  15. CMTSync(void) { ZeroMemory(&m_cs,sizeof(m_cs)); InitializeCriticalSection(&m_cs); }
  16. ~CMTSync(void) { DeleteCriticalSection(&m_cs); }
  17. inline void Lock(void) { EnterCriticalSection(&m_cs); }
  18. inline void Unlock(void) { LeaveCriticalSection(&m_cs); }
  19. inline bool TryLock(void) { return(TryEnterCriticalSection(&m_cs)!=FALSE); }
  20. };
  21. //+------------------------------------------------------------------+