diff options
author | Kirill Volinsky <mataes2007@gmail.com> | 2015-05-11 11:09:40 +0000 |
---|---|---|
committer | Kirill Volinsky <mataes2007@gmail.com> | 2015-05-11 11:09:40 +0000 |
commit | e6040d454c758e72333132dc05ee72d910b78bed (patch) | |
tree | d8853aafe250599eaf70b3eb262b897862a77346 | |
parent | 93e2b89909ac060eccb27a3a651ab3efb4911c5c (diff) |
minus critical section
git-svn-id: http://svn.miranda-ng.org/main/trunk@13523 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
-rw-r--r-- | protocols/Sametime/src/messaging.cpp | 12 | ||||
-rw-r--r-- | protocols/Sametime/src/sametime_proto.cpp | 2 | ||||
-rw-r--r-- | protocols/Sametime/src/sametime_proto.h | 6 | ||||
-rw-r--r-- | protocols/Sametime/src/sametime_session.cpp | 35 |
4 files changed, 12 insertions, 43 deletions
diff --git a/protocols/Sametime/src/messaging.cpp b/protocols/Sametime/src/messaging.cpp index 55f49ea16f..e6e953b38f 100644 --- a/protocols/Sametime/src/messaging.cpp +++ b/protocols/Sametime/src/messaging.cpp @@ -28,7 +28,7 @@ void mwIm_conversation_opened(mwConversation* conv) }
ContactMessageQueue::iterator i;
- EnterCriticalSection(&proto->q_cs);
+ mir_cslock lck(proto->q_cs);
if ((i = proto->contact_message_queue.find(hContact)) != proto->contact_message_queue.end()) {
while (i->second.size()) {
mwConversation_send(conv, mwImSend_PLAIN, (gconstpointer)i->second.front().c_str());
@@ -36,7 +36,6 @@ void mwIm_conversation_opened(mwConversation* conv) }
proto->contact_message_queue.erase(i);
}
- LeaveCriticalSection(&proto->q_cs);
// gives linker error 'unresolved external symbol' :( So instead we will either add ciphers to the session or not (see session.cpp)
//mwConversation_setEncrypted(conv, options.encrypt_session);
@@ -57,12 +56,10 @@ void mwIm_conversation_closed(mwConversation* conv, guint32 err) mwIdBlock* idb = mwConversation_getTarget(conv);
MCONTACT hContact = proto->FindContactByUserId(idb->user);
if (hContact) {
- EnterCriticalSection(&proto->q_cs);
+ mir_cslock lck(proto->q_cs);
ContactMessageQueue::iterator i = proto->contact_message_queue.find(hContact);
if (i != proto->contact_message_queue.end())
proto->contact_message_queue.erase(i);
-
- LeaveCriticalSection(&proto->q_cs);
}
}
@@ -130,9 +127,8 @@ HANDLE CSametimeProto::SendMessageToUser(MCONTACT hContact, char* msg_utf8) if (conv) {
if (!mwConversation_isOpen(conv)) {
debugLog(_T("CSametimeProto::SendMessageToUser() mwConversation_isOpen"));
- EnterCriticalSection(&q_cs);
+ mir_cslock lck(q_cs);
contact_message_queue[hContact].push(msg_utf8);
- LeaveCriticalSection(&q_cs);
mwConversation_open(conv);
}
else {
@@ -196,7 +192,6 @@ void CSametimeProto::CloseIm(MCONTACT hContact) void CSametimeProto::InitMessaging()
{
debugLog(_T("CSametimeProto::InitMessaging()"));
- InitializeCriticalSection(&q_cs);
mwSession_addService(session, (mwService*)(service_im = mwServiceIm_new(session, &mwIm_handler)));
mwServiceIm_setClientType(service_im, mwImClient_PLAIN);
}
@@ -207,5 +202,4 @@ void CSametimeProto::DeinitMessaging() mwSession_removeService(session, mwService_IM);
mwService_free((mwService*)service_im);
service_im = 0;
- DeleteCriticalSection(&q_cs);
}
diff --git a/protocols/Sametime/src/sametime_proto.cpp b/protocols/Sametime/src/sametime_proto.cpp index 9ee51096e7..cacb87a850 100644 --- a/protocols/Sametime/src/sametime_proto.cpp +++ b/protocols/Sametime/src/sametime_proto.cpp @@ -27,7 +27,6 @@ CSametimeProto::CSametimeProto(const char* pszProtoName, const TCHAR* tszUserNam debugLog(_T("CSametimeProto::CSametimeProto() start m_szModuleName=[%s], m_tszUserName=[%s]"), _A2T(m_szModuleName), m_tszUserName);
SametimeInitIcons();
- InitCritSection();
CreateProtoService(PS_GETNAME, &CSametimeProto::GetName);
CreateProtoService(PS_GETSTATUS, &CSametimeProto::GetStatus);
@@ -72,7 +71,6 @@ CSametimeProto::~CSametimeProto() DeinitAwayMsg();
UnregisterPopups();
- DeinitCritSection();
debugLog(_T("CSametimeProto::~CSametimeProto() end"));
diff --git a/protocols/Sametime/src/sametime_proto.h b/protocols/Sametime/src/sametime_proto.h index 7a68ae3e33..4243f16f61 100644 --- a/protocols/Sametime/src/sametime_proto.h +++ b/protocols/Sametime/src/sametime_proto.h @@ -115,8 +115,6 @@ struct CSametimeProto : public PROTO<CSametimeProto> void DeinitSessionMenu();
int LogIn(int status, HANDLE hNetlibUser);
int LogOut();
- void InitCritSection();
- void DeinitCritSection();
int SetSessionStatus(int status);
void UpdateSelfStatus();
int SetIdle(bool idle);
@@ -153,7 +151,7 @@ struct CSametimeProto : public PROTO<CSametimeProto> char szProtoGroups[128];
HANDLE mainThread;
- CRITICAL_SECTION session_cs;
+ mir_cs session_cs;
mwSession* session;
int previous_status;
bool is_idle;
@@ -168,7 +166,7 @@ struct CSametimeProto : public PROTO<CSametimeProto> mwServiceFileTransfer* service_files;
// messaging.cpp
- CRITICAL_SECTION q_cs;
+ mir_cs q_cs;
mwServiceIm* service_im;
ContactMessageQueue contact_message_queue;
diff --git a/protocols/Sametime/src/sametime_session.cpp b/protocols/Sametime/src/sametime_session.cpp index 3a5a05fd92..2f322b2c4f 100644 --- a/protocols/Sametime/src/sametime_session.cpp +++ b/protocols/Sametime/src/sametime_session.cpp @@ -238,9 +238,8 @@ void __cdecl SessionSetUserStatus(struct mwSession* session) void CSametimeProto::UpdateSelfStatus()
{
- EnterCriticalSection(&session_cs);
+ mir_cslock lck(session_cs);
if (session) SessionSetUserStatus(session);
- LeaveCriticalSection(&session_cs);
}
int CSametimeProto::SetSessionStatus(int status)
@@ -366,13 +365,11 @@ void __cdecl KeepAliveThread(LPVOID param) SleepEx(250, TRUE);
- EnterCriticalSection(&(proto->session_cs));
+ mir_cslock lck(proto->session_cs);
if (Miranda_Terminated() || !proto->session) {
- LeaveCriticalSection(&(proto->session_cs));
proto->debugLog(_T("KeepAliveThread() end"));
break;
}
- LeaveCriticalSection(&(proto->session_cs));
}
return;
@@ -427,13 +424,12 @@ void __cdecl SessionThread(LPVOID param) handler.on_setPrivacyInfo = SessionSetPrivacyInfo;
handler.on_setUserStatus = SessionSetUserStatus;
- EnterCriticalSection(&proto->session_cs);
+ mir_cslock lck(proto->session_cs);
proto->session = mwSession_new(&handler);
proto->InitMeanwhileServices();
mwSession_start(proto->session);
- LeaveCriticalSection(&proto->session_cs);
mir_forkthread(KeepAliveThread, (void*)proto);
@@ -452,19 +448,17 @@ void __cdecl SessionThread(LPVOID param) break;
}
else {
- EnterCriticalSection(&proto->session_cs);
+ mir_cslock lck(proto->session_cs);
mwSession_recv(proto->session, recv_buffer, bytes);
- LeaveCriticalSection(&proto->session_cs);
}
}
mir_free(recv_buffer);
- EnterCriticalSection(&proto->session_cs);
+ mir_cslock lck2(proto->session_cs);
proto->DeinitMeanwhileServices();
mwSession* old_session = proto->session;
proto->session = 0; // kills keepalive thread, if awake
mwSession_free(old_session);
- LeaveCriticalSection(&proto->session_cs);
proto->BroadcastNewStatus(ID_STATUS_OFFLINE);
proto->SetAllOffline();
@@ -498,13 +492,11 @@ int CSametimeProto::LogIn(int ls, HANDLE hNetlibUser) {
debugLog(_T("LogIn() start"));
- EnterCriticalSection(&session_cs);
+ mir_cslock lck(session_cs);
if (session) {
- LeaveCriticalSection(&session_cs);
debugLog(_T("LogIn() end, currently in session"));
return 0;
}
- LeaveCriticalSection(&session_cs);
login_status = ls;
@@ -518,12 +510,11 @@ int CSametimeProto::LogOut() debugLog(_T("LogOut() start"));
continue_connect = false;
- EnterCriticalSection(&session_cs);
+ mir_cslock lck(session_cs);
if (session && server_connection && m_iStatus != ID_STATUS_OFFLINE && !mwSession_isStopped(session) && !mwSession_isStopping(session)) {
debugLog(_T("LogOut() mwSession_stop"));
mwSession_stop(session, 0);
}
- LeaveCriticalSection(&session_cs);
return 0;
}
@@ -587,15 +578,3 @@ void CSametimeProto::DeinitSessionMenu() debugLog(_T("CSametimeProto::DeinitSessionMenu()"));
CallService(MO_REMOVEMENUITEM, (WPARAM)hSessionAnnounceMenuItem, 0);
}
-
-void CSametimeProto::InitCritSection()
-{
- debugLog(_T("CSametimeProto::InitCritSection()"));
- InitializeCriticalSection(&session_cs);
-}
-
-void CSametimeProto::DeinitCritSection()
-{
- debugLog(_T("CSametimeProto::DeinitCritSection()"));
- DeleteCriticalSection(&session_cs);
-}
|