Generic Sprtlock class header implementation files on Windows and Linux

Source: Internet
Author: User

/**
@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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.