reduced number of calls to indicateConfigChanged(), and renamed mIngoingQueue into mIncomingQueue in GxsTrans

This commit is contained in:
csoler 2017-06-05 22:27:54 +02:00
parent b7c09bd6cf
commit 1e652d6577
2 changed files with 30 additions and 26 deletions

View File

@ -30,7 +30,7 @@ p3GxsTrans::~p3GxsTrans()
{ {
RS_STACK_MUTEX(mIngoingMutex); RS_STACK_MUTEX(mIngoingMutex);
for ( auto& kv : mIngoingQueue ) delete kv.second; for ( auto& kv : mIncomingQueue) delete kv.second;
} }
} }
@ -126,8 +126,9 @@ void p3GxsTrans::registerGxsTransClient(
void p3GxsTrans::handleResponse(uint32_t token, uint32_t req_type) void p3GxsTrans::handleResponse(uint32_t token, uint32_t req_type)
{ {
std::cout << "p3GxsTrans::handleResponse(" << token << ", " << req_type std::cout << "p3GxsTrans::handleResponse(" << token << ", " << req_type << ")" << std::endl;
<< ")" << std::endl; bool changed = false ;
switch (req_type) switch (req_type)
{ {
case GROUPS_LIST: case GROUPS_LIST:
@ -224,13 +225,14 @@ void p3GxsTrans::handleResponse(uint32_t token, uint32_t req_type)
case GxsTransItemsSubtypes::GXS_TRANS_SUBTYPE_MAIL: case GxsTransItemsSubtypes::GXS_TRANS_SUBTYPE_MAIL:
case GxsTransItemsSubtypes::GXS_TRANS_SUBTYPE_RECEIPT: case GxsTransItemsSubtypes::GXS_TRANS_SUBTYPE_RECEIPT:
{ {
RsGxsTransBaseItem* mb = RsGxsTransBaseItem* mb = dynamic_cast<RsGxsTransBaseItem*>(*mIt);
dynamic_cast<RsGxsTransBaseItem*>(*mIt);
if(mb) if(mb)
{ {
RS_STACK_MUTEX(mIngoingMutex); RS_STACK_MUTEX(mIngoingMutex);
mIngoingQueue.insert(inMap::value_type(mb->mailId, mb)); mIncomingQueue.insert(inMap::value_type(mb->mailId,mb));
IndicateConfigChanged();
changed = true ;
} }
else else
std::cerr << "p3GxsTrans::handleResponse(...) " std::cerr << "p3GxsTrans::handleResponse(...) "
@ -256,6 +258,9 @@ void p3GxsTrans::handleResponse(uint32_t token, uint32_t req_type)
<< req_type << std::endl; << req_type << std::endl;
break; break;
} }
if(changed)
IndicateConfigChanged();
} }
void p3GxsTrans::GxsTransIntegrityCleanupThread::getMessagesToDelete(GxsMsgReq& m) void p3GxsTrans::GxsTransIntegrityCleanupThread::getMessagesToDelete(GxsMsgReq& m)
@ -357,6 +362,7 @@ void p3GxsTrans::service_tick()
GxsTokenQueue::checkRequests(); GxsTokenQueue::checkRequests();
time_t now = time(NULL); time_t now = time(NULL);
bool changed = false ;
if(mLastMsgCleanup + MAX_DELAY_BETWEEN_CLEANUPS < now) if(mLastMsgCleanup + MAX_DELAY_BETWEEN_CLEANUPS < now)
{ {
@ -397,7 +403,6 @@ void p3GxsTrans::service_tick()
GxsTransSendStatus oldStatus = pr.status; GxsTransSendStatus oldStatus = pr.status;
locked_processOutgoingRecord(pr); locked_processOutgoingRecord(pr);
bool changed = false ;
if (oldStatus != pr.status) notifyClientService(pr); if (oldStatus != pr.status) notifyClientService(pr);
if( pr.status >= GxsTransSendStatus::RECEIPT_RECEIVED ) if( pr.status >= GxsTransSendStatus::RECEIPT_RECEIVED )
@ -406,19 +411,15 @@ void p3GxsTrans::service_tick()
changed = true ; changed = true ;
} }
else ++it; else ++it;
if(changed)
IndicateConfigChanged();
} }
} }
{ {
RS_STACK_MUTEX(mIngoingMutex); RS_STACK_MUTEX(mIngoingMutex);
for( auto it = mIngoingQueue.begin(); it != mIngoingQueue.end(); ) for( auto it = mIncomingQueue.begin(); it != mIncomingQueue.end(); )
{ {
switch(static_cast<GxsTransItemsSubtypes>( switch(static_cast<GxsTransItemsSubtypes>( it->second->PacketSubType()))
it->second->PacketSubType()))
{ {
case GxsTransItemsSubtypes::GXS_TRANS_SUBTYPE_MAIL: case GxsTransItemsSubtypes::GXS_TRANS_SUBTYPE_MAIL:
{ {
@ -479,12 +480,15 @@ void p3GxsTrans::service_tick()
break; break;
} }
delete it->second; it = mIngoingQueue.erase(it); delete it->second ;
it = mIncomingQueue.erase(it);
changed = true ;
}
}
if(changed)
IndicateConfigChanged(); IndicateConfigChanged();
} }
}
}
RsGenExchange::ServiceCreate_Return p3GxsTrans::service_CreateGroup( RsGenExchange::ServiceCreate_Return p3GxsTrans::service_CreateGroup(
RsGxsGrpItem* grpItem, RsTlvSecurityKeySet& /*keySet*/ ) RsGxsGrpItem* grpItem, RsTlvSecurityKeySet& /*keySet*/ )
@ -829,7 +833,7 @@ void p3GxsTrans::locked_processOutgoingRecord(OutgoingRecord& pr)
case GxsTransSendStatus::PENDING_RECEIPT_RECEIVE: case GxsTransSendStatus::PENDING_RECEIPT_RECEIVE:
{ {
RS_STACK_MUTEX(mIngoingMutex); RS_STACK_MUTEX(mIngoingMutex);
auto range = mIngoingQueue.equal_range(pr.mailItem.mailId); auto range = mIncomingQueue.equal_range(pr.mailItem.mailId);
bool changed = false ; bool changed = false ;
for( auto it = range.first; it != range.second; ++it) for( auto it = range.first; it != range.second; ++it)
@ -838,7 +842,7 @@ void p3GxsTrans::locked_processOutgoingRecord(OutgoingRecord& pr)
if(rt && mIdService.isOwnId(rt->meta.mAuthorId)) if(rt && mIdService.isOwnId(rt->meta.mAuthorId))
{ {
mIngoingQueue.erase(it); delete rt; mIncomingQueue.erase(it); delete rt;
pr.status = GxsTransSendStatus::RECEIPT_RECEIVED; pr.status = GxsTransSendStatus::RECEIPT_RECEIVED;
changed = true ; changed = true ;
@ -898,7 +902,7 @@ RsSerialiser* p3GxsTrans::setupSerialiser()
bool p3GxsTrans::saveList(bool &cleanup, std::list<RsItem *>& saveList) bool p3GxsTrans::saveList(bool &cleanup, std::list<RsItem *>& saveList)
{ {
std::cout << "p3GxsTrans::saveList(...)" << saveList.size() << " " << mIngoingQueue.size() << " " << mOutgoingQueue.size() << std::endl; std::cout << "p3GxsTrans::saveList(...)" << saveList.size() << " " << mIncomingQueue.size() << " " << mOutgoingQueue.size() << std::endl;
mOutgoingMutex.lock(); mOutgoingMutex.lock();
mIngoingMutex.lock(); mIngoingMutex.lock();
@ -908,13 +912,13 @@ bool p3GxsTrans::saveList(bool &cleanup, std::list<RsItem *>& saveList)
std::cerr << "Saving outgoing item, ID " << std::hex << std::setfill('0') << std::setw(16) << kv.first << std::dec << "Group id: " << kv.second.mailItem.meta.mGroupId << ", TS=" << kv.second.mailItem.meta.mPublishTs << std::endl; std::cerr << "Saving outgoing item, ID " << std::hex << std::setfill('0') << std::setw(16) << kv.first << std::dec << "Group id: " << kv.second.mailItem.meta.mGroupId << ", TS=" << kv.second.mailItem.meta.mPublishTs << std::endl;
saveList.push_back(&kv.second); saveList.push_back(&kv.second);
} }
for ( auto& kv : mIngoingQueue ) for ( auto& kv : mIncomingQueue )
{ {
std::cerr << "Saving incoming item, ID " << std::hex << std::setfill('0') << std::setw(16) << kv.first << std::endl; std::cerr << "Saving incoming item, ID " << std::hex << std::setfill('0') << std::setw(16) << kv.first << std::endl;
saveList.push_back(kv.second); saveList.push_back(kv.second);
} }
std::cout << "p3GxsTrans::saveList(...)" << saveList.size() << " " << mIngoingQueue.size() << " " << mOutgoingQueue.size() << std::endl; std::cout << "p3GxsTrans::saveList(...)" << saveList.size() << " " << mIncomingQueue.size() << " " << mOutgoingQueue.size() << std::endl;
cleanup = false; cleanup = false;
return true; return true;
@ -929,7 +933,7 @@ void p3GxsTrans::saveDone()
bool p3GxsTrans::loadList(std::list<RsItem *>&loadList) bool p3GxsTrans::loadList(std::list<RsItem *>&loadList)
{ {
std::cout << "p3GxsTrans::loadList(...) " << loadList.size() << " " std::cout << "p3GxsTrans::loadList(...) " << loadList.size() << " "
<< mIngoingQueue.size() << " " << mOutgoingQueue.size() << mIncomingQueue.size() << " " << mOutgoingQueue.size()
<< std::endl; << std::endl;
for(auto& v : loadList) for(auto& v : loadList)
@ -942,7 +946,7 @@ bool p3GxsTrans::loadList(std::list<RsItem *>&loadList)
if(mi) if(mi)
{ {
RS_STACK_MUTEX(mIngoingMutex); RS_STACK_MUTEX(mIngoingMutex);
mIngoingQueue.insert(inMap::value_type(mi->mailId, mi)); mIncomingQueue.insert(inMap::value_type(mi->mailId, mi));
} }
break; break;
} }
@ -971,7 +975,7 @@ bool p3GxsTrans::loadList(std::list<RsItem *>&loadList)
} }
std::cout << "p3GxsTrans::loadList(...) " << loadList.size() << " " std::cout << "p3GxsTrans::loadList(...) " << loadList.size() << " "
<< mIngoingQueue.size() << " " << mOutgoingQueue.size() << mIncomingQueue.size() << " " << mOutgoingQueue.size()
<< std::endl; << std::endl;
return true; return true;

View File

@ -205,7 +205,7 @@ private:
* for incoming queue. * for incoming queue.
*/ */
typedef std::unordered_multimap<RsGxsTransId, RsGxsTransBaseItem*> inMap; typedef std::unordered_multimap<RsGxsTransId, RsGxsTransBaseItem*> inMap;
inMap mIngoingQueue; inMap mIncomingQueue;
RsMutex mIngoingMutex; RsMutex mIngoingMutex;
/// @see GxsTokenQueue::handleResponse(uint32_t token, uint32_t req_type) /// @see GxsTokenQueue::handleResponse(uint32_t token, uint32_t req_type)