improved RsServer so that join() is called on every running thread at shutdown, hence avoiding SIGSEGV. Removed some unused members of RsServer

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@7776 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
csoler 2014-12-21 20:52:34 +00:00
parent acc45a4382
commit c8b3d4e527
6 changed files with 118 additions and 96 deletions

View File

@ -77,6 +77,12 @@ void RsServer::ConfigFinalSave()
mConfigMgr->completeConfiguration(); mConfigMgr->completeConfiguration();
} }
void RsServer::startServiceThread(RsThread *t)
{
t->start() ;
mRegisteredServiceThreads.push_back(t) ;
}
void RsServer::rsGlobalShutDown() void RsServer::rsGlobalShutDown()
{ {
// TODO: cache should also clean up old files // TODO: cache should also clean up old files
@ -89,17 +95,25 @@ void RsServer::rsGlobalShutDown()
join(); join();
// kill all registered service threads
#ifdef RS_ENABLE_GXS for(std::list<RsThread*>::iterator it= mRegisteredServiceThreads.begin();it!=mRegisteredServiceThreads.end();++it)
if(mGxsCircles) mGxsCircles->join(); {
if(mGxsForums) mGxsForums->join(); (*it)->join() ;
if(mGxsChannels) mGxsChannels->join(); }
if(mGxsIdService) mGxsIdService->join(); // #ifdef RS_ENABLE_GXS
if(mPosted) mPosted->join(); // // We should automate this.
if(mWiki) mWiki->join(); // //
//if(mPhoto) mPhoto->join(); // if(mGxsCircles) mGxsCircles->join();
//if(mWire) mWire->join(); // if(mGxsForums) mGxsForums->join();
#endif // if(mGxsChannels) mGxsChannels->join();
// if(mGxsIdService) mGxsIdService->join();
// if(mPosted) mPosted->join();
// if(mWiki) mWiki->join();
// if(mGxsNetService) mGxsNetService->join();
// if(mPhoto) mPhoto->join();
// if(mWire) mWire->join();
// #endif
AuthGPG::exit(); AuthGPG::exit();
} }

View File

@ -83,13 +83,13 @@ RsServer::RsServer()
/* GXS - Amazingly we can still initialise these /* GXS - Amazingly we can still initialise these
* even without knowing the data-types (they are just pointers???) * even without knowing the data-types (they are just pointers???)
*/ */
mPhoto = NULL; // mPhoto = NULL;
mWiki = NULL; // mWiki = NULL;
mPosted = NULL; // mPosted = NULL;
mGxsCircles = NULL; // mGxsCircles = NULL;
mGxsIdService = NULL; // mGxsIdService = NULL;
mGxsForums = NULL; // mGxsForums = NULL;
mWire = NULL; // mWire = NULL;
} }
RsServer::~RsServer() RsServer::~RsServer()

View File

@ -137,8 +137,8 @@ class RsServer: public RsControl, public RsThread
/* Config */ /* Config */
virtual int ConfigSetBootPrompt( bool on ); virtual int ConfigSetBootPrompt( bool on );
virtual void ConfigFinalSave( );
virtual void ConfigFinalSave( ); virtual void startServiceThread(RsThread *t) ;
/************* Rs shut down function: in upnp 'port lease time' bug *****************/ /************* Rs shut down function: in upnp 'port lease time' bug *****************/
@ -178,15 +178,20 @@ class RsServer: public RsControl, public RsThread
p3ChatService *chatSrv; p3ChatService *chatSrv;
p3StatusService *mStatusSrv; p3StatusService *mStatusSrv;
/* GXS */ // This list contains all threaded services. It will be used to shut them down properly.
p3Wiki *mWiki;
p3Posted *mPosted; std::list<RsThread*> mRegisteredServiceThreads ;
p3PhotoService *mPhoto;
p3GxsCircles *mGxsCircles; /* GXS */
p3IdService *mGxsIdService; // p3Wiki *mWiki;
p3GxsForums *mGxsForums; // p3Posted *mPosted;
p3GxsChannels *mGxsChannels; // p3PhotoService *mPhoto;
p3Wire *mWire; // p3GxsCircles *mGxsCircles;
// p3GxsNetService *mGxsNetService;
// p3IdService *mGxsIdService;
// p3GxsForums *mGxsForums;
// p3GxsChannels *mGxsChannels;
// p3Wire *mWire;
/* Config */ /* Config */
p3ConfigMgr *mConfigMgr; p3ConfigMgr *mConfigMgr;

View File

