created 2 subclasses of RsThread, one for ticking services, and one for single shot jobs. Now all threads use the same base code.

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@8288 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
csoler 2015-05-22 20:54:38 +00:00
parent f2d4a237ca
commit e9b9dce9f5
28 changed files with 317 additions and 335 deletions

View file

@ -115,6 +115,7 @@ ftController::ftController(CacheStrapper *cs, ftDataMultiplex *dm, p3ServiceCont
_max_active_downloads = 5 ; // default queue size
_min_prioritized_transfers = 3 ;
/* TODO */
cnt = 0 ;
}
void ftController::setTurtleRouter(p3turtle *pt) { mTurtle = pt ; }
@ -209,14 +210,10 @@ void ftController::removeFileSource(const RsFileHash& hash,const RsPeerId& peer_
std::cerr << "... not added: hash not found." << std::endl ;
#endif
}
void ftController::run()
void ftController::data_tick()
{
/* check the queues */
uint32_t cnt = 0 ;
while(isRunning())
{
//Waiting 1 sec before start
usleep(1*1000*1000); // 1 sec
@ -276,8 +273,6 @@ void ftController::run()
if(cnt++ % 10 == 0)
checkDownloadQueue() ;
}
}
void ftController::searchForDirectSources()

View file

@ -113,7 +113,7 @@ class ftPendingRequest
};
class ftController: public CacheTransfer, public RsThread, public pqiServiceMonitor, public p3Config
class ftController: public CacheTransfer, public RsTickingThread, public pqiServiceMonitor, public p3Config
{
public:
@ -126,7 +126,7 @@ class ftController: public CacheTransfer, public RsThread, public pqiServiceMoni
bool activate();
bool isActiveAndNoPending();
virtual void run();
virtual void data_tick();
/***************************************************************/
/********************** Controller Access **********************/
@ -243,6 +243,7 @@ class ftController: public CacheTransfer, public RsThread, public pqiServiceMoni
p3ServiceControl *mServiceCtrl;
uint32_t mFtServiceId;
uint32_t cnt ;
RsMutex ctrlMutex;
std::map<RsFileHash, ftFileControl*> mCompleted;

View file

@ -43,60 +43,55 @@
ftExtraList::ftExtraList()
:p3Config(), extMutex("p3Config")
{
return;
cleanup = 0;
return;
}
void ftExtraList::run()
void ftExtraList::data_tick()
{
bool todo = false;
time_t cleanup = 0;
time_t now = 0;
bool todo = false;
time_t now = time(NULL);
while (isRunning())
{
#ifdef DEBUG_ELIST
//std::cerr << "ftExtraList::run() Iteration";
//std::cerr << std::endl;
//std::cerr << "ftExtraList::run() Iteration";
//std::cerr << std::endl;
#endif
now = time(NULL);
{
RsStackMutex stack(extMutex);
{
RsStackMutex stack(extMutex);
todo = (mToHash.size() > 0);
}
todo = (mToHash.size() > 0);
}
if (todo)
{
/* Hash a file */
hashAFile();
if (todo)
{
/* Hash a file */
hashAFile();
#ifdef WIN32
Sleep(1);
Sleep(1);
#else
/* microsleep */
usleep(10);
/* microsleep */
usleep(10);
#endif
}
else
{
/* cleanup */
if (cleanup < now)
{
cleanupOldFiles();
cleanup = now + CLEANUP_PERIOD;
}
}
else
{
/* cleanup */
if (cleanup < now)
{
cleanupOldFiles();
cleanup = now + CLEANUP_PERIOD;
}
/* sleep */
/* sleep */
#ifdef WIN32
Sleep(1000);
Sleep(1000);
#else
sleep(1);
sleep(1);
#endif
}
}
}
}

View file

@ -106,7 +106,7 @@ const uint32_t FT_DETAILS_REMOTE = 0x0002;
const uint32_t CLEANUP_PERIOD = 600; /* 10 minutes */
class ftExtraList: public RsThread, public p3Config, public ftSearch
class ftExtraList: public RsTickingThread, public p3Config, public ftSearch
{
public:
@ -143,7 +143,7 @@ virtual bool search(const RsFileHash &hash, FileSearchFlags hintflags, FileIn
/***
* Thread Main Loop
**/
virtual void run();
virtual void data_tick();
/***
* Configuration - store extra files.
@ -167,6 +167,8 @@ bool cleanupEntry(std::string path, TransferRequestFlags flags);
std::map<std::string, RsFileHash> mHashedList; /* path -> hash ( not saved ) */
std::map<RsFileHash, FileDetails> mFiles;
time_t cleanup ;
};

View file

@ -542,13 +542,13 @@ bool ftTransferModule::isCheckingHash()
return mFlag == FT_TM_FLAG_CHECKING || mFlag == FT_TM_FLAG_CHUNK_CRC;
}
class HashThread: public RsThread
class HashThread: public RsSingleJobThread
{
public:
HashThread(ftFileCreator *m)
: _hashThreadMtx("HashThread"), _m(m),_finished(false),_hash("") {}
virtual void run()
virtual void run()
{
#ifdef FT_DEBUG
std::cerr << "hash thread is running for file " << std::endl;
@ -609,8 +609,6 @@ bool ftTransferModule::checkFile()
RsFileHash check_hash( _hash_thread->hash() ) ;
_hash_thread->join(); // allow releasing of resources when finished.
delete _hash_thread ;
_hash_thread = NULL ;