mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-12-25 15:39:27 -05:00
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:
parent
acc45a4382
commit
c8b3d4e527
@ -77,6 +77,12 @@ void RsServer::ConfigFinalSave()
|
||||
mConfigMgr->completeConfiguration();
|
||||
}
|
||||
|
||||
void RsServer::startServiceThread(RsThread *t)
|
||||
{
|
||||
t->start() ;
|
||||
mRegisteredServiceThreads.push_back(t) ;
|
||||
}
|
||||
|
||||
void RsServer::rsGlobalShutDown()
|
||||
{
|
||||
// TODO: cache should also clean up old files
|
||||
@ -89,17 +95,25 @@ void RsServer::rsGlobalShutDown()
|
||||
|
||||
join();
|
||||
|
||||
// kill all registered service threads
|
||||
|
||||
#ifdef RS_ENABLE_GXS
|
||||
if(mGxsCircles) mGxsCircles->join();
|
||||
if(mGxsForums) mGxsForums->join();
|
||||
if(mGxsChannels) mGxsChannels->join();
|
||||
if(mGxsIdService) mGxsIdService->join();
|
||||
if(mPosted) mPosted->join();
|
||||
if(mWiki) mWiki->join();
|
||||
//if(mPhoto) mPhoto->join();
|
||||
//if(mWire) mWire->join();
|
||||
#endif
|
||||
for(std::list<RsThread*>::iterator it= mRegisteredServiceThreads.begin();it!=mRegisteredServiceThreads.end();++it)
|
||||
{
|
||||
(*it)->join() ;
|
||||
}
|
||||
// #ifdef RS_ENABLE_GXS
|
||||
// // We should automate this.
|
||||
// //
|
||||
// if(mGxsCircles) mGxsCircles->join();
|
||||
// if(mGxsForums) mGxsForums->join();
|
||||
// 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();
|
||||
}
|
||||
|
@ -83,13 +83,13 @@ RsServer::RsServer()
|
||||
/* GXS - Amazingly we can still initialise these
|
||||
* even without knowing the data-types (they are just pointers???)
|
||||
*/
|
||||
mPhoto = NULL;
|
||||
mWiki = NULL;
|
||||
mPosted = NULL;
|
||||
mGxsCircles = NULL;
|
||||
mGxsIdService = NULL;
|
||||
mGxsForums = NULL;
|
||||
mWire = NULL;
|
||||
// mPhoto = NULL;
|
||||
// mWiki = NULL;
|
||||
// mPosted = NULL;
|
||||
// mGxsCircles = NULL;
|
||||
// mGxsIdService = NULL;
|
||||
// mGxsForums = NULL;
|
||||
// mWire = NULL;
|
||||
}
|
||||
|
||||
RsServer::~RsServer()
|
||||
|
@ -137,8 +137,8 @@ class RsServer: public RsControl, public RsThread
|
||||
/* Config */
|
||||
|
||||
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 *****************/
|
||||
|
||||
@ -178,15 +178,20 @@ class RsServer: public RsControl, public RsThread
|
||||
p3ChatService *chatSrv;
|
||||
p3StatusService *mStatusSrv;
|
||||
|
||||
/* GXS */
|
||||
p3Wiki *mWiki;
|
||||
p3Posted *mPosted;
|
||||
p3PhotoService *mPhoto;
|
||||
p3GxsCircles *mGxsCircles;
|
||||
p3IdService *mGxsIdService;
|
||||
p3GxsForums *mGxsForums;
|
||||
p3GxsChannels *mGxsChannels;
|
||||
p3Wire *mWire;
|
||||
// This list contains all threaded services. It will be used to shut them down properly.
|
||||
|
||||
std::list<RsThread*> mRegisteredServiceThreads ;
|
||||
|
||||
/* GXS */
|
||||
// p3Wiki *mWiki;
|
||||
// p3Posted *mPosted;
|
||||
// p3PhotoService *mPhoto;
|
||||
// p3GxsCircles *mGxsCircles;
|
||||
// p3GxsNetService *mGxsNetService;
|
||||
// p3IdService *mGxsIdService;
|
||||
// p3GxsForums *mGxsForums;
|
||||
// p3GxsChannels *mGxsChannels;
|
||||
// p3Wire *mWire;
|
||||
|
||||
/* Config */
|
||||
p3ConfigMgr *mConfigMgr;
|
||||
|
@ -1298,14 +1298,14 @@ int RsServer::StartupRetroShare()
|
||||
|
||||
// init gxs services
|
||||
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.
|
||||
RsGeneralDataService* gxscircles_ds = new RsDataService(currGxsDir + "/", "gxscircles_db",
|
||||
RS_SERVICE_GXS_TYPE_GXSCIRCLE, NULL, rsInitConfig->gxs_passwd);
|
||||
|
||||
// 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
|
||||
RsGxsNetService* gxsid_ns = new RsGxsNetService(
|
||||
@ -1333,7 +1333,7 @@ int RsServer::StartupRetroShare()
|
||||
RS_SERVICE_GXS_TYPE_POSTED,
|
||||
NULL, rsInitConfig->gxs_passwd);
|
||||
|
||||
mPosted = new p3Posted(posted_ds, NULL, mGxsIdService);
|
||||
p3Posted *mPosted = new p3Posted(posted_ds, NULL, mGxsIdService);
|
||||
|
||||
// create GXS photo service
|
||||
RsGxsNetService* posted_ns = new RsGxsNetService(
|
||||
@ -1351,7 +1351,7 @@ int RsServer::StartupRetroShare()
|
||||
RS_SERVICE_GXS_TYPE_WIKI,
|
||||
NULL, rsInitConfig->gxs_passwd);
|
||||
|
||||
mWiki = new p3Wiki(wiki_ds, NULL, mGxsIdService);
|
||||
p3Wiki *mWiki = new p3Wiki(wiki_ds, NULL, mGxsIdService);
|
||||
|
||||
// create GXS photo service
|
||||
RsGxsNetService* wiki_ns = new RsGxsNetService(
|
||||
@ -1368,7 +1368,7 @@ int RsServer::StartupRetroShare()
|
||||
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
|
||||
RsGxsNetService* gxsforums_ns = new RsGxsNetService(
|
||||
@ -1384,7 +1384,7 @@ int RsServer::StartupRetroShare()
|
||||
RsGeneralDataService* gxschannels_ds = new RsDataService(currGxsDir + "/", "gxschannels_db",
|
||||
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
|
||||
RsGxsNetService* gxschannels_ns = new RsGxsNetService(
|
||||
@ -1708,33 +1708,33 @@ int RsServer::StartupRetroShare()
|
||||
#ifdef RS_ENABLE_GXS
|
||||
|
||||
// Must Set the GXS pointers before starting threads.
|
||||
rsIdentity = mGxsIdService;
|
||||
rsGxsCircles = mGxsCircles;
|
||||
rsWiki = mWiki;
|
||||
rsPosted = mPosted;
|
||||
rsGxsForums = mGxsForums;
|
||||
rsGxsChannels = mGxsChannels;
|
||||
//rsPhoto = mPhoto;
|
||||
//rsWire = mWire;
|
||||
rsIdentity = mGxsIdService;
|
||||
rsGxsCircles = mGxsCircles;
|
||||
rsWiki = mWiki;
|
||||
rsPosted = mPosted;
|
||||
rsGxsForums = mGxsForums;
|
||||
rsGxsChannels = mGxsChannels;
|
||||
//rsPhoto = mPhoto;
|
||||
//rsWire = mWire;
|
||||
|
||||
/*** start up GXS core runner ***/
|
||||
createThread(*mGxsIdService);
|
||||
createThread(*mGxsCircles);
|
||||
createThread(*mPosted);
|
||||
createThread(*mWiki);
|
||||
createThread(*mGxsForums);
|
||||
createThread(*mGxsChannels);
|
||||
startServiceThread(mGxsIdService);
|
||||
startServiceThread(mGxsCircles);
|
||||
startServiceThread(mPosted);
|
||||
startServiceThread(mWiki);
|
||||
startServiceThread(mGxsForums);
|
||||
startServiceThread(mGxsChannels);
|
||||
|
||||
//createThread(*mPhoto);
|
||||
//createThread(*mWire);
|
||||
|
||||
// cores ready start up GXS net servers
|
||||
createThread(*gxsid_ns);
|
||||
createThread(*gxscircles_ns);
|
||||
createThread(*posted_ns);
|
||||
createThread(*wiki_ns);
|
||||
createThread(*gxsforums_ns);
|
||||
createThread(*gxschannels_ns);
|
||||
startServiceThread(gxsid_ns);
|
||||
startServiceThread(gxscircles_ns);
|
||||
startServiceThread(posted_ns);
|
||||
startServiceThread(wiki_ns);
|
||||
startServiceThread(gxsforums_ns);
|
||||
startServiceThread(gxschannels_ns);
|
||||
|
||||
//createThread(*photo_ns);
|
||||
//createThread(*wire_ns);
|
||||
@ -1781,7 +1781,7 @@ int RsServer::StartupRetroShare()
|
||||
}
|
||||
|
||||
/* Startup this thread! */
|
||||
createThread(*this);
|
||||
start() ;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
@ -49,57 +49,57 @@
|
||||
#include <iostream>
|
||||
#endif
|
||||
|
||||
extern "C" void* rsthread_init(void* p)
|
||||
void *RsThread::rsthread_init(void* p)
|
||||
{
|
||||
RsThread *thread = (RsThread *) p;
|
||||
if (!thread)
|
||||
{
|
||||
return 0;
|
||||
return NULL;
|
||||
}
|
||||
thread -> run();
|
||||
return 0;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
pthread_t createThread(RsThread &thread)
|
||||
void RsThread::start()
|
||||
{
|
||||
pthread_t tid;
|
||||
void *data = (void *) (&thread);
|
||||
void *data = (void *)this ;
|
||||
|
||||
thread.mMutex.lock();
|
||||
{
|
||||
RS_STACK_MUTEX(mMutex) ;
|
||||
|
||||
#if 0
|
||||
int ret;
|
||||
ret = pthread_attr_init(&tattr);
|
||||
if (doDetached)
|
||||
{
|
||||
ret = pthread_attr_setdetachstate(&tattr,PTHREAD_CREATE_DETACHED);
|
||||
}
|
||||
else
|
||||
{
|
||||
ret = pthread_attr_setdetachstate(&tattr,PTHREAD_CREATE_JOINABLE);
|
||||
}
|
||||
int ret;
|
||||
ret = pthread_attr_init(&tattr);
|
||||
if (doDetached)
|
||||
{
|
||||
ret = pthread_attr_setdetachstate(&tattr,PTHREAD_CREATE_DETACHED);
|
||||
}
|
||||
else
|
||||
{
|
||||
ret = pthread_attr_setdetachstate(&tattr,PTHREAD_CREATE_JOINABLE);
|
||||
}
|
||||
|
||||
pthread_create(&tid, &tattr, &rsthread_init, data);
|
||||
pthread_create(&tid, &tattr, &rsthread_init, data);
|
||||
#endif
|
||||
|
||||
int err ;
|
||||
int err ;
|
||||
|
||||
if( 0 == (err=pthread_create(&tid, 0, &rsthread_init, data)))
|
||||
thread.mTid = tid;
|
||||
else
|
||||
std::cerr << "Fatal error: pthread_create could not create a thread. Error returned: " << err << " !!!!!!!" << std::endl;
|
||||
if( 0 == (err=pthread_create(&tid, 0, &rsthread_init, data)))
|
||||
{
|
||||
mTid = tid;
|
||||
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")
|
||||
{
|
||||
mIsRunning = true;
|
||||
mIsRunning = false;
|
||||
|
||||
#ifdef WINDOWS_SYS
|
||||
memset (&mTid, 0, sizeof(mTid));
|
||||
|
@ -178,22 +178,25 @@ pthread_t createThread(RsThread &thread);
|
||||
|
||||
class RsThread
|
||||
{
|
||||
public:
|
||||
RsThread();
|
||||
virtual ~RsThread() {}
|
||||
public:
|
||||
RsThread();
|
||||
virtual ~RsThread() {}
|
||||
|
||||
virtual void start() { mIsRunning = true; createThread(*this); }
|
||||
virtual void run() = 0; /* called once the thread is started */
|
||||
virtual void join(); /* waits for the the mTid thread to stop */
|
||||
virtual void stop(); /* calls pthread_exit() */
|
||||
void start() ;
|
||||
void join(); /* waits for the the mTid thread to stop */
|
||||
void stop(); /* calls pthread_exit() */
|
||||
|
||||
bool isRunning();
|
||||
|
||||
pthread_t mTid;
|
||||
RsMutex mMutex;
|
||||
bool isRunning();
|
||||
|
||||
protected:
|
||||
virtual void run() = 0; /* called once the thread is started. Should be overloaded by subclasses. */
|
||||
private:
|
||||
bool mIsRunning;
|
||||
static void *rsthread_init(void*) ;
|
||||
|
||||
pthread_t mTid;
|
||||
RsMutex mMutex;
|
||||
|
||||
bool mIsRunning;
|
||||
};
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user