@ -1298,14 +1298,14 @@ int RsServer::StartupRetroShare()
// init gxs services // init gxs services
PgpAuxUtils *pgpAuxUtils = new PgpAuxUtilsImpl(); PgpAuxUtils *pgpAuxUtils = new PgpAuxUtilsImpl();
mGxsIdService = new p3IdService(gxsid_ds, NULL, pgpAuxUtils); p3IdService *mGxsIdService = new p3IdService(gxsid_ds, NULL, pgpAuxUtils);
// circles created here, as needed by Ids. // circles created here, as needed by Ids.
RsGeneralDataService* gxscircles_ds = new RsDataService(currGxsDir + "/", "gxscircles_db", RsGeneralDataService* gxscircles_ds = new RsDataService(currGxsDir + "/", "gxscircles_db",
RS_SERVICE_GXS_TYPE_GXSCIRCLE, NULL, rsInitConfig->gxs_passwd); RS_SERVICE_GXS_TYPE_GXSCIRCLE, NULL, rsInitConfig->gxs_passwd);
// create GxsCircles - early, as IDs need it. // create GxsCircles - early, as IDs need it.
mGxsCircles = new p3GxsCircles(gxscircles_ds, NULL, mGxsIdService, pgpAuxUtils); p3GxsCircles *mGxsCircles = new p3GxsCircles(gxscircles_ds, NULL, mGxsIdService, pgpAuxUtils);
// create GXS ID service // create GXS ID service
RsGxsNetService* gxsid_ns = new RsGxsNetService( RsGxsNetService* gxsid_ns = new RsGxsNetService(
@ -1333,7 +1333,7 @@ int RsServer::StartupRetroShare()
RS_SERVICE_GXS_TYPE_POSTED, RS_SERVICE_GXS_TYPE_POSTED,
NULL, rsInitConfig->gxs_passwd); NULL, rsInitConfig->gxs_passwd);
mPosted = new p3Posted(posted_ds, NULL, mGxsIdService); p3Posted *mPosted = new p3Posted(posted_ds, NULL, mGxsIdService);
// create GXS photo service // create GXS photo service
RsGxsNetService* posted_ns = new RsGxsNetService( RsGxsNetService* posted_ns = new RsGxsNetService(
@ -1351,7 +1351,7 @@ int RsServer::StartupRetroShare()
RS_SERVICE_GXS_TYPE_WIKI, RS_SERVICE_GXS_TYPE_WIKI,
NULL, rsInitConfig->gxs_passwd); NULL, rsInitConfig->gxs_passwd);
mWiki = new p3Wiki(wiki_ds, NULL, mGxsIdService); p3Wiki *mWiki = new p3Wiki(wiki_ds, NULL, mGxsIdService);
// create GXS photo service // create GXS photo service
RsGxsNetService* wiki_ns = new RsGxsNetService( RsGxsNetService* wiki_ns = new RsGxsNetService(
@ -1368,7 +1368,7 @@ int RsServer::StartupRetroShare()
RS_SERVICE_GXS_TYPE_FORUMS, NULL, rsInitConfig->gxs_passwd); RS_SERVICE_GXS_TYPE_FORUMS, NULL, rsInitConfig->gxs_passwd);
mGxsForums = new p3GxsForums(gxsforums_ds, NULL, mGxsIdService); p3GxsForums *mGxsForums = new p3GxsForums(gxsforums_ds, NULL, mGxsIdService);
// create GXS photo service // create GXS photo service
RsGxsNetService* gxsforums_ns = new RsGxsNetService( RsGxsNetService* gxsforums_ns = new RsGxsNetService(
@ -1384,7 +1384,7 @@ int RsServer::StartupRetroShare()
RsGeneralDataService* gxschannels_ds = new RsDataService(currGxsDir + "/", "gxschannels_db", RsGeneralDataService* gxschannels_ds = new RsDataService(currGxsDir + "/", "gxschannels_db",
RS_SERVICE_GXS_TYPE_CHANNELS, NULL, rsInitConfig->gxs_passwd); RS_SERVICE_GXS_TYPE_CHANNELS, NULL, rsInitConfig->gxs_passwd);
mGxsChannels = new p3GxsChannels(gxschannels_ds, NULL, mGxsIdService); p3GxsChannels *mGxsChannels = new p3GxsChannels(gxschannels_ds, NULL, mGxsIdService);
// create GXS photo service // create GXS photo service
RsGxsNetService* gxschannels_ns = new RsGxsNetService( RsGxsNetService* gxschannels_ns = new RsGxsNetService(
@ -1708,33 +1708,33 @@ int RsServer::StartupRetroShare()
#ifdef RS_ENABLE_GXS #ifdef RS_ENABLE_GXS
// Must Set the GXS pointers before starting threads. // Must Set the GXS pointers before starting threads.
rsIdentity = mGxsIdService; rsIdentity = mGxsIdService;
rsGxsCircles = mGxsCircles; rsGxsCircles = mGxsCircles;
rsWiki = mWiki; rsWiki = mWiki;
rsPosted = mPosted; rsPosted = mPosted;
rsGxsForums = mGxsForums; rsGxsForums = mGxsForums;
rsGxsChannels = mGxsChannels; rsGxsChannels = mGxsChannels;
//rsPhoto = mPhoto; //rsPhoto = mPhoto;
//rsWire = mWire; //rsWire = mWire;
/*** start up GXS core runner ***/ /*** start up GXS core runner ***/
createThread(*mGxsIdService); startServiceThread(mGxsIdService);
createThread(*mGxsCircles); startServiceThread(mGxsCircles);
createThread(*mPosted); startServiceThread(mPosted);
createThread(*mWiki); startServiceThread(mWiki);
createThread(*mGxsForums); startServiceThread(mGxsForums);
createThread(*mGxsChannels); startServiceThread(mGxsChannels);
//createThread(*mPhoto); //createThread(*mPhoto);
//createThread(*mWire); //createThread(*mWire);
// cores ready start up GXS net servers // cores ready start up GXS net servers
createThread(*gxsid_ns); startServiceThread(gxsid_ns);
createThread(*gxscircles_ns); startServiceThread(gxscircles_ns);
createThread(*posted_ns); startServiceThread(posted_ns);
createThread(*wiki_ns); startServiceThread(wiki_ns);
createThread(*gxsforums_ns); startServiceThread(gxsforums_ns);
createThread(*gxschannels_ns); startServiceThread(gxschannels_ns);
//createThread(*photo_ns); //createThread(*photo_ns);
//createThread(*wire_ns); //createThread(*wire_ns);
@ -1781,7 +1781,7 @@ int RsServer::StartupRetroShare()
} }
/* Startup this thread! */ /* Startup this thread! */
createThread(*this); start() ;
return 1; return 1;
} }

