mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-02-17 21:34:10 -05:00
fixed sleeping when hashing strategy
This commit is contained in:
parent
733ad438fb
commit
df14b41ba6
@ -23,22 +23,41 @@ void HashStorage::data_tick()
|
||||
uint64_t size ;
|
||||
|
||||
{
|
||||
RS_STACK_MUTEX(mHashMtx) ;
|
||||
bool empty ;
|
||||
uint32_t st ;
|
||||
|
||||
if(mFilesToHash.empty())
|
||||
{
|
||||
std::cerr << "Stopping hashing thread." << std::endl;
|
||||
shutdown();
|
||||
mRunning = false ;
|
||||
std::cerr << "done." << std::endl;
|
||||
RS_STACK_MUTEX(mHashMtx) ;
|
||||
|
||||
RsServer::notify()->notifyHashingInfo(NOTIFY_HASHTYPE_FINISH, "") ;
|
||||
empty = mFilesToHash.empty();
|
||||
st = mInactivitySleepTime ;
|
||||
}
|
||||
|
||||
usleep(mInactivitySleepTime); // when no files to hash, just wait for 2 secs. This avoids a dramatic loop.
|
||||
mInactivitySleepTime *= 2;
|
||||
// sleep off mutex!
|
||||
if(empty)
|
||||
{
|
||||
std::cerr << "nothing to hash. Sleeping for " << st << " us" << std::endl;
|
||||
|
||||
if(mInactivitySleepTime > MAX_INACTIVITY_SLEEP_TIME)
|
||||
mInactivitySleepTime = MAX_INACTIVITY_SLEEP_TIME;
|
||||
usleep(st); // when no files to hash, just wait for 2 secs. This avoids a dramatic loop.
|
||||
|
||||
if(st > MAX_INACTIVITY_SLEEP_TIME)
|
||||
{
|
||||
RS_STACK_MUTEX(mHashMtx) ;
|
||||
|
||||
mInactivitySleepTime = MAX_INACTIVITY_SLEEP_TIME;
|
||||
|
||||
std::cerr << "Stopping hashing thread." << std::endl;
|
||||
shutdown();
|
||||
mRunning = false ;
|
||||
std::cerr << "done." << std::endl;
|
||||
|
||||
RsServer::notify()->notifyHashingInfo(NOTIFY_HASHTYPE_FINISH, "") ;
|
||||
}
|
||||
else
|
||||
{
|
||||
RS_STACK_MUTEX(mHashMtx) ;
|
||||
mInactivitySleepTime = 2*st ;
|
||||
}
|
||||
|
||||
return ;
|
||||
}
|
||||
@ -279,6 +298,9 @@ bool HashStorage::readHashStorageInfo(const unsigned char *data,uint32_t total_s
|
||||
uint32_t section_size = 0;
|
||||
uint32_t section_offset = 0;
|
||||
|
||||
// This way, the entire section is either read or skipped. That avoids the risk of being stuck somewhere in the middle
|
||||
// of a section because of some unknown field, etc.
|
||||
|
||||
if(!FileListIO::readField(data,total_size,offset,FILE_LIST_IO_TAG_HASH_STORAGE_ENTRY,section_data,section_size))
|
||||
return false;
|
||||
|
||||
|
@ -102,6 +102,15 @@ int p3FileDatabase::tick()
|
||||
// -
|
||||
cleanup();
|
||||
|
||||
static time_t last_print_time = 0;
|
||||
time_t now = time(NULL) ;
|
||||
|
||||
if(last_print_time + 60 < now)
|
||||
{
|
||||
mLocalSharedDirs->print();
|
||||
last_print_time = now ;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -353,6 +362,8 @@ int p3FileDatabase::RequestDirDetails(void *ref, DirDetails& d, FileSearchFlags
|
||||
|
||||
d.prow = mDirectories[fi]->parentRow(e) ;
|
||||
d.id = mDirectories[fi]->peerId();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
int p3FileDatabase::RequestDirDetails(const RsPeerId& uid,const std::string& path, DirDetails &details) const
|
||||
|
Loading…
x
Reference in New Issue
Block a user