From 15d4346a1e3ada4bd14739b63fc239109dc96a0c Mon Sep 17 00:00:00 2001 From: George Hazan Date: Thu, 30 Apr 2015 18:47:28 +0000 Subject: custom critical section class replaced with mir_cs/mir_cslock git-svn-id: http://svn.miranda-ng.org/main/trunk@13300 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- plugins/Boltun/src/Engine/CriticalSection.h | 54 ----------------------------- plugins/Boltun/src/Engine/PerContactData.h | 36 ++++++------------- plugins/Boltun/src/Engine/TalkEngine.cpp | 11 +++--- plugins/Boltun/src/Engine/TalkEngine.h | 2 ++ plugins/Boltun/src/Engine/ValueChooser.h | 3 ++ 5 files changed, 20 insertions(+), 86 deletions(-) delete mode 100644 plugins/Boltun/src/Engine/CriticalSection.h (limited to 'plugins/Boltun/src/Engine') diff --git a/plugins/Boltun/src/Engine/CriticalSection.h b/plugins/Boltun/src/Engine/CriticalSection.h deleted file mode 100644 index 550aa32696..0000000000 --- a/plugins/Boltun/src/Engine/CriticalSection.h +++ /dev/null @@ -1,54 +0,0 @@ -//*********************************************************** -// Copyright © 2008 Valentin Pavlyuchenko -// -// This file is part of Boltun. -// -// Boltun is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 2 of the License, or -// (at your option) any later version. -// -// Boltun is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with Boltun. If not, see . -// -//*********************************************************** - -#ifndef CriticalSectionH -#define CriticalSectionH - -class CriticalSection -{ - CRITICAL_SECTION csQueue; -public: - inline CriticalSection() - { - InitializeCriticalSection(&csQueue); - } - - inline ~CriticalSection() - { - DeleteCriticalSection(&csQueue); - } - - inline void Enter() - { - EnterCriticalSection(&csQueue); - } - - inline void Leave() - { - LeaveCriticalSection(&csQueue); - } - - inline bool TryEnter() - { - return TryEnterCriticalSection(&csQueue) != 0; - } -}; - -#endif /* CriticalSectionH */ \ No newline at end of file diff --git a/plugins/Boltun/src/Engine/PerContactData.h b/plugins/Boltun/src/Engine/PerContactData.h index e81192053f..75bc321b66 100644 --- a/plugins/Boltun/src/Engine/PerContactData.h +++ b/plugins/Boltun/src/Engine/PerContactData.h @@ -21,17 +21,16 @@ #ifndef PerContactDataH #define PerContactDataH -#include "CriticalSection.h" - static std::map perContactDataObjects; template class PerContactData { + PerContactData& operator=(const PerContactData&); + template struct InternalData { - CriticalSection lock; Data *data; time_t time; inline InternalData(const Source& src) @@ -51,7 +50,7 @@ class PerContactData delete data; } }; - CriticalSection mapLock; + mir_cs mapLock; unsigned timerID; std::map* > datas; typedef typename std::map* >::iterator mapIt; @@ -59,6 +58,7 @@ class PerContactData void CleanupData(); template friend VOID CALLBACK RunTimerProc(HWND hwnd, UINT uMsg, UINT_PTR idEvent, DWORD dwTime); + public: PerContactData(const Source& src); ~PerContactData(); @@ -75,7 +75,7 @@ PerContactData::PerContactData(const Source& src) template PerContactData::~PerContactData() { - mapLock.Enter(); + mir_cslock mlck(mapLock); if (timerID) { KillTimer(NULL, timerID); @@ -83,40 +83,26 @@ PerContactData::~PerContactData() } while (!datas.empty()) { - while (!(*datas.begin()).second->lock.TryEnter()) - { - mapLock.Leave(); - Sleep(10); - mapLock.Enter(); - } - //Now we know exactly that no-one onws a contact lock - InternalData* data = (*datas.begin()).second; - data->lock.Leave(); - delete data; + delete (*datas.begin()).second; datas.erase(datas.begin()); } - mapLock.Leave(); } template Data* PerContactData::GetData(ContactHandle Contact) { - mapLock.Enter(); + mir_cslock mlck(mapLock); mapIt it; if ((it = datas.find(Contact)) == datas.end()) it = datas.insert(make_pair(Contact, new InternalData(source))).first; - (*it).second->lock.Enter(); (*it).second->time = 0; - Data* data = (*it).second->data; - mapLock.Leave(); - return data; + return (*it).second->data; } template void PerContactData::PutData(ContactHandle Contact) { - mapLock.Enter(); - datas[Contact]->lock.Leave(); + mir_cslock mlck(mapLock); ::time(&(datas[Contact]->time)); if (!timerID) { @@ -124,13 +110,12 @@ void PerContactData::PutData(ContactHandle Contact) assert(timerID); perContactDataObjects[timerID] = this; } - mapLock.Leave(); } template void PerContactData::CleanupData() { - mapLock.Enter(); + mir_cslock mlck(mapLock); time_t now; time(&now); for (mapIt it = datas.begin(); it != datas.end();) @@ -156,7 +141,6 @@ void PerContactData::CleanupData() KillTimer(NULL, timerID); perContactDataObjects.erase(timerID); } - mapLock.Leave(); } template diff --git a/plugins/Boltun/src/Engine/TalkEngine.cpp b/plugins/Boltun/src/Engine/TalkEngine.cpp index 0391c11112..8d4efbf476 100644 --- a/plugins/Boltun/src/Engine/TalkEngine.cpp +++ b/plugins/Boltun/src/Engine/TalkEngine.cpp @@ -97,8 +97,7 @@ tstring TalkBot::ReplaceAliases(const tstring &message) const TCHAR dividers[] = _T(" \t\n\r,./?\\|;:'\"~!#^&*()_-+=[{]}—\1"); tstring sentence = message; tstring result; - int len = (int)sentence.length(); - map sm; + map sm; //Find smiles for (size_t i = 0; i < sentence.length() - 1; i++) { @@ -116,7 +115,7 @@ tstring TalkBot::ReplaceAliases(const tstring &message) } } } - len = (int)sentence.length(); + int len = (int)sentence.length(); bool hadQuestionSigns = false; int it = 0; while (it != len) @@ -125,7 +124,7 @@ tstring TalkBot::ReplaceAliases(const tstring &message) { if (sentence[it] == _T('?')) hadQuestionSigns = true; - map::iterator smit; + map::iterator smit; if (sentence[it] == '\1') { smit = sm.find(it); @@ -515,7 +514,7 @@ void TalkBot::SplitAndSortWords(tstring sentence, vector& keywords, const TCHAR dividers[] = _T(" \t\n\r,./?\\|;:'\"~!#^&*()_-+=[{]}—"); int len = (int)sentence.length(); vector words; - map sm; + map sm; //Find smiles for (size_t i = 0; i < sentence.length() - 1; i++) { @@ -543,7 +542,7 @@ void TalkBot::SplitAndSortWords(tstring sentence, vector& keywords, { if (sentence[it] == _T('?')) hadQuestionSigns = true; - map::iterator smit; + map::iterator smit; if (_istspace(sentence[it]) && (smit = sm.find(it)) != sm.end()) words.push_back((*smit).second); it++; diff --git a/plugins/Boltun/src/Engine/TalkEngine.h b/plugins/Boltun/src/Engine/TalkEngine.h index 6f95541941..c18f3df1c1 100644 --- a/plugins/Boltun/src/Engine/TalkEngine.h +++ b/plugins/Boltun/src/Engine/TalkEngine.h @@ -28,6 +28,8 @@ class TalkBot { + TalkBot& operator=(const TalkBot&); + public: struct MessageInfo { diff --git a/plugins/Boltun/src/Engine/ValueChooser.h b/plugins/Boltun/src/Engine/ValueChooser.h index 10256a5b70..0018ac8ff2 100644 --- a/plugins/Boltun/src/Engine/ValueChooser.h +++ b/plugins/Boltun/src/Engine/ValueChooser.h @@ -29,6 +29,9 @@ private: bool *numbers; const container data; bool notifyOnReset; + + ValueChooser& operator=(const ValueChooser&); + public: ValueChooser(const container& vec, bool NotifyOnReset = false) :data(vec), notifyOnReset(NotifyOnReset) -- cgit v1.2.3