mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-01-20 20:31:46 -05:00
remove unneeded lock of p3ServiceServer mutex
This commit is contained in:
parent
7634d121de
commit
2c1238db2c
@ -1,5 +1,5 @@
|
|||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* libretroshare/src/pqi: pqiservice.h *
|
* libretroshare/src/pqi: pqiservice.cc *
|
||||||
* *
|
* *
|
||||||
* libretroshare: retroshare core library *
|
* libretroshare: retroshare core library *
|
||||||
* *
|
* *
|
||||||
@ -23,6 +23,22 @@
|
|||||||
#include "util/rsdebug.h"
|
#include "util/rsdebug.h"
|
||||||
#include "util/rsstring.h"
|
#include "util/rsstring.h"
|
||||||
|
|
||||||
|
#include <sstream>
|
||||||
|
#include <sys/time.h>
|
||||||
|
static double getCurrentTS()
|
||||||
|
{
|
||||||
|
#ifndef WINDOWS_SYS
|
||||||
|
struct timeval cts_tmp;
|
||||||
|
gettimeofday(&cts_tmp, NULL);
|
||||||
|
double cts = (cts_tmp.tv_sec) + ((double) cts_tmp.tv_usec) / 1000000.0;
|
||||||
|
#else
|
||||||
|
struct _timeb timebuf;
|
||||||
|
_ftime( &timebuf);
|
||||||
|
double cts = (timebuf.time) + ((double) timebuf.millitm) / 1000.0;
|
||||||
|
#endif
|
||||||
|
return cts;
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef SERVICE_DEBUG
|
#ifdef SERVICE_DEBUG
|
||||||
const int pqiservicezone = 60478;
|
const int pqiservicezone = 60478;
|
||||||
#endif
|
#endif
|
||||||
@ -44,7 +60,7 @@ bool pqiService::send(RsRawItem *item)
|
|||||||
|
|
||||||
p3ServiceServer::p3ServiceServer(pqiPublisher *pub, p3ServiceControl *ctrl) : mPublisher(pub), mServiceControl(ctrl), srvMtx("p3ServiceServer")
|
p3ServiceServer::p3ServiceServer(pqiPublisher *pub, p3ServiceControl *ctrl) : mPublisher(pub), mServiceControl(ctrl), srvMtx("p3ServiceServer")
|
||||||
{
|
{
|
||||||
RsStackMutex stack(srvMtx); /********* LOCKED *********/
|
RS_STACK_MUTEX(srvMtx); /********* LOCKED *********/
|
||||||
|
|
||||||
#ifdef SERVICE_DEBUG
|
#ifdef SERVICE_DEBUG
|
||||||
pqioutput(PQL_DEBUG_BASIC, pqiservicezone,
|
pqioutput(PQL_DEBUG_BASIC, pqiservicezone,
|
||||||
@ -56,7 +72,7 @@ p3ServiceServer::p3ServiceServer(pqiPublisher *pub, p3ServiceControl *ctrl) : mP
|
|||||||
|
|
||||||
int p3ServiceServer::addService(pqiService *ts, bool defaultOn)
|
int p3ServiceServer::addService(pqiService *ts, bool defaultOn)
|
||||||
{
|
{
|
||||||
RsStackMutex stack(srvMtx); /********* LOCKED *********/
|
RS_STACK_MUTEX(srvMtx); /********* LOCKED *********/
|
||||||
|
|
||||||
#ifdef SERVICE_DEBUG
|
#ifdef SERVICE_DEBUG
|
||||||
pqioutput(PQL_DEBUG_BASIC, pqiservicezone,
|
pqioutput(PQL_DEBUG_BASIC, pqiservicezone,
|
||||||
@ -84,7 +100,7 @@ int p3ServiceServer::addService(pqiService *ts, bool defaultOn)
|
|||||||
|
|
||||||
bool p3ServiceServer::getServiceItemNames(uint32_t service_type,std::map<uint8_t,std::string>& names)
|
bool p3ServiceServer::getServiceItemNames(uint32_t service_type,std::map<uint8_t,std::string>& names)
|
||||||
{
|
{
|
||||||
RsStackMutex stack(srvMtx); /********* LOCKED *********/
|
RS_STACK_MUTEX(srvMtx); /********* LOCKED *********/
|
||||||
|
|
||||||
std::map<uint32_t, pqiService *>::iterator it=services.find(service_type) ;
|
std::map<uint32_t, pqiService *>::iterator it=services.find(service_type) ;
|
||||||
|
|
||||||
@ -99,7 +115,7 @@ bool p3ServiceServer::getServiceItemNames(uint32_t service_type,std::map<uint8_t
|
|||||||
|
|
||||||
int p3ServiceServer::removeService(pqiService *ts)
|
int p3ServiceServer::removeService(pqiService *ts)
|
||||||
{
|
{
|
||||||
RsStackMutex stack(srvMtx); /********* LOCKED *********/
|
RS_STACK_MUTEX(srvMtx); /********* LOCKED *********/
|
||||||
|
|
||||||
#ifdef SERVICE_DEBUG
|
#ifdef SERVICE_DEBUG
|
||||||
pqioutput(PQL_DEBUG_BASIC, pqiservicezone, "p3ServiceServer::removeService()");
|
pqioutput(PQL_DEBUG_BASIC, pqiservicezone, "p3ServiceServer::removeService()");
|
||||||
@ -124,60 +140,33 @@ int p3ServiceServer::removeService(pqiService *ts)
|
|||||||
|
|
||||||
bool p3ServiceServer::recvItem(RsRawItem *item)
|
bool p3ServiceServer::recvItem(RsRawItem *item)
|
||||||
{
|
{
|
||||||
RsStackMutex stack(srvMtx); /********* LOCKED *********/
|
|
||||||
|
|
||||||
#ifdef SERVICE_DEBUG
|
|
||||||
std::cerr << "p3ServiceServer::incoming()";
|
|
||||||
std::cerr << std::endl;
|
|
||||||
|
|
||||||
{
|
|
||||||
std::string out;
|
|
||||||
rs_sprintf(out, "p3ServiceServer::incoming() PacketId: %x\nLooking for Service: %x\nItem:\n", item -> PacketId(), (item -> PacketId() & 0xffffff00));
|
|
||||||
item -> print_string(out);
|
|
||||||
std::cerr << out;
|
|
||||||
std::cerr << std::endl;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Packet Filtering.
|
// Packet Filtering.
|
||||||
// This doesn't need to be in Mutex.
|
// This doesn't need to be in Mutex.
|
||||||
if (!mServiceControl->checkFilter(item->PacketId() & 0xffffff00, item->PeerId()))
|
if (!mServiceControl->checkFilter(item->PacketId() & 0xffffff00, item->PeerId()))
|
||||||
{
|
{
|
||||||
#ifdef SERVICE_DEBUG
|
|
||||||
std::cerr << "p3ServiceServer::recvItem() Fails Filtering " << std::endl;
|
|
||||||
#endif
|
|
||||||
delete item;
|
delete item;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pqiService *s = NULL;
|
||||||
|
|
||||||
std::map<uint32_t, pqiService *>::iterator it;
|
// access the service map under mutex lock
|
||||||
it = services.find(item -> PacketId() & 0xffffff00);
|
|
||||||
if (it == services.end())
|
|
||||||
{
|
{
|
||||||
#ifdef SERVICE_DEBUG
|
RS_STACK_MUTEX(srvMtx);
|
||||||
std::cerr << "p3ServiceServer::incoming() Service: No Service - deleting";
|
auto it = services.find(item -> PacketId() & 0xffffff00);
|
||||||
std::cerr << std::endl;
|
if (it == services.end())
|
||||||
#endif
|
{
|
||||||
delete item;
|
delete item;
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
s = it->second;
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
// then call recv off mutex
|
||||||
#ifdef SERVICE_DEBUG
|
bool result = s->recv(item);
|
||||||
std::cerr << "p3ServiceServer::incoming() Sending to : " << (void *) it -> second;
|
return result;
|
||||||
std::cerr << std::endl;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return (it->second) -> recv(item);
|
|
||||||
}
|
|
||||||
|
|
||||||
delete item;
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool p3ServiceServer::sendItem(RsRawItem *item)
|
bool p3ServiceServer::sendItem(RsRawItem *item)
|
||||||
{
|
{
|
||||||
#ifdef SERVICE_DEBUG
|
#ifdef SERVICE_DEBUG
|
||||||
@ -204,40 +193,27 @@ bool p3ServiceServer::sendItem(RsRawItem *item)
|
|||||||
}
|
}
|
||||||
|
|
||||||
mPublisher->sendItem(item);
|
mPublisher->sendItem(item);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int p3ServiceServer::tick()
|
int p3ServiceServer::tick()
|
||||||
{
|
{
|
||||||
|
|
||||||
mServiceControl->tick();
|
mServiceControl->tick();
|
||||||
|
|
||||||
RsStackMutex stack(srvMtx); /********* LOCKED *********/
|
// make a copy of the service map
|
||||||
|
std::map<uint32_t,pqiService *> local_map;
|
||||||
#ifdef SERVICE_DEBUG
|
{
|
||||||
pqioutput(PQL_DEBUG_ALL, pqiservicezone,
|
RS_STACK_MUTEX(srvMtx);
|
||||||
"p3ServiceServer::tick()");
|
local_map=services;
|
||||||
#endif
|
|
||||||
|
|
||||||
std::map<uint32_t, pqiService *>::iterator it;
|
|
||||||
|
|
||||||
// from the beginning to where we started.
|
|
||||||
for(it = services.begin();it != services.end(); ++it)
|
|
||||||
{
|
|
||||||
|
|
||||||
#ifdef SERVICE_DEBUG
|
|
||||||
std::string out;
|
|
||||||
rs_sprintf(out, "p3ServiceServer::service id: %u -> Service: %p", it -> first, it -> second);
|
|
||||||
pqioutput(PQL_DEBUG_ALL, pqiservicezone, out);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// now we should actually tick the service.
|
|
||||||
(it -> second) -> tick();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// tick all services off mutex
|
||||||
|
for(auto it(local_map.begin());it!=local_map.end();++it)
|
||||||
|
{
|
||||||
|
(it->second)->tick();
|
||||||
|
}
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user