mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-01-26 07:16:11 -05:00
The working (hashing) thread FileIndexMonitor is now stopped when RetroShare is closed.
git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@4072 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
6bb4854925
commit
0a42b7899e
@ -453,13 +453,13 @@ void FileIndexMonitor::run()
|
||||
{
|
||||
updateCycle();
|
||||
|
||||
while(m_bRun)
|
||||
while(isRunning())
|
||||
{
|
||||
|
||||
for(int i = 0; i < updatePeriod; i++)
|
||||
{
|
||||
|
||||
if (m_bRun == false) {
|
||||
if (isRunning() == false) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -515,7 +515,7 @@ void FileIndexMonitor::updateCycle()
|
||||
cache_is_new = useHashCache && hashCache.empty() ;
|
||||
}
|
||||
|
||||
while(moretodo)
|
||||
while(isRunning() && moretodo)
|
||||
{
|
||||
/* sleep a bit for each loop */
|
||||
/********************************** WINDOWS/UNIX SPECIFIC PART ******************/
|
||||
@ -617,7 +617,7 @@ void FileIndexMonitor::updateCycle()
|
||||
to_hash.back().realpath = realpath ;
|
||||
to_hash.back().dirpath = dirpath ;
|
||||
|
||||
while(dirIt.readdir())
|
||||
while(isRunning() && dirIt.readdir())
|
||||
{
|
||||
/* check entry type */
|
||||
std::string fname;
|
||||
@ -738,7 +738,7 @@ void FileIndexMonitor::updateCycle()
|
||||
|
||||
// Now, hash all files at once.
|
||||
//
|
||||
if(!to_hash.empty())
|
||||
if(isRunning() && !to_hash.empty())
|
||||
hashFiles(to_hash) ;
|
||||
|
||||
cb->notifyHashingInfo(NOTIFY_HASHTYPE_FINISH, "") ;
|
||||
@ -827,9 +827,12 @@ void FileIndexMonitor::hashFiles(const std::vector<DirContentToHash>& to_hash)
|
||||
uint64_t hashed_size=0 ;
|
||||
uint64_t last_save_size=0 ;
|
||||
|
||||
// check if thread is running
|
||||
bool running = isRunning();
|
||||
|
||||
/* update files */
|
||||
for(uint32_t i=0;i<to_hash.size();++i)
|
||||
for(uint32_t j=0;j<to_hash[i].fentries.size();++j,++cnt)
|
||||
for(uint32_t i=0;running && i<to_hash.size();++i)
|
||||
for(uint32_t j=0;running && j<to_hash[i].fentries.size();++j,++cnt)
|
||||
{
|
||||
// This is a very basic progress notification. To be more complete and user friendly, one would
|
||||
// rather send a completion ratio based on the size of files vs/ total size.
|
||||
@ -846,7 +849,7 @@ void FileIndexMonitor::hashFiles(const std::vector<DirContentToHash>& to_hash)
|
||||
//
|
||||
if(useHashCache && hashCache.find(real_path,fe.size,fe.modtime,fe.hash))
|
||||
fi.updateFileEntry(to_hash[i].dirpath,fe,stamp);
|
||||
else if(RsDirUtil::getFileHash(real_path, fe.hash,fe.size)) // not found, then hash it.
|
||||
else if(RsDirUtil::getFileHash(real_path, fe.hash,fe.size, this)) // not found, then hash it.
|
||||
{
|
||||
RsStackMutex stack(fiMutex); /**** LOCKED DIRS ****/
|
||||
|
||||
@ -893,6 +896,9 @@ void FileIndexMonitor::hashFiles(const std::vector<DirContentToHash>& to_hash)
|
||||
if(useHashCache)
|
||||
hashCache.save() ;
|
||||
}
|
||||
|
||||
// check if thread is running
|
||||
running = isRunning();
|
||||
}
|
||||
|
||||
cb->notifyListChange(NOTIFY_LIST_DIRLIST_LOCAL, 0);
|
||||
|
@ -209,7 +209,7 @@ void ftController::run()
|
||||
/* check the queues */
|
||||
uint32_t cnt = 0 ;
|
||||
|
||||
while(m_bRun)
|
||||
while(isRunning())
|
||||
{
|
||||
#ifdef WIN32
|
||||
Sleep(1000);
|
||||
|
@ -49,7 +49,7 @@ void ftExtraList::run()
|
||||
time_t cleanup = 0;
|
||||
time_t now = 0;
|
||||
|
||||
while (m_bRun)
|
||||
while (isRunning())
|
||||
{
|
||||
#ifdef DEBUG_ELIST
|
||||
//std::cerr << "ftExtraList::run() Iteration";
|
||||
|
@ -225,7 +225,7 @@ CacheTransfer *ftServer::getCacheTransfer()
|
||||
|
||||
void ftServer::run()
|
||||
{
|
||||
while(m_bRun)
|
||||
while(isRunning())
|
||||
{
|
||||
mFtDataplex->deleteUnusedServers() ;
|
||||
#ifdef WIN32
|
||||
|
@ -358,7 +358,7 @@ void AuthGPGimpl::run()
|
||||
{
|
||||
int count = 0;
|
||||
|
||||
while (m_bRun)
|
||||
while (isRunning())
|
||||
{
|
||||
#ifdef WIN32
|
||||
Sleep(100);
|
||||
|
@ -110,7 +110,7 @@ void RsServer::run()
|
||||
int min = 0;
|
||||
int loop = 0;
|
||||
|
||||
while(m_bRun)
|
||||
while(isRunning())
|
||||
{
|
||||
#ifndef WINDOWS_SYS
|
||||
usleep((int) (timeDelta * 1000000));
|
||||
|
@ -32,6 +32,7 @@
|
||||
#include "util/rsdir.h"
|
||||
#include "pqi/pqinotify.h"
|
||||
#include "retroshare/rstypes.h"
|
||||
#include "rsthreads.h"
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include <algorithm>
|
||||
@ -526,7 +527,7 @@ bool RsDirUtil::hashFile(const std::string& filepath,
|
||||
#include <iomanip>
|
||||
|
||||
/* Function to hash, and get details of a file */
|
||||
bool RsDirUtil::getFileHash(const std::string& filepath, std::string &hash, uint64_t &size)
|
||||
bool RsDirUtil::getFileHash(const std::string& filepath, std::string &hash, uint64_t &size, RsThread *thread /*= NULL*/)
|
||||
{
|
||||
FILE *fd;
|
||||
int len;
|
||||
@ -549,10 +550,28 @@ bool RsDirUtil::getFileHash(const std::string& filepath, std::string &hash, uint
|
||||
size = ftello64(fd);
|
||||
fseeko64(fd, 0, SEEK_SET);
|
||||
|
||||
/* check if thread is running */
|
||||
bool isRunning = thread ? thread->isRunning() : true;
|
||||
int runningCheckCount = 0;
|
||||
|
||||
SHA1_Init(sha_ctx);
|
||||
while((len = fread(gblBuf,1, 512, fd)) > 0)
|
||||
while(isRunning && (len = fread(gblBuf,1, 512, fd)) > 0)
|
||||
{
|
||||
SHA1_Update(sha_ctx, gblBuf, len);
|
||||
|
||||
if (thread && ++runningCheckCount > (10 * 1024)) {
|
||||
/* check all 50MB if thread is running */
|
||||
isRunning = thread->isRunning();
|
||||
runningCheckCount = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* Thread has ended */
|
||||
if (isRunning == false)
|
||||
{
|
||||
delete sha_ctx;
|
||||
fclose(fd);
|
||||
return false;
|
||||
}
|
||||
|
||||
/* reading failed for some reason */
|
||||
|
@ -33,6 +33,7 @@
|
||||
#include <stdint.h>
|
||||
|
||||
class CRC32Map ;
|
||||
class RsThread;
|
||||
|
||||
namespace RsDirUtil {
|
||||
|
||||
@ -64,7 +65,7 @@ bool checkCreateDirectory(const std::string& dir);
|
||||
bool cleanupDirectory(const std::string& dir, const std::list<std::string> &keepFiles);
|
||||
|
||||
bool hashFile(const std::string& filepath, std::string &name, std::string &hash, uint64_t &size);
|
||||
bool getFileHash(const std::string& filepath,std::string &hash, uint64_t &size);
|
||||
bool getFileHash(const std::string& filepath,std::string &hash, uint64_t &size, RsThread *thread = NULL);
|
||||
|
||||
|
||||
std::wstring getWideTopDir(std::wstring);
|
||||
|
@ -82,7 +82,7 @@ pthread_t createThread(RsThread &thread)
|
||||
|
||||
RsThread::RsThread ()
|
||||
{
|
||||
m_bRun = true;
|
||||
mIsRunning = true;
|
||||
|
||||
#ifdef WINDOWS_SYS
|
||||
memset (&mTid, 0, sizeof(mTid));
|
||||
@ -93,7 +93,8 @@ RsThread::RsThread ()
|
||||
|
||||
void RsThread::join() /* waits for the the mTid thread to stop */
|
||||
{
|
||||
m_bRun = false;
|
||||
// do we need a mutex for this ?
|
||||
mIsRunning = false;
|
||||
|
||||
void *ptr;
|
||||
pthread_join(mTid, &ptr);
|
||||
@ -104,6 +105,12 @@ void RsThread::stop()
|
||||
pthread_exit(NULL);
|
||||
}
|
||||
|
||||
bool RsThread::isRunning()
|
||||
{
|
||||
// do we need a mutex for this ?
|
||||
return mIsRunning;
|
||||
}
|
||||
|
||||
RsQueueThread::RsQueueThread(uint32_t min, uint32_t max, double relaxFactor )
|
||||
:mMinSleep(min), mMaxSleep(max), mRelaxFactor(relaxFactor)
|
||||
{
|
||||
@ -113,7 +120,7 @@ RsQueueThread::RsQueueThread(uint32_t min, uint32_t max, double relaxFactor )
|
||||
|
||||
void RsQueueThread::run()
|
||||
{
|
||||
while(m_bRun)
|
||||
while(isRunning())
|
||||
{
|
||||
bool doneWork = false;
|
||||
while(workQueued() && doWork())
|
||||
|
@ -118,10 +118,13 @@ 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() */
|
||||
|
||||
bool isRunning();
|
||||
|
||||
pthread_t mTid;
|
||||
RsMutex mMutex;
|
||||
protected:
|
||||
bool m_bRun;
|
||||
|
||||
private:
|
||||
bool mIsRunning;
|
||||
};
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user