mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-06-20 20:34:25 -04:00
Fixed deadlock when receiving a chat message with open history browser.
git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@5042 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
d765721e83
commit
9f627783aa
1 changed files with 75 additions and 65 deletions
|
@ -53,66 +53,74 @@ p3HistoryMgr::~p3HistoryMgr()
|
||||||
|
|
||||||
void p3HistoryMgr::addMessage(bool incoming, const std::string &chatPeerId, const std::string &peerId, const RsChatMsgItem *chatItem)
|
void p3HistoryMgr::addMessage(bool incoming, const std::string &chatPeerId, const std::string &peerId, const RsChatMsgItem *chatItem)
|
||||||
{
|
{
|
||||||
RsStackMutex stack(mHistoryMtx); /********** STACK LOCKED MTX ******/
|
uint32_t addMsgId = 0;
|
||||||
|
|
||||||
if (mPublicEnable == false && chatPeerId.empty()) {
|
{
|
||||||
// public chat not enabled
|
RsStackMutex stack(mHistoryMtx); /********** STACK LOCKED MTX ******/
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mPrivateEnable == false && chatPeerId.empty() == false) {
|
if (mPublicEnable == false && chatPeerId.empty()) {
|
||||||
// private chat not enabled
|
// public chat not enabled
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
const RsChatLobbyMsgItem *cli = dynamic_cast<const RsChatLobbyMsgItem*>(chatItem);
|
|
||||||
|
|
||||||
if (cli) {
|
|
||||||
// disable history for chat lobbies until they are saved
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
RsHistoryMsgItem* item = new RsHistoryMsgItem;
|
|
||||||
item->chatPeerId = chatPeerId;
|
|
||||||
item->incoming = incoming;
|
|
||||||
item->peerId = peerId;
|
|
||||||
item->peerName = cli ? cli->nick : rsPeers->getPeerName(item->peerId);
|
|
||||||
item->sendTime = chatItem->sendTime;
|
|
||||||
item->recvTime = chatItem->recvTime;
|
|
||||||
|
|
||||||
librs::util::ConvertUtf16ToUtf8(chatItem->message, item->message);
|
|
||||||
|
|
||||||
std::map<std::string, std::map<uint32_t, RsHistoryMsgItem*> >::iterator mit = mMessages.find(item->chatPeerId);
|
|
||||||
if (mit != mMessages.end()) {
|
|
||||||
item->msgId = nextMsgId++;
|
|
||||||
mit->second.insert(std::make_pair(item->msgId, item));
|
|
||||||
|
|
||||||
// check the limit
|
|
||||||
uint32_t limit;
|
|
||||||
if (chatPeerId.empty()) {
|
|
||||||
limit = mPublicSaveCount;
|
|
||||||
} else {
|
|
||||||
limit = mPrivateSaveCount;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (limit) {
|
if (mPrivateEnable == false && chatPeerId.empty() == false) {
|
||||||
while (mit->second.size() > limit) {
|
// private chat not enabled
|
||||||
delete(mit->second.begin()->second);
|
return;
|
||||||
mit->second.erase(mit->second.begin());
|
}
|
||||||
|
|
||||||
|
const RsChatLobbyMsgItem *cli = dynamic_cast<const RsChatLobbyMsgItem*>(chatItem);
|
||||||
|
|
||||||
|
if (cli) {
|
||||||
|
// disable history for chat lobbies until they are saved
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
RsHistoryMsgItem* item = new RsHistoryMsgItem;
|
||||||
|
item->chatPeerId = chatPeerId;
|
||||||
|
item->incoming = incoming;
|
||||||
|
item->peerId = peerId;
|
||||||
|
item->peerName = cli ? cli->nick : rsPeers->getPeerName(item->peerId);
|
||||||
|
item->sendTime = chatItem->sendTime;
|
||||||
|
item->recvTime = chatItem->recvTime;
|
||||||
|
|
||||||
|
librs::util::ConvertUtf16ToUtf8(chatItem->message, item->message);
|
||||||
|
|
||||||
|
std::map<std::string, std::map<uint32_t, RsHistoryMsgItem*> >::iterator mit = mMessages.find(item->chatPeerId);
|
||||||
|
if (mit != mMessages.end()) {
|
||||||
|
item->msgId = nextMsgId++;
|
||||||
|
mit->second.insert(std::make_pair(item->msgId, item));
|
||||||
|
addMsgId = item->msgId;
|
||||||
|
|
||||||
|
// check the limit
|
||||||
|
uint32_t limit;
|
||||||
|
if (chatPeerId.empty()) {
|
||||||
|
limit = mPublicSaveCount;
|
||||||
|
} else {
|
||||||
|
limit = mPrivateSaveCount;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
} else {
|
|
||||||
std::map<uint32_t, RsHistoryMsgItem*> msgs;
|
|
||||||
item->msgId = nextMsgId++;
|
|
||||||
msgs.insert(std::make_pair(item->msgId, item));
|
|
||||||
mMessages.insert(std::make_pair(item->chatPeerId, msgs));
|
|
||||||
|
|
||||||
// no need to check the limit
|
if (limit) {
|
||||||
|
while (mit->second.size() > limit) {
|
||||||
|
delete(mit->second.begin()->second);
|
||||||
|
mit->second.erase(mit->second.begin());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
std::map<uint32_t, RsHistoryMsgItem*> msgs;
|
||||||
|
item->msgId = nextMsgId++;
|
||||||
|
msgs.insert(std::make_pair(item->msgId, item));
|
||||||
|
mMessages.insert(std::make_pair(item->chatPeerId, msgs));
|
||||||
|
addMsgId = item->msgId;
|
||||||
|
|
||||||
|
// no need to check the limit
|
||||||
|
}
|
||||||
|
|
||||||
|
IndicateConfigChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
IndicateConfigChanged();
|
if (addMsgId) {
|
||||||
|
rsicontrol->getNotify().notifyHistoryChanged(addMsgId, NOTIFY_TYPE_ADD);
|
||||||
rsicontrol->getNotify().notifyHistoryChanged(item->msgId, NOTIFY_TYPE_ADD);
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/***** p3Config *****/
|
/***** p3Config *****/
|
||||||
|
@ -320,22 +328,24 @@ bool p3HistoryMgr::getMessage(uint32_t msgId, HistoryMsg &msg)
|
||||||
|
|
||||||
void p3HistoryMgr::clear(const std::string &chatPeerId)
|
void p3HistoryMgr::clear(const std::string &chatPeerId)
|
||||||
{
|
{
|
||||||
RsStackMutex stack(mHistoryMtx); /********** STACK LOCKED MTX ******/
|
{
|
||||||
|
RsStackMutex stack(mHistoryMtx); /********** STACK LOCKED MTX ******/
|
||||||
|
|
||||||
std::map<std::string, std::map<uint32_t, RsHistoryMsgItem*> >::iterator mit = mMessages.find(chatPeerId);
|
std::map<std::string, std::map<uint32_t, RsHistoryMsgItem*> >::iterator mit = mMessages.find(chatPeerId);
|
||||||
if (mit == mMessages.end()) {
|
if (mit == mMessages.end()) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::map<uint32_t, RsHistoryMsgItem*>::iterator lit;
|
||||||
|
for (lit = mit->second.begin(); lit != mit->second.end(); lit++) {
|
||||||
|
delete(lit->second);
|
||||||
|
}
|
||||||
|
mit->second.clear();
|
||||||
|
mMessages.erase(mit);
|
||||||
|
|
||||||
|
IndicateConfigChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::map<uint32_t, RsHistoryMsgItem*>::iterator lit;
|
|
||||||
for (lit = mit->second.begin(); lit != mit->second.end(); lit++) {
|
|
||||||
delete(lit->second);
|
|
||||||
}
|
|
||||||
mit->second.clear();
|
|
||||||
mMessages.erase(mit);
|
|
||||||
|
|
||||||
IndicateConfigChanged();
|
|
||||||
|
|
||||||
rsicontrol->getNotify().notifyHistoryChanged(0, NOTIFY_TYPE_MOD);
|
rsicontrol->getNotify().notifyHistoryChanged(0, NOTIFY_TYPE_MOD);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue