diff options
author | George Hazan <george.hazan@gmail.com> | 2014-07-13 10:50:59 +0000 |
---|---|---|
committer | George Hazan <george.hazan@gmail.com> | 2014-07-13 10:50:59 +0000 |
commit | 5df94ff719eccd04c7450df35fb5e3f2b36e2ee7 (patch) | |
tree | 440d736b199ff849ca0619adf355ffc73750ca7f /protocols/IRCG/src/tools.cpp | |
parent | 70496fb739225b559a251f4518c946110aef718c (diff) |
wrapping the most evident critical sections into a class
git-svn-id: http://svn.miranda-ng.org/main/trunk@9785 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'protocols/IRCG/src/tools.cpp')
-rw-r--r-- | protocols/IRCG/src/tools.cpp | 38 |
1 files changed, 12 insertions, 26 deletions
diff --git a/protocols/IRCG/src/tools.cpp b/protocols/IRCG/src/tools.cpp index 5d07573291..8046eebf0d 100644 --- a/protocols/IRCG/src/tools.cpp +++ b/protocols/IRCG/src/tools.cpp @@ -513,34 +513,21 @@ static int CompareTimers(const TimerPair* p1, const TimerPair* p2) }
static OBJLIST<TimerPair> timers(10, CompareTimers);
-static CRITICAL_SECTION timers_cs;
-
-void InitTimers(void)
-{
- InitializeCriticalSection(&timers_cs);
-}
+static mir_cs timers_cs;
void UninitTimers(void)
{
- EnterCriticalSection(&timers_cs);
+ mir_cslock lck(timers_cs);
timers.destroy();
- LeaveCriticalSection(&timers_cs);
- DeleteCriticalSection(&timers_cs);
}
CIrcProto* GetTimerOwner(UINT_PTR nIDEvent)
{
- CIrcProto* result;
+ mir_cslock lck(timers_cs);
- EnterCriticalSection(&timers_cs);
TimerPair temp(NULL, nIDEvent);
int idx = timers.getIndex(&temp);
- if (idx == -1)
- result = NULL;
- else
- result = timers[idx].ppro;
- LeaveCriticalSection(&timers_cs);
- return result;
+ return (idx == -1) ? NULL : timers[idx].ppro;
}
void CIrcProto::SetChatTimer(UINT_PTR &nIDEvent, UINT uElapse, TIMERPROC lpTimerFunc)
@@ -550,25 +537,24 @@ void CIrcProto::SetChatTimer(UINT_PTR &nIDEvent, UINT uElapse, TIMERPROC lpTimer nIDEvent = SetTimer(NULL, NULL, uElapse, lpTimerFunc);
- EnterCriticalSection(&timers_cs);
+ mir_cslock lck(timers_cs);
timers.insert(new TimerPair(this, nIDEvent));
- LeaveCriticalSection(&timers_cs);
}
void CIrcProto::KillChatTimer(UINT_PTR &nIDEvent)
{
- if (nIDEvent) {
- EnterCriticalSection(&timers_cs);
+ if (nIDEvent == 0)
+ return;
+ {
+ mir_cslock lck(timers_cs);
TimerPair temp(this, nIDEvent);
int idx = timers.getIndex(&temp);
if (idx != -1)
timers.remove(idx);
-
- LeaveCriticalSection(&timers_cs);
-
- KillTimer(NULL, nIDEvent);
- nIDEvent = NULL;
}
+
+ KillTimer(NULL, nIDEvent);
+ nIDEvent = NULL;
}
/////////////////////////////////////////////////////////////////////////////////////////
|