From 5f55dcc2e10098ac93710d13176939e4c30d5b5f Mon Sep 17 00:00:00 2001 From: Gluzskiy Alexandr Date: Tue, 22 Mar 2011 17:04:43 +0200 Subject: thread safety (incompete) --- messages.cpp | 62 +++++++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 43 insertions(+), 19 deletions(-) (limited to 'messages.cpp') diff --git a/messages.cpp b/messages.cpp index 05d138a..6875ece 100644 --- a/messages.cpp +++ b/messages.cpp @@ -19,18 +19,16 @@ wstring new_key; HANDLE new_key_hcnt = NULL; -boost::mutex new_key_hcnt_mutex; +boost::mutex new_key_hcnt_mutex, gpg_file_mutex; bool _terminate = false; int returnNoError(HANDLE hContact); int RecvMsgSvc_func(HANDLE hContact, char *msg, DWORD flags) -{ +{ + DWORD dbflags = DBEF_UTF; { //check for gpg related data wstring str = toUTF16(msg); wstring::size_type s1 = wstring::npos, s2 = wstring::npos; - DWORD dbflags = 0; - if(flags & PREF_UTF) - flags |= DBEF_UTF; if((str.find(_T("-----PGP KEY RESPONSE-----")) != wstring::npos) && !metaIsProtoMetaContacts(hContact)) { @@ -54,7 +52,10 @@ int RecvMsgSvc_func(HANDLE hContact, char *msg, DWORD flags) _tcscat(tmp2, _T("\\")); _tcscat(tmp2, _T("temporary_exported.asc")); DeleteFile(tmp2); + gpg_file_mutex.timed_lock(boost::posix_time::minutes(1)); wfstream f(tmp2, std::ios::out); + while(!f.is_open()) + f.open(tmp2, std::ios::out); ptmp = UniGetContactSettingUtf(hContact, szGPGModuleName, "GPGPubKey", _T("")); wstring new_key = ptmp; mir_free(ptmp); @@ -78,13 +79,16 @@ int RecvMsgSvc_func(HANDLE hContact, char *msg, DWORD flags) gpg_thread.~thread(); debuglog<