removed ifdef for the different sleep methods. Now only usleep is used, on all systems. Patch from Phenom

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@7629 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
csoler 2014-10-24 21:31:58 +00:00
parent c17de671bb
commit 880efee332
12 changed files with 57 additions and 129 deletions

View File

@ -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<DirContentToHash>& 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<DirContentToHash>& 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) ;

View File

@ -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()";

View File

@ -39,9 +39,9 @@
#include <time.h>
/* 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 ;

View File

@ -23,7 +23,6 @@
*
*/
#include <unistd.h> /* for (u)sleep() */
#include <iostream>
#include <time.h>
#include "util/rsdebug.h"

View File

@ -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()

View File

@ -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<RsGxsGroupId, GrpFragments>& 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()

View File

@ -340,7 +340,7 @@ private:
const RsGxsGroupId& grpId, uint32_t& transN,
std::list<RsNxsItem*>& reqList);
bool locked_canReceive(const RsGxsGrpMetaData * const grpMeta, const RsPeerId& peerId);
//bool locked_canReceive(const RsGxsGrpMetaData * const grpMeta, const RsPeerId& peerId);
void processExplicitGroupRequests();

View File

@ -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()

View File

@ -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 ;

View File

@ -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 ;

View File

@ -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 ;

View File

@ -26,8 +26,8 @@
#include "rsthreads.h"
#include <unistd.h> /* for usleep() */
#include <errno.h> /* for usleep() */
#include <unistd.h> // for usleep()
#include <errno.h> // for errno
#include <iostream>
#include <time.h>
@ -35,10 +35,6 @@
#include <stdio.h>
#endif
#if defined(WINDOWS_SYS) && defined(__MINGW64_VERSION_MAJOR)
#include <windows.h> // 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
}
}