/**
@file SprtLock.cpp
@brief SPRT lock Operation class, Sprtlock class implementation
@author Cxw
@version Version Number: 1.0 Date: 2013-10-28 Revision: Long revision: Modify source files according to the C + + coding specification
*/
#include "stdafx.h"
#include "SprtLock.h"
Sprtlock::sprtlock (void)
{
Createlock = false;
Initiallock ();
}
Sprtlock::~sprtlock ()
{
#ifdef WIN32
CloseHandle (M_hmutex);
#else
Pthread_mutex_destroy (&m_lock);
#endif
}
void Sprtlock::initiallock ()
{
if (!createlock)
{
#ifdef WIN32
M_hmutex = CreateMutex (null,false,null);
#else
Pthread_mutex_init (&m_lock,null);
#endif
Createlock = true;
}
}
int Sprtlock::lock ()
{
Return WaitForSingleObject (This->m_lock,infinite);
#ifdef WIN32
Return WaitForSingleObject (M_hmutex,infinite);
#else
Return Pthread_mutex_lock (&m_lock);
#endif
}
int Sprtlock::unlock ()
{
Return SetEvent (This->m_lock);
#ifdef WIN32
Return ReleaseMutex (M_hmutex);
#else
Return Pthread_mutex_unlock (&m_lock);
#endif
}
void Sprtlock::initialwaite ()
//{
this->m_wait = CreateEvent (null, TRUE, FALSE, NULL);
//
//}
//
int Sprtlock::waitproc ()
//{
if (WaitForSingleObject (this->m_wait, 0) = = wait_object_0)//This killclient is created in the mainline thread to control thread exit
// {
Return successful
// }
Else
// {
Return Failed
// }
//}
//
int sprtlock::unwait ()
//{
Return SetEvent (this->m_wait);
//}
Generic Sprtlock class header implementation files on Windows and Linux