Old fashion design for PC-104
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.

52 lines
1.3 KiB

4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. //----------------------------------------------------------------------------
  2. // Laser Guard Ltd.
  3. // Copyright � 2000-2002. All Rights Reserved.
  4. // Version 1.0 01/01/2000
  5. // Last modification: 08/10/2003
  6. // PROJECT:
  7. // SUBSYSTEM:
  8. // FILE: LgInstanceLock.cpp
  9. // AUTHOR: Sergey Chizhevskiy
  10. // OVERVIEW
  11. // ~~~~~~~~
  12. // Source file of LgInstanceLock.cpp
  13. //----------------------------------------------------------------------------
  14. #include "stdafx.h"
  15. #include "LgLogger.h"
  16. #include "LgInstanceLock.h"
  17. CLgInstanceLock::CLgInstanceLock()
  18. {
  19. LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, "CLgInstanceLock::CLgInstanceLock" );
  20. }
  21. CLgInstanceLock::~CLgInstanceLock()
  22. {
  23. Unlock();
  24. LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, "CLgInstanceLock::~CLgInstanceLock" );
  25. }
  26. BOOL CLgInstanceLock::Lock( LPCTSTR pInstanceName )
  27. {
  28. // destroy old incarnation
  29. LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, "CLgInstanceLock::Lock" );
  30. // create mutex
  31. if( !m_Mutex.Create( TRUE, pInstanceName ) )
  32. return FALSE;
  33. // ackquery lock
  34. if( ::WaitForSingleObject( m_Mutex, 0 ) != WAIT_OBJECT_0 )
  35. return FALSE;
  36. return TRUE;
  37. }
  38. void CLgInstanceLock::Unlock()
  39. {
  40. m_Mutex.Release();
  41. m_Mutex.Close();
  42. LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, "CLgInstanceLock::Unlock" );
  43. }