moved rsGlobalShutDown from MainWindow::doQuit to main

rsGlobalShutDown now cleans the threads and some memory on exit

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@3028 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
thunder2 2010-05-29 15:14:25 +00:00
parent b80aef1228
commit 334c9b61d3
13 changed files with 61 additions and 16 deletions

View File

@ -267,12 +267,16 @@ void FileIndexMonitor::run()
{
updateCycle();
while(1)
while(m_bRun)
{
for(int i = 0; i < updatePeriod; i++)
{
if (m_bRun == false) {
return;
}
/********************************** WINDOWS/UNIX SPECIFIC PART ******************/
#ifndef WINDOWS_SYS
sleep(1);

View File

@ -207,7 +207,7 @@ void ftController::run()
/* check the queues */
uint32_t cnt = 0 ;
while(1)
while(m_bRun)
{
#ifdef WIN32
Sleep(1000);

View File

@ -49,7 +49,7 @@ void ftExtraList::run()
time_t cleanup = 0;
time_t now = 0;
while (1)
while (m_bRun)
{
#ifdef DEBUG_ELIST
//std::cerr << "ftExtraList::run() Iteration";

View File

@ -191,6 +191,37 @@ void ftServer::StartupThreads()
start();
}
void ftServer::StopThreads()
{
/* stop own thread */
join();
/* stop Dataplex */
mFtDataplex->join();
/* stop Controller thread */
mFtController->join();
/* stop Monitor Thread */
mFiMon->join();
/* self contained threads */
/* stop ExtraList Thread */
mFtExtra->join();
delete (mFtDataplex);
mFtDataplex = NULL;
delete (mFtController);
mFtController = NULL;
delete (mFiMon);
mFiMon = NULL;
delete (mFtExtra);
mFtExtra = NULL;
}
CacheStrapper *ftServer::getCacheStrapper()
{
return mCacheStrapper;
@ -203,7 +234,7 @@ CacheTransfer *ftServer::getCacheTransfer()
void ftServer::run()
{
while(1)
while(m_bRun)
{
mFtDataplex->deleteUnusedServers() ;
#ifdef WIN32

View File

@ -98,6 +98,7 @@ void SetupFtServer(NotifyBase *cb);
void connectToTurtleRouter(p3turtle *p) ;
void StartupThreads();
void StopThreads();
/* own thread */
virtual void run();

View File

@ -170,5 +170,7 @@ void RsServer::rsGlobalShutDown()
mChannels->cleanUpOldFiles();
ConfigFinalSave(); // save configuration before exit
mConnMgr->shutdown(); /* Handles UPnP */
}
join();
ftserver->StopThreads();
}

View File

@ -93,7 +93,7 @@ void RsServer::run()
int min = 0;
int loop = 0;
while(1)
while(m_bRun)
{
#ifndef WINDOWS_SYS
usleep((int) (timeDelta * 1000000));

View File

@ -1508,7 +1508,6 @@ bool RsInit::RsStoreAutoLogin()
DataIn.cbData = cbDataInput;
DataEnt.pbData = pbDataEnt;
DataEnt.cbData = cbDataEnt;
LPWSTR pDescrOut = NULL;
CRYPTPROTECT_PROMPTSTRUCT prom;

View File

@ -258,7 +258,7 @@ void UdpLayer::recv_loop()
int status;
struct timeval timeout;
while(1)
while(m_bRun)
{
/* select on the socket TODO */
fd_set rset;

View File

@ -80,8 +80,15 @@ pthread_t createThread(RsThread &thread)
}
RsThread::RsThread ()
{
m_bRun = true;
}
void RsThread::join() /* waits for the the mTid thread to stop */
{
m_bRun = false;
void *ptr;
pthread_join(mTid, &ptr);
}
@ -100,7 +107,7 @@ RsQueueThread::RsQueueThread(uint32_t min, uint32_t max, double relaxFactor )
void RsQueueThread::run()
{
while(1)
while(m_bRun)
{
bool doneWork = false;
while(workQueued() && doWork())

View File

@ -145,8 +145,8 @@ pthread_t createThread(RsThread &thread);
class RsThread
{
public:
RsThread() { return; }
virtual ~RsThread() { return; }
RsThread();
virtual ~RsThread() {}
virtual void start() { createThread(*this); }
virtual void run() = 0; /* called once the thread is started */
@ -155,6 +155,8 @@ virtual void stop(); /* calls pthread_exit() */
pthread_t mTid;
RsMutex mMutex;
protected:
bool m_bRun;
};

View File

@ -638,14 +638,12 @@ void MainWindow::doQuit()
if ((QMessageBox::question(this, tr("Really quit ? "),queryWrn,QMessageBox::Yes|QMessageBox::No, QMessageBox::Yes))== QMessageBox::Yes)
{
rsicontrol->rsGlobalShutDown();
qApp->quit();
}
else
return;
return;
}
else
rsicontrol->rsGlobalShutDown();
rApp->quit();
}

View File

@ -180,10 +180,11 @@ int main(int argc, char *argv[])
timer->start(1000);
/* dive into the endless loop */
// return ret;
int ti = rshare.exec();
delete w ;
rsicontrol->rsGlobalShutDown();
Settings->sync();
delete Settings;