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
52 lines
1.3 KiB
//----------------------------------------------------------------------------
|
|
// Laser Guard Ltd.
|
|
// Copyright © 2000-2002. All Rights Reserved.
|
|
// Version 1.0 01/01/2000
|
|
// Last modification: 08/10/2003
|
|
// PROJECT:
|
|
// SUBSYSTEM:
|
|
// FILE: LgInstanceLock.cpp
|
|
// AUTHOR: Sergey Chizhevskiy
|
|
// OVERVIEW
|
|
// ~~~~~~~~
|
|
// Source file of LgInstanceLock.cpp
|
|
//----------------------------------------------------------------------------
|
|
#include "stdafx.h"
|
|
#include "LgLogger.h"
|
|
#include "LgInstanceLock.h"
|
|
|
|
CLgInstanceLock::CLgInstanceLock()
|
|
{
|
|
LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, "CLgInstanceLock::CLgInstanceLock" );
|
|
}
|
|
|
|
CLgInstanceLock::~CLgInstanceLock()
|
|
{
|
|
Unlock();
|
|
|
|
LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, "CLgInstanceLock::~CLgInstanceLock" );
|
|
}
|
|
|
|
BOOL CLgInstanceLock::Lock( LPCTSTR pInstanceName )
|
|
{
|
|
// destroy old incarnation
|
|
LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, "CLgInstanceLock::Lock" );
|
|
|
|
// create mutex
|
|
if( !m_Mutex.Create( TRUE, pInstanceName ) )
|
|
return FALSE;
|
|
|
|
// ackquery lock
|
|
if( ::WaitForSingleObject( m_Mutex, 0 ) != WAIT_OBJECT_0 )
|
|
return FALSE;
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
void CLgInstanceLock::Unlock()
|
|
{
|
|
m_Mutex.Release();
|
|
m_Mutex.Close();
|
|
|
|
LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, "CLgInstanceLock::Unlock" );
|
|
}
|