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

@ -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));

View file

@ -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;
};