Commit 307bf11d authored by captainwong's avatar captainwong

try lock

parent 634b6b7a
// LocalLock.h: interface for the CLocalLock class. // LocalLock.h: interface for the CLocalLock class.
// //
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
#if !defined(AFX_LOCALLOCK_H__FD10F2F9_1DF2_46A6_8261_1FA9E2AB061C__INCLUDED_) #if !defined(AFX_LOCALLOCK_H__FD10F2F9_1DF2_46A6_8261_1FA9E2AB061C__INCLUDED_)
#define AFX_LOCALLOCK_H__FD10F2F9_1DF2_46A6_8261_1FA9E2AB061C__INCLUDED_ #define AFX_LOCALLOCK_H__FD10F2F9_1DF2_46A6_8261_1FA9E2AB061C__INCLUDED_
#if _MSC_VER > 1000 #if _MSC_VER > 1000
#pragma once #pragma once
#endif // _MSC_VER > 1000 #endif // _MSC_VER > 1000
class CLocalLock class CLocalLock
{ {
public: public:
CLocalLock(LPCRITICAL_SECTION lpCriticalSection) CLocalLock(LPCRITICAL_SECTION lpCriticalSection)
:m_lpCriticalSection(lpCriticalSection) :m_lpCriticalSection(lpCriticalSection)
{ {
EnterCriticalSection(m_lpCriticalSection); EnterCriticalSection(m_lpCriticalSection);
} }
~CLocalLock() ~CLocalLock()
{ {
LeaveCriticalSection(m_lpCriticalSection); LeaveCriticalSection(m_lpCriticalSection);
} }
private: private:
LPCRITICAL_SECTION m_lpCriticalSection; LPCRITICAL_SECTION m_lpCriticalSection;
}; };
class CLock class CLock
{ {
public: public:
/*CLock(PCRITICAL_SECTION cs) : m_cs(cs), bNullInit(FALSE) /*CLock(PCRITICAL_SECTION cs) : m_cs(cs), bNullInit(FALSE)
{ {
if (m_cs == NULL) { if (m_cs == NULL) {
bNullInit = TRUE; bNullInit = TRUE;
m_cs = new CRITICAL_SECTION(); m_cs = new CRITICAL_SECTION();
} }
InitializeCriticalSection(m_cs); InitializeCriticalSection(m_cs);
}*/ }*/
CLock()/* : m_cs(NULL), bNullInit(FALSE)*/ CLock()/* : m_cs(NULL), bNullInit(FALSE)*/
{ {
/*if (m_cs == NULL) { /*if (m_cs == NULL) {
m_cs = new CRITICAL_SECTION(); m_cs = new CRITICAL_SECTION();
}*/ }*/
InitializeCriticalSection(&m_cs); InitializeCriticalSection(&m_cs);
} }
~CLock() ~CLock()
{ {
DeleteCriticalSection(&m_cs); DeleteCriticalSection(&m_cs);
/*if (bNullInit) { /*if (bNullInit) {
delete m_cs; delete m_cs;
}*/ }*/
} }
void Lock() void Lock()
{ {
EnterCriticalSection(&m_cs); EnterCriticalSection(&m_cs);
} }
void UnLock() void UnLock()
{ {
LeaveCriticalSection(&m_cs); LeaveCriticalSection(&m_cs);
} }
const LPCRITICAL_SECTION GetObject() { return &m_cs; } BOOL TryLock()
private: {
CRITICAL_SECTION m_cs; return ::TryEnterCriticalSection(&m_cs);
//BOOL bNullInit; }
};
const LPCRITICAL_SECTION GetObject() { return &m_cs; }
private:
#endif // !defined(AFX_LOCALLOCK_H__FD10F2F9_1DF2_46A6_8261_1FA9E2AB061C__INCLUDED_) CRITICAL_SECTION m_cs;
//BOOL bNullInit;
};
#endif // !defined(AFX_LOCALLOCK_H__FD10F2F9_1DF2_46A6_8261_1FA9E2AB061C__INCLUDED_)
...@@ -106,4 +106,4 @@ public: \ ...@@ -106,4 +106,4 @@ public: \
DECLARE_SETTER_STRING(val); DECLARE_SETTER_STRING(val);
#define INITIALIZE_STRING(val) { val = new wchar_t[1]; val[0] = 0; } #define INITIALIZE_STRING(val) { val = new wchar_t[1]; val[0] = 0; }
\ No newline at end of file
...@@ -48,6 +48,7 @@ void class_name::UnRegisterObserver(void* udata) \ ...@@ -48,6 +48,7 @@ void class_name::UnRegisterObserver(void* udata) \
} \ } \
void class_name::NotifyObservers(_param_type param) \ void class_name::NotifyObservers(_param_type param) \
{ \ { \
AUTO_LOG_FUNCTION; \
_lock4ObserverList.Lock(); \ _lock4ObserverList.Lock(); \
std::list<_callbackInfo *>::iterator iter = _observerList.begin(); \ std::list<_callbackInfo *>::iterator iter = _observerList.begin(); \
while (iter != _observerList.end()) { \ 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