diff --git a/libretroshare/src/dbase/fimonitor.cc b/libretroshare/src/dbase/fimonitor.cc index 0b0f6f527..96da1dda3 100644 --- a/libretroshare/src/dbase/fimonitor.cc +++ b/libretroshare/src/dbase/fimonitor.cc @@ -632,13 +632,7 @@ void FileIndexMonitor::run() if(!isRunning()) return; - /********************************** WINDOWS/UNIX SPECIFIC PART ******************/ -#ifndef WINDOWS_SYS - sleep(1); -#else - Sleep(1000); -#endif - /********************************** WINDOWS/UNIX SPECIFIC PART ******************/ + usleep(1*1000*1000); // 1 sec /* check dirs if they've changed */ if (internal_setSharedDirectories()) @@ -698,16 +692,10 @@ void FileIndexMonitor::updateCycle() while(isRunning() && moretodo) { /* sleep a bit for each loop */ -/********************************** WINDOWS/UNIX SPECIFIC PART ******************/ // csoler: I'm disabling this since it causes a very long update cycle when the number // of directories to go through is very large. // -// #ifndef WINDOWS_SYS -// usleep(100000); /* 1/10 sec */ -// #else -// Sleep(100); -// #endif -/********************************** WINDOWS/UNIX SPECIFIC PART ******************/ +// usleep(100*1000); /* 100 msec */ /* check if directories have been updated */ @@ -1127,14 +1115,8 @@ void FileIndexMonitor::hashFiles(const std::vector& to_hash) size += to_hash[i].fentries[j].size ; - /* don't hit the disk too hard! */ -#ifndef WINDOWS_SYS - /********************************** WINDOWS/UNIX SPECIFIC PART ******************/ - usleep(10000); /* 10 msec */ -#else - - Sleep(10); -#endif + // don't hit the disk too hard! + usleep(10*1000); // 10 msec // Save the hashing result every 60 seconds, so has to save what is already hashed. #ifdef FIM_DEBUG @@ -1144,11 +1126,10 @@ void FileIndexMonitor::hashFiles(const std::vector& to_hash) if(hashed_size > last_save_size + MAX_SIZE_WITHOUT_SAVING) { RsServer::notify()->notifyHashingInfo(NOTIFY_HASHTYPE_SAVE_FILE_INDEX, "") ; -#ifdef WINDOWS_SYS - Sleep(1000) ; -#else - sleep(1) ; -#endif + + //Waiting 1 sec before pass to other hash ??is it really needed?? + usleep(1*1000*1000); // 1 sec + RsStackMutex stack(fiMutex); /**** LOCKED DIRS ****/ fi.updateHashIndex() ; FileIndexMonitor::locked_saveFileIndexes(true) ; diff --git a/libretroshare/src/ft/ftcontroller.cc b/libretroshare/src/ft/ftcontroller.cc index 9add5309c..34a560623 100644 --- a/libretroshare/src/ft/ftcontroller.cc +++ b/libretroshare/src/ft/ftcontroller.cc @@ -217,11 +217,8 @@ void ftController::run() while(isRunning()) { -#ifdef WIN32 - Sleep(1000); -#else - sleep(1); -#endif + //Waiting 1 sec before start + usleep(1*1000*1000); // 1 sec #ifdef CONTROL_DEBUG std::cerr << "ftController::run()"; diff --git a/libretroshare/src/ft/ftdatamultiplex.cc b/libretroshare/src/ft/ftdatamultiplex.cc index 6566983fa..32e04af28 100644 --- a/libretroshare/src/ft/ftdatamultiplex.cc +++ b/libretroshare/src/ft/ftdatamultiplex.cc @@ -39,9 +39,9 @@ #include /* For Thread Behaviour */ -const uint32_t DMULTIPLEX_MIN = 10; /* 1ms sleep */ +const uint32_t DMULTIPLEX_MIN = 10; /* 10 msec sleep */ const uint32_t DMULTIPLEX_MAX = 1000; /* 1 sec sleep */ -const double DMULTIPLEX_RELAX = 0.5; /* ??? */ +const double DMULTIPLEX_RELAX = 0.5; /* relax factor to calculate sleep time if not working in /libretroshare/src/util/rsthreads.cc */ static const uint32_t MAX_CHECKING_CHUNK_WAIT_DELAY = 120 ; //! TTL for an inactive chunk const uint32_t MAX_SIMULTANEOUS_CRC_REQUESTS = 20 ; diff --git a/libretroshare/src/ft/ftserver.cc b/libretroshare/src/ft/ftserver.cc index a787828e3..b8e7222be 100644 --- a/libretroshare/src/ft/ftserver.cc +++ b/libretroshare/src/ft/ftserver.cc @@ -23,7 +23,6 @@ * */ -#include /* for (u)sleep() */ #include #include #include "util/rsdebug.h" diff --git a/libretroshare/src/gxs/rsgenexchange.cc b/libretroshare/src/gxs/rsgenexchange.cc index fb095791c..ef151db47 100644 --- a/libretroshare/src/gxs/rsgenexchange.cc +++ b/libretroshare/src/gxs/rsgenexchange.cc @@ -147,18 +147,13 @@ RsGenExchange::~RsGenExchange() void RsGenExchange::run() { - double timeDelta = 0.1; // slow tick + double timeDelta = 0.1; // slow tick in sec - while(isRunning()) - { + while(isRunning()) { tick(); -#ifndef WINDOWS_SYS - usleep((int) (timeDelta * 1000000)); -#else - Sleep((int) (timeDelta * 1000)); -#endif - } + usleep((int) (timeDelta * 1000 *1000)); // timeDelta sec + }//while(isRunning()) } void RsGenExchange::tick() diff --git a/libretroshare/src/gxs/rsgxsnetservice.cc b/libretroshare/src/gxs/rsgxsnetservice.cc index 8838acc5d..fa053307f 100644 --- a/libretroshare/src/gxs/rsgxsnetservice.cc +++ b/libretroshare/src/gxs/rsgxsnetservice.cc @@ -487,46 +487,35 @@ void RsGxsNetService::locked_createTransactionFromPending(MsgCircleIdsRequestVet locked_pushMsgRespFromList(itemL, msgPend->mPeerId, transN); } -bool RsGxsNetService::locked_canReceive(const RsGxsGrpMetaData * const grpMeta, - const RsPeerId& peerId) +/*bool RsGxsNetService::locked_canReceive(const RsGxsGrpMetaData * const grpMeta + , const RsPeerId& peerId ) { double timeDelta = 0.2; - if(grpMeta->mCircleType == GXS_CIRCLE_TYPE_EXTERNAL) - { + if(grpMeta->mCircleType == GXS_CIRCLE_TYPE_EXTERNAL) { int i=0; mCircles->loadCircle(grpMeta->mCircleId); // check 5 times at most // spin for 1 second at most - while(i < 5) - { -#ifndef WINDOWS_SYS - usleep((int) (timeDelta * 1000000)); -#else - Sleep((int) (timeDelta * 1000)); -#endif + while(i < 5) { - if(mCircles->isLoaded(grpMeta->mCircleId)) - { + if(mCircles->isLoaded(grpMeta->mCircleId)) { const RsPgpId& pgpId = mPgpUtils->getPGPId(peerId); return mCircles->canSend(grpMeta->mCircleId, pgpId); - } - + }//if(mCircles->isLoaded(grpMeta->mCircleId)) + usleep((int) (timeDelta * 1000 * 1000));// timeDelta sec i++; - } + }//while(i < 5) - } - else - { + } else {//if(grpMeta->mCircleType == GXS_CIRCLE_TYPE_EXTERNAL) return true; - } - + }//else (grpMeta->mCircleType == GXS_CIRCLE_TYPE_EXTERNAL) return false; -} +}*/ void RsGxsNetService::collateGrpFragments(GrpFragments fragments, std::map& partFragments) const @@ -939,26 +928,19 @@ bool RsGxsNetService::locked_processTransac(RsNxsTransac* item) } void RsGxsNetService::run(){ - - double timeDelta = 0.5; int updateCounter = 0; while(isRunning()){ + //Start waiting as nothing to do in runup + usleep((int) (timeDelta * 1000 * 1000)); // timeDelta sec -#ifndef WINDOWS_SYS - usleep((int) (timeDelta * 1000000)); -#else - Sleep((int) (timeDelta * 1000)); -#endif - - if(updateCounter == 20) - { + if(updateCounter >= 20) { updateServerSyncTS(); updateCounter = 0; - } - else + } else {//if(updateCounter >= 20) updateCounter++; + }//else (updateCounter >= 20) // process active transactions processTransactions(); @@ -971,7 +953,7 @@ void RsGxsNetService::run(){ processExplicitGroupRequests(); - } + }//while(isRunning()) } void RsGxsNetService::updateServerSyncTS() diff --git a/libretroshare/src/gxs/rsgxsnetservice.h b/libretroshare/src/gxs/rsgxsnetservice.h index d9efeda34..dbc73f98f 100644 --- a/libretroshare/src/gxs/rsgxsnetservice.h +++ b/libretroshare/src/gxs/rsgxsnetservice.h @@ -340,7 +340,7 @@ private: const RsGxsGroupId& grpId, uint32_t& transN, std::list& reqList); - bool locked_canReceive(const RsGxsGrpMetaData * const grpMeta, const RsPeerId& peerId); + //bool locked_canReceive(const RsGxsGrpMetaData * const grpMeta, const RsPeerId& peerId); void processExplicitGroupRequests(); diff --git a/libretroshare/src/pqi/authgpg.cc b/libretroshare/src/pqi/authgpg.cc index 0afc462cd..bd44847bb 100644 --- a/libretroshare/src/pqi/authgpg.cc +++ b/libretroshare/src/pqi/authgpg.cc @@ -182,32 +182,26 @@ void AuthGPG::run() { int count = 0; - while (isRunning()) - { -#ifdef WIN32 - Sleep(100); -#else - usleep(100000); -#endif + while (isRunning()) { + usleep(100 * 1000); //100 msec - /* every 100 milliseconds */ + /// every 100 milliseconds processServices(); - /* every ten seconds */ - if (++count >= 100 || _force_sync_database) - { - RsStackMutex stack(gpgMtxService); /******* LOCKED ******/ - - // The call does multiple things at once: - // - checks whether the keyring has changed in memory - // - checks whether the keyring has changed on disk. - // - merges/updates according to status. - // + /// every ten seconds + if (++count >= 100 || _force_sync_database) { + RsStackMutex stack(gpgMtxService); ///******* LOCKED ****** + + /// The call does multiple things at once: + /// - checks whether the keyring has changed in memory + /// - checks whether the keyring has changed on disk. + /// - merges/updates according to status. + /// PGPHandler::syncDatabase() ; count = 0; _force_sync_database = false ; - } - } + }//if (++count >= 100 || _force_sync_database) + }//while (isRunning()) } void AuthGPG::processServices() diff --git a/libretroshare/src/services/p3chatservice.cc b/libretroshare/src/services/p3chatservice.cc index e9653989a..5c77d399b 100644 --- a/libretroshare/src/services/p3chatservice.cc +++ b/libretroshare/src/services/p3chatservice.cc @@ -3422,7 +3422,7 @@ void p3ChatService::handleRecvDHPublicKey(RsChatDHPublicKeyItem *item) #ifdef DEBUG_DISTANT_CHAT std::cerr << " Cannot get key. Waiting for caching. try " << i << "/6" << std::endl; #endif - usleep(500000) ; // sleep for 500 msec. + usleep(500 * 1000) ; // sleep for 500 msec. } else break ; @@ -3529,7 +3529,7 @@ bool p3ChatService::locked_sendDHPublicKey(const DistantChatPeerInfo& pinfo) if(!mIdService->getPrivateKey(pinfo.own_gxs_id,signature_key) || signature_key.keyData.bin_data == NULL) { std::cerr << " Cannot get key. Waiting for caching. try " << i << "/6" << std::endl; - usleep(500000) ; // sleep for 500 msec. + usleep(500 * 1000) ; // sleep for 500 msec. } else break ; diff --git a/libretroshare/src/services/p3msgservice.cc b/libretroshare/src/services/p3msgservice.cc index c4e7cad5c..307cc19a4 100644 --- a/libretroshare/src/services/p3msgservice.cc +++ b/libretroshare/src/services/p3msgservice.cc @@ -2005,7 +2005,7 @@ bool p3MsgService::decryptMessage(const std::string& mId) if(!mIdService->getKey(senders_id,signature_key) || signature_key.keyData.bin_data == NULL) { std::cerr << " Cannot get key. Waiting for caching. try " << i << "/6" << std::endl; - usleep(500000) ; // sleep for 500 msec. + usleep(500 * 1000) ; // sleep for 500 msec. } else break ; diff --git a/libretroshare/src/util/rsdir.cc b/libretroshare/src/util/rsdir.cc index ee0d10e59..e22acd0e1 100644 --- a/libretroshare/src/util/rsdir.cc +++ b/libretroshare/src/util/rsdir.cc @@ -746,11 +746,7 @@ bool RsDirUtil::renameFile(const std::string& from, const std::string& to) #endif /* set errno? */ return false ; -#ifdef WIN32 - Sleep(200); /* 200 milliseconds */ -#else - usleep(100000); /* 100000 microseconds */ -#endif + usleep(100 * 1000); // 100 msec if (loops >= 30) return false ; @@ -956,11 +952,7 @@ RsStackFileLock::RsStackFileLock(const std::string& file_path) while(RsDirUtil::createLockFile(file_path,_file_handle)) { std::cerr << "Cannot acquire file lock " << file_path << ", waiting 1 sec." << std::endl; -#ifdef WINDOWS_SYS - Sleep(1000) ; -#else - sleep(1) ; -#endif + sleep(1 * 1000 * 1000) ; // 1 sec } #ifdef RSDIR_DEBUG std::cerr << "Acquired file handle " << _file_handle << ", lock file:" << file_path << std::endl; @@ -1364,11 +1356,7 @@ bool RsDirUtil::renameWideFile(const std::wstring& from, const std::wstring& to) #endif /* set errno? */ return false ; -#ifdef WIN32 - Sleep(100000); /* us */ -#else - usleep(100000); /* us */ -#endif + usleep(100 * 1000); //100 msec if (loops >= 30) return false ; diff --git a/libretroshare/src/util/rsthreads.cc b/libretroshare/src/util/rsthreads.cc index b64411b7d..3852c1b1e 100644 --- a/libretroshare/src/util/rsthreads.cc +++ b/libretroshare/src/util/rsthreads.cc @@ -26,8 +26,8 @@ #include "rsthreads.h" -#include /* for usleep() */ -#include /* for usleep() */ +#include // for usleep() +#include // for errno #include #include @@ -35,10 +35,6 @@ #include #endif -#if defined(WINDOWS_SYS) && defined(__MINGW64_VERSION_MAJOR) -#include // for Sleep -#endif - /******* * #define DEBUG_THREADS 1 * #define RSMUTEX_ABORT 1 // Catch wrong pthreads mode. @@ -176,11 +172,7 @@ void RsQueueThread::run() std::cerr << std::endl; #endif } -#ifdef WIN32 - Sleep(mLastSleep); -#else - usleep(1000 * mLastSleep); -#endif + usleep(mLastSleep * 1000); // mLastSleep msec } }