From 6a61e0a781d5c65c9faf00e4c38f652b36754040 Mon Sep 17 00:00:00 2001 From: Konrad Date: Mon, 1 Jan 2018 23:20:26 +0100 Subject: [PATCH] Changed in Libresapi: Locking mutex using macro instead of RsStackMutex object creation --- libresapi/src/api/ChatHandler.cpp | 28 +++++++++++----------- libresapi/src/api/FileSearchHandler.cpp | 10 ++++---- libresapi/src/api/FileSharingHandler.cpp | 4 ++-- libresapi/src/api/IdentityHandler.cpp | 4 ++-- libresapi/src/api/PeersHandler.cpp | 18 +++++++------- libresapi/src/api/RsControlModule.cpp | 30 ++++++++++++------------ libresapi/src/api/StateTokenServer.cpp | 14 +++++------ 7 files changed, 54 insertions(+), 54 deletions(-) diff --git a/libresapi/src/api/ChatHandler.cpp b/libresapi/src/api/ChatHandler.cpp index 35fa1f859..877b17c23 100644 --- a/libresapi/src/api/ChatHandler.cpp +++ b/libresapi/src/api/ChatHandler.cpp @@ -200,13 +200,13 @@ ChatHandler::~ChatHandler() void ChatHandler::notifyChatMessage(const ChatMessage &msg) { - RS_STACK_MUTEX(mMtx); /********** LOCKED **********/ + RS_STACK_MUTEX(mMtx); // ********** LOCKED ********** mRawMsgs.push_back(msg); } void ChatHandler::notifyChatCleared(const ChatId &chat_id) { - RS_STACK_MUTEX(mMtx); /********** LOCKED **********/ + RS_STACK_MUTEX(mMtx); // ********** LOCKED ********** //Remove processed messages std::list& msgs = mMsgs[chat_id]; msgs.clear(); @@ -225,14 +225,14 @@ void ChatHandler::notifyChatCleared(const ChatId &chat_id) void ChatHandler::notifyChatStatus(const ChatId &chat_id, const std::string &status) { - RS_STACK_MUTEX(mMtx); /********** LOCKED **********/ + RS_STACK_MUTEX(mMtx); // ********** LOCKED ********** locked_storeTypingInfo(chat_id, status); } void ChatHandler::notifyChatLobbyEvent(uint64_t lobby_id, uint32_t event_type, const RsGxsId &nickname, const std::string& any_string) { - RS_STACK_MUTEX(mMtx); /********** LOCKED **********/ + RS_STACK_MUTEX(mMtx); // ********** LOCKED ********** if(event_type == RS_CHAT_LOBBY_EVENT_PEER_STATUS) { locked_storeTypingInfo(ChatId(lobby_id), any_string, nickname); @@ -243,14 +243,14 @@ void ChatHandler::notifyListChange(int list, int /*type*/) { if(list == NOTIFY_LIST_CHAT_LOBBY_INVITATION) { - RS_STACK_MUTEX(mMtx); /********** LOCKED **********/ + RS_STACK_MUTEX(mMtx); // ********** LOCKED ********** mStateTokenServer->replaceToken(mInvitationsStateToken); } } void ChatHandler::tick() { - RS_STACK_MUTEX(mMtx); /********** LOCKED **********/ + RS_STACK_MUTEX(mMtx); // ********** LOCKED ********** // first fetch lobbies std::vector lobbies; @@ -868,7 +868,7 @@ void ChatHandler::locked_storeTypingInfo(const ChatId &chat_id, std::string stat void ChatHandler::handleWildcard(Request &/*req*/, Response &resp) { - RS_STACK_MUTEX(mMtx); /********** LOCKED **********/ + RS_STACK_MUTEX(mMtx); // ********** LOCKED ********** resp.mDataStream.getStreamToMember(); for(std::map >::iterator mit = mMsgs.begin(); mit != mMsgs.end(); ++mit) { @@ -882,7 +882,7 @@ void ChatHandler::handleLobbies(Request &/*req*/, Response &resp) tick(); { - RS_STACK_MUTEX(mMtx); /********** LOCKED **********/ + RS_STACK_MUTEX(mMtx); // ********** LOCKED ********** resp.mDataStream.getStreamToMember(); for(std::vector::iterator vit = mLobbies.begin(); vit != mLobbies.end(); ++vit) { @@ -1021,7 +1021,7 @@ void ChatHandler::handleAnswerToInvitation(Request& req, Response& resp) ResponseTask* ChatHandler::handleLobbyParticipants(Request &req, Response &resp) { - RS_STACK_MUTEX(mMtx); /********** LOCKED **********/ + RS_STACK_MUTEX(mMtx); // ********** LOCKED ********** ChatId id(req.mPath.top()); if(!id.isLobbyId()) @@ -1122,7 +1122,7 @@ void ChatHandler::handleMessages(Request &req, Response &resp) tick(); { - RS_STACK_MUTEX(mMtx); /********** LOCKED **********/ + RS_STACK_MUTEX(mMtx); // ********** LOCKED ********** ChatId id(req.mPath.top()); // make response a list @@ -1204,7 +1204,7 @@ void ChatHandler::handleMarkMessageAsRead(Request &req, Response &resp) void ChatHandler::handleMarkChatAsRead(Request &req, Response &resp) { - RS_STACK_MUTEX(mMtx); /********** LOCKED **********/ + RS_STACK_MUTEX(mMtx); // ********** LOCKED ********** ChatId id(req.mPath.top()); if(id.isNotSet()) @@ -1235,7 +1235,7 @@ void ChatHandler::handleMarkChatAsRead(Request &req, Response &resp) void ChatHandler::handleInfo(Request &req, Response &resp) { - RS_STACK_MUTEX(mMtx); /********** LOCKED **********/ + RS_STACK_MUTEX(mMtx); // ********** LOCKED ********** ChatId id(req.mPath.top()); if(id.isNotSet()) { @@ -1319,7 +1319,7 @@ protected: ResponseTask* ChatHandler::handleReceiveStatus(Request &req, Response &resp) { - RS_STACK_MUTEX(mMtx); /********** LOCKED **********/ + RS_STACK_MUTEX(mMtx); // ********** LOCKED ********** ChatId id(req.mPath.top()); if(id.isNotSet()) { @@ -1354,7 +1354,7 @@ void ChatHandler::handleSendStatus(Request &req, Response &resp) void ChatHandler::handleUnreadMsgs(Request &/*req*/, Response &resp) { - RS_STACK_MUTEX(mMtx); /********** LOCKED **********/ + RS_STACK_MUTEX(mMtx); // ********** LOCKED ********** resp.mDataStream.getStreamToMember(); for( std::map >::const_iterator mit = mMsgs.begin(); diff --git a/libresapi/src/api/FileSearchHandler.cpp b/libresapi/src/api/FileSearchHandler.cpp index 5d3d2a86d..0382005df 100644 --- a/libresapi/src/api/FileSearchHandler.cpp +++ b/libresapi/src/api/FileSearchHandler.cpp @@ -31,7 +31,7 @@ FileSearchHandler::~FileSearchHandler() void FileSearchHandler::notifyTurtleSearchResult(uint32_t search_id, const std::list& files) { - RsStackMutex stackMtx(mMtx); // ********** STACK LOCKED MTX ********** + RS_STACK_MUTEX(mMtx); // ********** LOCKED ********** std::map::iterator mit = mSearches.find(search_id); if(mit == mSearches.end()) return; @@ -85,7 +85,7 @@ void FileSearchHandler::handleWildcard(Request &req, Response &resp) } { - RsStackMutex stackMtx(mMtx); // ********** STACK LOCKED MTX ********** + RS_STACK_MUTEX(mMtx); // ********** LOCKED ********** std::map::iterator mit = mSearches.find(id); if(mit == mSearches.end()) { @@ -115,7 +115,7 @@ void FileSearchHandler::handleWildcard(Request &req, Response &resp) else { // list searches - RsStackMutex stackMtx(mMtx); // ********** STACK LOCKED MTX ********** + RS_STACK_MUTEX(mMtx); // ********** LOCKED ********** resp.mDataStream.getStreamToMember(); for(std::map::iterator mit = mSearches.begin(); mit != mSearches.end(); ++mit) { @@ -221,7 +221,7 @@ void FileSearchHandler::handleCreateSearch(Request &req, Response &resp) } { - RsStackMutex stackMtx(mMtx); // ********** STACK LOCKED MTX ********** + RS_STACK_MUTEX(mMtx); // ********** LOCKED ********** Search& search = mSearches[search_id]; search.mStateToken = mStateTokenServer->getNewToken(); @@ -262,7 +262,7 @@ void FileSearchHandler::handleGetSearchResult(Request& req, Response& resp) } { - RsStackMutex stackMtx(mMtx); // ********** STACK LOCKED MTX ********** + RS_STACK_MUTEX(mMtx); // ********** LOCKED ********** std::map::iterator mit = mSearches.find(id); if(mit == mSearches.end()) { diff --git a/libresapi/src/api/FileSharingHandler.cpp b/libresapi/src/api/FileSharingHandler.cpp index 19098a188..b1faf338a 100644 --- a/libresapi/src/api/FileSharingHandler.cpp +++ b/libresapi/src/api/FileSharingHandler.cpp @@ -56,13 +56,13 @@ void FileSharingHandler::notifyListChange(int list, int /* type */) { if(list == NOTIFY_LIST_DIRLIST_LOCAL) { - RsStackMutex stack(mMtx); /********** STACK LOCKED MTX ******/ + RS_STACK_MUTEX(mMtx); mStateTokenServer->discardToken(mLocalDirStateToken); mLocalDirStateToken = mStateTokenServer->getNewToken(); } else if(list == NOTIFY_LIST_DIRLIST_FRIENDS) { - RsStackMutex stack(mMtx); /********** STACK LOCKED MTX ******/ + RS_STACK_MUTEX(mMtx); mStateTokenServer->discardToken(mRemoteDirStateToken); mRemoteDirStateToken = mStateTokenServer->getNewToken(); } diff --git a/libresapi/src/api/IdentityHandler.cpp b/libresapi/src/api/IdentityHandler.cpp index 8d132dd85..ff5e50a1e 100644 --- a/libresapi/src/api/IdentityHandler.cpp +++ b/libresapi/src/api/IdentityHandler.cpp @@ -374,7 +374,7 @@ void IdentityHandler::handleAddContact(Request& req, Response& resp) mRsIdentity->setAsRegularContact(RsGxsId(gxs_id), true); { - RsStackMutex stack(mMtx); /********** STACK LOCKED MTX ******/ + RS_STACK_MUTEX(mMtx); // ********** LOCKED ********** mStateTokenServer->replaceToken(mStateToken); } @@ -389,7 +389,7 @@ void IdentityHandler::handleRemoveContact(Request& req, Response& resp) mRsIdentity->setAsRegularContact(RsGxsId(gxs_id), false); { - RsStackMutex stack(mMtx); /********** STACK LOCKED MTX ******/ + RS_STACK_MUTEX(mMtx); // ********** LOCKED ********** mStateTokenServer->replaceToken(mStateToken); } diff --git a/libresapi/src/api/PeersHandler.cpp b/libresapi/src/api/PeersHandler.cpp index b3f48c7fc..66def7eab 100644 --- a/libresapi/src/api/PeersHandler.cpp +++ b/libresapi/src/api/PeersHandler.cpp @@ -267,9 +267,9 @@ PeersHandler::~PeersHandler() void PeersHandler::notifyListChange(int list, int /* type */) { - RsStackMutex stack(mMtx); /********** STACK LOCKED MTX ******/ if(list == NOTIFY_LIST_FRIENDS) { + RS_STACK_MUTEX(mMtx); // ********** LOCKED ********** mStateTokenServer->discardToken(mStateToken); mStateToken = mStateTokenServer->getNewToken(); } @@ -277,13 +277,13 @@ void PeersHandler::notifyListChange(int list, int /* type */) void PeersHandler::notifyPeerStatusChanged(const std::string& /*peer_id*/, uint32_t /*state*/) { - RsStackMutex stack(mMtx); /********** STACK LOCKED MTX ******/ + RS_STACK_MUTEX(mMtx); // ********** LOCKED ********** mStateTokenServer->replaceToken(mStateToken); } void PeersHandler::notifyPeerHasNewAvatar(std::string /*peer_id*/) { - RsStackMutex stack(mMtx); /********** STACK LOCKED MTX ******/ + RS_STACK_MUTEX(mMtx); // ********** LOCKED ********** mStateTokenServer->replaceToken(mStateToken); } @@ -295,7 +295,7 @@ void PeersHandler::tick() { mOnlinePeers = online; - RsStackMutex stack(mMtx); /********** STACK LOCKED MTX ******/ + RS_STACK_MUTEX(mMtx); // ********** LOCKED ********** mStateTokenServer->discardToken(mStateToken); mStateToken = mStateTokenServer->getNewToken(); } @@ -306,7 +306,7 @@ void PeersHandler::tick() { status = statusInfo.status; - RsStackMutex stack(mMtx); /********** STACK LOCKED MTX ******/ + RS_STACK_MUTEX(mMtx); // ********** LOCKED ********** mStateTokenServer->discardToken(mStringStateToken); mStringStateToken = mStateTokenServer->getNewToken(); } @@ -316,7 +316,7 @@ void PeersHandler::tick() { custom_state_string = custom_state; - RsStackMutex stack(mMtx); /********** STACK LOCKED MTX ******/ + RS_STACK_MUTEX(mMtx); // ********** LOCKED ********** mStateTokenServer->discardToken(mCustomStateToken); mCustomStateToken = mStateTokenServer->getNewToken(); } @@ -324,7 +324,7 @@ void PeersHandler::tick() void PeersHandler::notifyUnreadMsgCountChanged(const RsPeerId &peer, uint32_t count) { - RsStackMutex stack(mMtx); /********** STACK LOCKED MTX ******/ + RS_STACK_MUTEX(mMtx); // ********** LOCKED ********** mUnreadMsgsCounts[peer] = count; mStateTokenServer->replaceToken(mStateToken); } @@ -460,7 +460,7 @@ void PeersHandler::handleWildcard(Request &req, Response &resp) { std::map unread_msgs; { - RsStackMutex stack(mMtx); /********** STACK LOCKED MTX ******/ + RS_STACK_MUTEX(mMtx); // ********** LOCKED ********** unread_msgs = mUnreadMsgsCounts; } std::list statusInfo; @@ -1281,7 +1281,7 @@ void PeersHandler::handleSetNodeOptions(Request& req, Response& resp) StateToken PeersHandler::getCurrentStateToken() { - RsStackMutex stack(mMtx); /********** STACK LOCKED MTX ******/ + RS_STACK_MUTEX(mMtx); // ********** LOCKED ********** if(mStateToken.isNull()) mStateToken = mStateTokenServer->getNewToken(); return mStateToken; diff --git a/libresapi/src/api/RsControlModule.cpp b/libresapi/src/api/RsControlModule.cpp index 1e7f19b38..ebeadf986 100644 --- a/libresapi/src/api/RsControlModule.cpp +++ b/libresapi/src/api/RsControlModule.cpp @@ -57,7 +57,7 @@ RsControlModule::~RsControlModule() bool RsControlModule::processShouldExit() { - RsStackMutex stack(mExitFlagMtx); + RS_STACK_MUTEX(mExitFlagMtx); // ********** LOCKED ********** return mProcessShouldExit; } @@ -158,7 +158,7 @@ void RsControlModule::run() std::cerr << "RsControlModule::run() reseting passwd." << std::endl; #endif { - RsStackMutex stack(mDataMtx); // ********** LOCKED ********** + RS_STACK_MUTEX(mDataMtx); // ********** LOCKED ********** mPassword = ""; } @@ -182,7 +182,7 @@ void RsControlModule::run() std::cerr << "RsControlModule::run() while(wait_for_account_select) mLoadPeerId=" << mLoadPeerId << std::endl; #endif usleep(500*1000); - RsStackMutex stack(mDataMtx); // ********** LOCKED ********** + RS_STACK_MUTEX(mDataMtx); // ********** LOCKED ********** if(!mLoadPeerId.isNull()) { @@ -238,7 +238,7 @@ void RsControlModule::run() #endif { - RsStackMutex stack(mDataMtx); // ********** LOCKED ********** + RS_STACK_MUTEX(mDataMtx); // ********** LOCKED ********** mLoadPeerId.clear(); } } @@ -247,7 +247,7 @@ void RsControlModule::run() #endif { - RsStackMutex stack(mDataMtx); // ********** LOCKED ********** + RS_STACK_MUTEX(mDataMtx); // ********** LOCKED ********** mFixedPassword = mPassword; std::cerr << "***Reseting mPasswd " << std::endl; @@ -279,7 +279,7 @@ void RsControlModule::run() void RsControlModule::handleRunState(Request &, Response &resp) { - RsStackMutex stack(mDataMtx); // ********** LOCKED ********** + RS_STACK_MUTEX(mDataMtx); // ********** LOCKED ********** std::string state; switch(mRunState) { @@ -311,7 +311,7 @@ void RsControlModule::handleRunState(Request &, Response &resp) void RsControlModule::handleIdentities(Request &, Response &resp) { - RsStackMutex stack(mDataMtx); // ********** LOCKED ********** + RS_STACK_MUTEX(mDataMtx); // ********** LOCKED ********** if(mRunState == WAITING_INIT || mRunState == FATAL_ERROR) { resp.setFail("Retroshare is not initialised. Operation not possible."); @@ -337,7 +337,7 @@ void RsControlModule::handleIdentities(Request &, Response &resp) void RsControlModule::handleLocations(Request &, Response &resp) { - RsStackMutex stack(mDataMtx); // ********** LOCKED ********** + RS_STACK_MUTEX(mDataMtx); // ********** LOCKED ********** if(mRunState == WAITING_INIT || mRunState == FATAL_ERROR) { resp.setFail("Retroshare is not initialised. Operation not possible."); @@ -370,7 +370,7 @@ void RsControlModule::handleLocations(Request &, Response &resp) void RsControlModule::handlePassword(Request &req, Response &resp) { - RsStackMutex stack(mDataMtx); // ********** LOCKED ********** + RS_STACK_MUTEX(mDataMtx); // ********** LOCKED ********** std::string passwd; req.mStream << makeKeyValueReference("password", passwd); if(passwd != "")// && mWantPassword) @@ -398,7 +398,7 @@ void RsControlModule::handlePassword(Request &req, Response &resp) void RsControlModule::handleLogin(Request &req, Response &resp) { - RsStackMutex stack(mDataMtx); // ********** LOCKED ********** + RS_STACK_MUTEX(mDataMtx); // ********** LOCKED ********** if(mRunState != WAITING_ACCOUNT_SELECT) { resp.setFail("Operation not allowed in this runstate. Login is only allowed rigth after initialisation."); @@ -411,7 +411,7 @@ void RsControlModule::handleLogin(Request &req, Response &resp) void RsControlModule::handleShutdown(Request &, Response &resp) { - RsStackMutex stack(mExitFlagMtx); // ********** LOCKED ********** + RS_STACK_MUTEX(mExitFlagMtx); // ********** LOCKED ********** mProcessShouldExit = true; resp.setOk(); } @@ -514,7 +514,7 @@ void RsControlModule::handleCreateLocation(Request &req, Response &resp) std::string err_string; // give the password to the password callback { - RsStackMutex stack(mDataMtx); // ********** LOCKED ********** + RS_STACK_MUTEX(mDataMtx); // ********** LOCKED ********** mPassword = pgp_password; mFixedPassword = pgp_password; } @@ -522,7 +522,7 @@ void RsControlModule::handleCreateLocation(Request &req, Response &resp) // clear fixed password to restore normal password operation // { -// RsStackMutex stack(mDataMtx); // ********** LOCKED ********** +// RS_STACK_MUTEX(mDataMtx); // ********** LOCKED ********** // mFixedPassword = ""; // } @@ -532,7 +532,7 @@ void RsControlModule::handleCreateLocation(Request &req, Response &resp) RsInit::LoadPassword(ssl_password); // trigger login in init thread { - RsStackMutex stack(mDataMtx); // ********** LOCKED ********** + RS_STACK_MUTEX(mDataMtx); // ********** LOCKED ********** mLoadPeerId = ssl_id; } resp.mDataStream << makeKeyValueReference("pgp_id", pgp_id) @@ -561,7 +561,7 @@ bool RsControlModule::askForDeferredSelfSignature(const void *data, const uint32 void RsControlModule::setRunState(RunState s, std::string errstr) { - RsStackMutex stack(mDataMtx); // ********** LOCKED ********** + RS_STACK_MUTEX(mDataMtx); // ********** LOCKED ********** mRunState = s; mLastErrorString = errstr; mStateTokenServer->replaceToken(mStateToken); diff --git a/libresapi/src/api/StateTokenServer.cpp b/libresapi/src/api/StateTokenServer.cpp index b3c785bc6..6c113cdae 100644 --- a/libresapi/src/api/StateTokenServer.cpp +++ b/libresapi/src/api/StateTokenServer.cpp @@ -64,19 +64,19 @@ StateTokenServer::StateTokenServer(): StateToken StateTokenServer::getNewToken() { - RsStackMutex stack(mMtx); /********** STACK LOCKED MTX ******/ + RS_STACK_MUTEX(mMtx); // ********** LOCKED ********** return locked_getNewToken(); } void StateTokenServer::discardToken(StateToken token) { - RsStackMutex stack(mMtx); /********** STACK LOCKED MTX ******/ + RS_STACK_MUTEX(mMtx); // ********** LOCKED ********** locked_discardToken(token); } void StateTokenServer::replaceToken(StateToken &token) { - RsStackMutex stack(mMtx); /********** STACK LOCKED MTX ******/ + RS_STACK_MUTEX(mMtx); // ********** LOCKED ********** locked_discardToken(token); token = locked_getNewToken(); } @@ -89,13 +89,13 @@ void StateTokenServer::registerTickClient(Tickable *c) // avoid double registration unregisterTickClient(c); - RsStackMutex stack(mClientsMtx); /********** STACK LOCKED MTX ***********/ + RS_STACK_MUTEX(mClientsMtx); // ********** LOCKED ********** mTickClients.push_back(c); } void StateTokenServer::unregisterTickClient(Tickable *c) { - RsStackMutex stack(mClientsMtx); /********** STACK LOCKED MTX ***********/ + RS_STACK_MUTEX(mClientsMtx); // ********** LOCKED ********** std::vector::iterator vit = std::find(mTickClients.begin(), mTickClients.end(), c); if(vit != mTickClients.end()) mTickClients.erase(vit); @@ -104,14 +104,14 @@ void StateTokenServer::unregisterTickClient(Tickable *c) void StateTokenServer::handleWildcard(Request &req, Response &resp) { { - RsStackMutex stack(mClientsMtx); /********** STACK LOCKED MTX ***********/ + RS_STACK_MUTEX(mClientsMtx); // ********** LOCKED ********** for(std::vector::iterator vit = mTickClients.begin(); vit != mTickClients.end(); ++vit) { (*vit)->tick(); } } - RsStackMutex stack(mMtx); /********** STACK LOCKED MTX ******/ + RS_STACK_MUTEX(mMtx); // ********** LOCKED ********** // want to lookpup many tokens at once, return a list of invalid tokens // TODO: make generic list serialiser/deserialiser resp.mDataStream.getStreamToMember();