mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-02-27 02:11:27 -05:00
fixed threading issues in directory updater
This commit is contained in:
parent
067d4231ae
commit
43f4f5d2d9
@ -5,7 +5,7 @@
|
|||||||
|
|
||||||
#define DEBUG_LOCAL_DIR_UPDATER 1
|
#define DEBUG_LOCAL_DIR_UPDATER 1
|
||||||
|
|
||||||
static const uint32_t DELAY_BETWEEN_DIRECTORY_UPDATES = 10 ; // 10 seconds for testing. Should be much more!!
|
static const uint32_t DELAY_BETWEEN_DIRECTORY_UPDATES = 100 ; // 10 seconds for testing. Should be much more!!
|
||||||
|
|
||||||
void RemoteDirectoryUpdater::tick()
|
void RemoteDirectoryUpdater::tick()
|
||||||
{
|
{
|
||||||
@ -27,6 +27,8 @@ void LocalDirectoryUpdater::data_tick()
|
|||||||
sweepSharedDirectories() ;
|
sweepSharedDirectories() ;
|
||||||
mLastSweepTime = now;
|
mLastSweepTime = now;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
usleep(10*1000*1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
void LocalDirectoryUpdater::sweepSharedDirectories()
|
void LocalDirectoryUpdater::sweepSharedDirectories()
|
||||||
|
@ -19,7 +19,15 @@ void HashStorage::data_tick()
|
|||||||
RS_STACK_MUTEX(mHashMtx) ;
|
RS_STACK_MUTEX(mHashMtx) ;
|
||||||
|
|
||||||
if(mFilesToHash.empty())
|
if(mFilesToHash.empty())
|
||||||
|
{
|
||||||
|
std::cerr << "Stopping hashing thread." << std::endl;
|
||||||
|
shutdown();
|
||||||
|
mRunning = false ;
|
||||||
|
std::cerr << "done." << std::endl;
|
||||||
|
|
||||||
|
usleep(2*1000*1000); // when no files to hash, just wait for 2 secs. This avoids a dramatic loop.
|
||||||
return ;
|
return ;
|
||||||
|
}
|
||||||
|
|
||||||
job = mFilesToHash.begin()->second ;
|
job = mFilesToHash.begin()->second ;
|
||||||
|
|
||||||
@ -33,14 +41,6 @@ void HashStorage::data_tick()
|
|||||||
|
|
||||||
mFilesToHash.erase(mFilesToHash.begin()) ;
|
mFilesToHash.erase(mFilesToHash.begin()) ;
|
||||||
|
|
||||||
if(mFilesToHash.empty())
|
|
||||||
{
|
|
||||||
std::cerr << "Stopping hashing thread." << std::endl;
|
|
||||||
shutdown();
|
|
||||||
mRunning = false ;
|
|
||||||
std::cerr << "done." << std::endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
// store the result
|
// store the result
|
||||||
|
|
||||||
HashStorageInfo& info(mFiles[job.full_path]);
|
HashStorageInfo& info(mFiles[job.full_path]);
|
||||||
|
@ -31,8 +31,6 @@ p3FileDatabase::p3FileDatabase(p3ServiceControl *mpeers)
|
|||||||
mLocalDirWatcher = new LocalDirectoryUpdater(mHashCache,mLocalSharedDirs) ;
|
mLocalDirWatcher = new LocalDirectoryUpdater(mHashCache,mLocalSharedDirs) ;
|
||||||
mRemoteDirWatcher = NULL; // not used yet
|
mRemoteDirWatcher = NULL; // not used yet
|
||||||
|
|
||||||
mLocalDirWatcher->start();
|
|
||||||
|
|
||||||
mUpdateFlags = P3FILELISTS_UPDATE_FLAG_NOTHING_CHANGED ;
|
mUpdateFlags = P3FILELISTS_UPDATE_FLAG_NOTHING_CHANGED ;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -101,15 +99,21 @@ int p3FileDatabase::tick()
|
|||||||
void p3FileDatabase::startThreads()
|
void p3FileDatabase::startThreads()
|
||||||
{
|
{
|
||||||
std::cerr << "Starting hash cache thread..." ;
|
std::cerr << "Starting hash cache thread..." ;
|
||||||
|
|
||||||
mHashCache->start();
|
mHashCache->start();
|
||||||
|
std::cerr << "Done." << std::endl;
|
||||||
|
|
||||||
|
std::cerr << "Starting directory watcher thread..." ;
|
||||||
|
mLocalDirWatcher->start();
|
||||||
|
std::cerr << "Done." << std::endl;
|
||||||
}
|
}
|
||||||
void p3FileDatabase::stopThreads()
|
void p3FileDatabase::stopThreads()
|
||||||
{
|
{
|
||||||
std::cerr << "Stopping hash cache thread..." ; std::cerr.flush() ;
|
std::cerr << "Stopping hash cache thread..." ; std::cerr.flush() ;
|
||||||
|
|
||||||
mHashCache->fullstop();
|
mHashCache->fullstop();
|
||||||
|
std::cerr << "Done." << std::endl;
|
||||||
|
|
||||||
|
std::cerr << "Stopping directory watcher thread..." ; std::cerr.flush() ;
|
||||||
|
mLocalDirWatcher->fullstop();
|
||||||
std::cerr << "Done." << std::endl;
|
std::cerr << "Done." << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user