Commit 307bf11d authored by captainwong's avatar captainwong

try lock

parent 634b6b7a
// LocalLock.h: interface for the CLocalLock class.
//
//////////////////////////////////////////////////////////////////////
#if !defined(AFX_LOCALLOCK_H__FD10F2F9_1DF2_46A6_8261_1FA9E2AB061C__INCLUDED_)
#define AFX_LOCALLOCK_H__FD10F2F9_1DF2_46A6_8261_1FA9E2AB061C__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
class CLocalLock
{
public:
CLocalLock(LPCRITICAL_SECTION lpCriticalSection)
:m_lpCriticalSection(lpCriticalSection)
{
EnterCriticalSection(m_lpCriticalSection);
}
~CLocalLock()
{
LeaveCriticalSection(m_lpCriticalSection);
}
private:
LPCRITICAL_SECTION m_lpCriticalSection;
};
class CLock
{
public:
/*CLock(PCRITICAL_SECTION cs) : m_cs(cs), bNullInit(FALSE)
{
if (m_cs == NULL) {
bNullInit = TRUE;
m_cs = new CRITICAL_SECTION();
}
InitializeCriticalSection(m_cs);
}*/
CLock()/* : m_cs(NULL), bNullInit(FALSE)*/
{
/*if (m_cs == NULL) {
m_cs = new CRITICAL_SECTION();
}*/
InitializeCriticalSection(&m_cs);
}
~CLock()
{
DeleteCriticalSection(&m_cs);
/*if (bNullInit) {
delete m_cs;
}*/
}
void Lock()
{
EnterCriticalSection(&m_cs);
}
void UnLock()
{
LeaveCriticalSection(&m_cs);
}
const LPCRITICAL_SECTION GetObject() { return &m_cs; }
private:
CRITICAL_SECTION m_cs;
//BOOL bNullInit;
};
#endif // !defined(AFX_LOCALLOCK_H__FD10F2F9_1DF2_46A6_8261_1FA9E2AB061C__INCLUDED_)
// LocalLock.h: interface for the CLocalLock class.
//
//////////////////////////////////////////////////////////////////////
#if !defined(AFX_LOCALLOCK_H__FD10F2F9_1DF2_46A6_8261_1FA9E2AB061C__INCLUDED_)
#define AFX_LOCALLOCK_H__FD10F2F9_1DF2_46A6_8261_1FA9E2AB061C__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
class CLocalLock
{
public:
CLocalLock(LPCRITICAL_SECTION lpCriticalSection)
:m_lpCriticalSection(lpCriticalSection)
{
EnterCriticalSection(m_lpCriticalSection);
}
~CLocalLock()
{
LeaveCriticalSection(m_lpCriticalSection);
}
private:
LPCRITICAL_SECTION m_lpCriticalSection;
};
class CLock
{
public:
/*CLock(PCRITICAL_SECTION cs) : m_cs(cs), bNullInit(FALSE)
{
if (m_cs == NULL) {
bNullInit = TRUE;
m_cs = new CRITICAL_SECTION();
}
InitializeCriticalSection(m_cs);
}*/
CLock()/* : m_cs(NULL), bNullInit(FALSE)*/
{
/*if (m_cs == NULL) {
m_cs = new CRITICAL_SECTION();
}*/
InitializeCriticalSection(&m_cs);
}
~CLock()
{
DeleteCriticalSection(&m_cs);
/*if (bNullInit) {
delete m_cs;
}*/
}
void Lock()
{
EnterCriticalSection(&m_cs);
}
void UnLock()
{
LeaveCriticalSection(&m_cs);
}
BOOL TryLock()
{
return ::TryEnterCriticalSection(&m_cs);
}
const LPCRITICAL_SECTION GetObject() { return &m_cs; }
private:
CRITICAL_SECTION m_cs;
//BOOL bNullInit;
};
#endif // !defined(AFX_LOCALLOCK_H__FD10F2F9_1DF2_46A6_8261_1FA9E2AB061C__INCLUDED_)
......@@ -106,4 +106,4 @@ public: \
DECLARE_SETTER_STRING(val);
#define INITIALIZE_STRING(val) { val = new wchar_t[1]; val[0] = 0; }
\ No newline at end of file
#define INITIALIZE_STRING(val) { val = new wchar_t[1]; val[0] = 0; }
......@@ -48,6 +48,7 @@ void class_name::UnRegisterObserver(void* udata) \
} \
void class_name::NotifyObservers(_param_type param) \
{ \
AUTO_LOG_FUNCTION; \
_lock4ObserverList.Lock(); \
std::list<_callbackInfo *>::iterator iter = _observerList.begin(); \
while (iter != _observerList.end()) { \
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment