mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-06-19 11:54:22 -04:00
fixed sleeping when hashing strategy
This commit is contained in:
parent
733ad438fb
commit
df14b41ba6
2 changed files with 44 additions and 11 deletions
|
@ -23,22 +23,41 @@ void HashStorage::data_tick()
|
||||||
uint64_t size ;
|
uint64_t size ;
|
||||||
|
|
||||||
{
|
{
|
||||||
RS_STACK_MUTEX(mHashMtx) ;
|
bool empty ;
|
||||||
|
uint32_t st ;
|
||||||
|
|
||||||
if(mFilesToHash.empty())
|
|
||||||
{
|
{
|
||||||
std::cerr << "Stopping hashing thread." << std::endl;
|
RS_STACK_MUTEX(mHashMtx) ;
|
||||||
shutdown();
|
|
||||||
mRunning = false ;
|
|
||||||
std::cerr << "done." << std::endl;
|
|
||||||
|
|
||||||
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.
|
// sleep off mutex!
|
||||||
mInactivitySleepTime *= 2;
|
if(empty)
|
||||||
|
{
|
||||||
|
std::cerr << "nothing to hash. Sleeping for " << st << " us" << std::endl;
|
||||||
|
|
||||||
if(mInactivitySleepTime > MAX_INACTIVITY_SLEEP_TIME)
|
usleep(st); // when no files to hash, just wait for 2 secs. This avoids a dramatic loop.
|
||||||
mInactivitySleepTime = MAX_INACTIVITY_SLEEP_TIME;
|
|
||||||
|
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 ;
|
return ;
|
||||||
}
|
}
|
||||||
|
@ -279,6 +298,9 @@ bool HashStorage::readHashStorageInfo(const unsigned char *data,uint32_t total_s
|
||||||
uint32_t section_size = 0;
|
uint32_t section_size = 0;
|
||||||
uint32_t section_offset = 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))
|
if(!FileListIO::readField(data,total_size,offset,FILE_LIST_IO_TAG_HASH_STORAGE_ENTRY,section_data,section_size))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
|
|
@ -102,6 +102,15 @@ int p3FileDatabase::tick()
|
||||||
// -
|
// -
|
||||||
cleanup();
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -353,6 +362,8 @@ int p3FileDatabase::RequestDirDetails(void *ref, DirDetails& d, FileSearchFlags
|
||||||
|
|
||||||
d.prow = mDirectories[fi]->parentRow(e) ;
|
d.prow = mDirectories[fi]->parentRow(e) ;
|
||||||
d.id = mDirectories[fi]->peerId();
|
d.id = mDirectories[fi]->peerId();
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
int p3FileDatabase::RequestDirDetails(const RsPeerId& uid,const std::string& path, DirDetails &details) const
|
int p3FileDatabase::RequestDirDetails(const RsPeerId& uid,const std::string& path, DirDetails &details) const
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue