From b2cb548cd4b3b9a89da777f4465095fa37539d1b Mon Sep 17 00:00:00 2001 From: George Hazan Date: Wed, 27 Dec 2017 23:56:48 +0300 Subject: boost threads replaced with mir_forkthread --- plugins/StopSpamMod/src/init.cpp | 3 +- plugins/StopSpamMod/src/stdafx.h | 8 +++-- plugins/StopSpamMod/src/utilities.cpp | 68 +++++++++++++++++++---------------- 3 files changed, 45 insertions(+), 34 deletions(-) (limited to 'plugins/StopSpamMod') diff --git a/plugins/StopSpamMod/src/init.cpp b/plugins/StopSpamMod/src/init.cpp index 67da239639..4d18f3b559 100755 --- a/plugins/StopSpamMod/src/init.cpp +++ b/plugins/StopSpamMod/src/init.cpp @@ -117,9 +117,8 @@ static int OnSystemModulesLoaded(WPARAM, LPARAM) if (ServiceExists(MS_VARS_FORMATSTRING)) gbVarsServiceExist = TRUE; InitVars(); - void CleanThread(); if(gbDelAllTempory || gbDelExcluded) - new boost::thread(&CleanThread); + mir_forkthread(&CleanThread); // Folders plugin support hStopSpamLogDirH = FoldersRegisterCustomPathT(LPGEN("StopSpam"), LPGEN("StopSpam Logs"), FOLDER_LOGS); diff --git a/plugins/StopSpamMod/src/stdafx.h b/plugins/StopSpamMod/src/stdafx.h index c8479ab49b..d5551e8d10 100755 --- a/plugins/StopSpamMod/src/stdafx.h +++ b/plugins/StopSpamMod/src/stdafx.h @@ -19,7 +19,9 @@ using namespace std; #include #include -#include +#include +#include + #include #include #include @@ -38,4 +40,6 @@ extern HANDLE hStopSpamLogDirH; int OnDbContactSettingChanged(WPARAM w, LPARAM l); int OnDbEventFilterAdd(WPARAM w, LPARAM l); int OnDbEventAdded(WPARAM hContact, LPARAM hDbEvent); -int OnOptInit(WPARAM w, LPARAM l); \ No newline at end of file +int OnOptInit(WPARAM w, LPARAM l); + +void __cdecl CleanThread(void*); \ No newline at end of file diff --git a/plugins/StopSpamMod/src/utilities.cpp b/plugins/StopSpamMod/src/utilities.cpp index 7943dada3f..f6f586a5eb 100755 --- a/plugins/StopSpamMod/src/utilities.cpp +++ b/plugins/StopSpamMod/src/utilities.cpp @@ -81,8 +81,7 @@ void DeleteCListGroupsByName(wchar_t* szGroupName) int RemoveTmp(WPARAM, LPARAM) { - void CleanThread(); - CleanThread(); + CleanThread(0); return 0; } @@ -239,59 +238,68 @@ void LogSpamToFile(MCONTACT hContact, wstring message) file.close(); } -boost::mutex clean_mutex; +mir_cs clean_mutex; -void CleanProtocolTmpThread(std::string proto) +void __cdecl CleanProtocolTmpThread(void *param) { + const char *szProto = (const char*)param; + while (true) { - UINT status = CallProtoService(proto.c_str(), PS_GETSTATUS, 0, 0); + UINT status = CallProtoService(szProto, PS_GETSTATUS, 0, 0); if (status > ID_STATUS_OFFLINE) break; - boost::this_thread::sleep(boost::posix_time::seconds(2)); + Sleep(2000); } std::list contacts; - for (MCONTACT hContact = db_find_first(proto.c_str()); hContact; hContact = db_find_next(hContact, proto.c_str())) + for (MCONTACT hContact = db_find_first(szProto); hContact; hContact = db_find_next(hContact, szProto)) if (db_get_b(hContact, "CList", "NotOnList", 0) || (L"Not In List" == DBGetContactSettingStringPAN(hContact, "CList", "Group", L""))) contacts.push_back(hContact); - boost::this_thread::sleep(boost::posix_time::seconds(5)); - clean_mutex.lock(); - std::list::iterator end = contacts.end(); - for (std::list::iterator i = contacts.begin(); i != end; ++i) { - LogSpamToFile(*i, L"Deleted"); - HistoryLogFunc(*i, "Deleted"); - db_delete_contact(*i); + Sleep(5000); + { + mir_cslock lck(clean_mutex); + + std::list::iterator end = contacts.end(); + for (std::list::iterator i = contacts.begin(); i != end; ++i) { + LogSpamToFile(*i, L"Deleted"); + HistoryLogFunc(*i, "Deleted"); + db_delete_contact(*i); + } } - clean_mutex.unlock(); + mir_free(param); } -void CleanProtocolExclThread(std::string proto) +void __cdecl CleanProtocolExclThread(void *param) { + const char *szProto = (const char*)param; + while (true) { - UINT status = CallProtoService(proto.c_str(), PS_GETSTATUS, 0, 0); + UINT status = CallProtoService(szProto, PS_GETSTATUS, 0, 0); if (status > ID_STATUS_OFFLINE) break; - boost::this_thread::sleep(boost::posix_time::seconds(2)); + Sleep(2000); } std::list contacts; - for (MCONTACT hContact = db_find_first(proto.c_str()); hContact; hContact = db_find_next(hContact, proto.c_str())) + for (MCONTACT hContact = db_find_first(szProto); hContact; hContact = db_find_next(hContact, szProto)) if (db_get_b(hContact, "CList", "NotOnList", 0) && db_get_b(hContact, pluginName, "Excluded", 0)) contacts.push_back(hContact); - boost::this_thread::sleep(boost::posix_time::seconds(5)); - clean_mutex.lock(); - std::list::iterator end = contacts.end(); - for (std::list::iterator i = contacts.begin(); i != end; ++i) { - LogSpamToFile(*i, L"Deleted"); - HistoryLogFunc(*i, "Deleted"); - db_delete_contact(*i); + Sleep(5000); + { + mir_cslock lck(clean_mutex); + std::list::iterator end = contacts.end(); + for (std::list::iterator i = contacts.begin(); i != end; ++i) { + LogSpamToFile(*i, L"Deleted"); + HistoryLogFunc(*i, "Deleted"); + db_delete_contact(*i); + } } - clean_mutex.unlock(); + mir_free(param); } -void CleanThread() +void __cdecl CleanThread(void*) { std::list protocols; int count = 0; @@ -304,9 +312,9 @@ void CleanThread() std::list::iterator end = protocols.end(); for (std::list::iterator i = protocols.begin(); i != end; ++i) { if (gbDelAllTempory) - new boost::thread(boost::bind(&CleanProtocolTmpThread, *i)); + mir_forkthread(CleanProtocolTmpThread, mir_strdup((*i).c_str())); if (gbDelExcluded) - new boost::thread(boost::bind(&CleanProtocolExclThread, *i)); + mir_forkthread(CleanProtocolExclThread, mir_strdup((*i).c_str())); } } -- cgit v1.2.3