View File

@ -49,57 +49,57 @@
#include <iostream> #include <iostream>
#endif #endif
extern "C" void* rsthread_init(void* p) void *RsThread::rsthread_init(void* p)
{ {
RsThread *thread = (RsThread *) p; RsThread *thread = (RsThread *) p;
if (!thread) if (!thread)
{ {
return 0; return NULL;
} }
thread -> run(); thread -> run();
return 0; return NULL;
} }
void RsThread::start()
pthread_t createThread(RsThread &thread)
{ {
pthread_t tid; pthread_t tid;
void *data = (void *) (&thread); void *data = (void *)this ;
thread.mMutex.lock(); RS_STACK_MUTEX(mMutex) ;
{
#if 0 #if 0
int ret; int ret;
ret = pthread_attr_init(&tattr); ret = pthread_attr_init(&tattr);
if (doDetached) if (doDetached)
{ {
ret = pthread_attr_setdetachstate(&tattr,PTHREAD_CREATE_DETACHED); ret = pthread_attr_setdetachstate(&tattr,PTHREAD_CREATE_DETACHED);
} }
else else
{ {
ret = pthread_attr_setdetachstate(&tattr,PTHREAD_CREATE_JOINABLE); ret = pthread_attr_setdetachstate(&tattr,PTHREAD_CREATE_JOINABLE);
} }
pthread_create(&tid, &tattr, &rsthread_init, data); pthread_create(&tid, &tattr, &rsthread_init, data);
#endif #endif
int err ; int err ;
if( 0 == (err=pthread_create(&tid, 0, &rsthread_init, data))) if( 0 == (err=pthread_create(&tid, 0, &rsthread_init, data)))
thread.mTid = tid; {
else mTid = tid;
std::cerr << "Fatal error: pthread_create could not create a thread. Error returned: " << err << " !!!!!!!" << std::endl; mIsRunning = true ;
}
else
{
std::cerr << "Fatal error: pthread_create could not create a thread. Error returned: " << err << " !!!!!!!" << std::endl;
mIsRunning = false ;
} }
thread.mMutex.unlock();
return tid;
} }
RsThread::RsThread () : mMutex("RsThread") RsThread::RsThread () : mMutex("RsThread")
{ {
mIsRunning = true; mIsRunning = false;
#ifdef WINDOWS_SYS #ifdef WINDOWS_SYS
memset (&mTid, 0, sizeof(mTid)); memset (&mTid, 0, sizeof(mTid));

View File

@ -178,22 +178,25 @@ pthread_t createThread(RsThread &thread);
class RsThread class RsThread
{ {
public: public:
RsThread(); RsThread();
virtual ~RsThread() {} virtual ~RsThread() {}
virtual void start() { mIsRunning = true; createThread(*this); } void start() ;
virtual void run() = 0; /* called once the thread is started */ void join(); /* waits for the the mTid thread to stop */
virtual void join(); /* waits for the the mTid thread to stop */ void stop(); /* calls pthread_exit() */
virtual void stop(); /* calls pthread_exit() */
bool isRunning(); bool isRunning();
pthread_t mTid;
RsMutex mMutex;
protected:
virtual void run() = 0; /* called once the thread is started. Should be overloaded by subclasses. */
private: private:
bool mIsRunning; static void *rsthread_init(void*) ;
pthread_t mTid;
RsMutex mMutex;
bool mIsRunning;
}; };