mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-05-04 23:25:32 -04:00
replaced usleep() by rstime::rs_usleep() which accepts times >= 1 sec. Should fix problems on windows
This commit is contained in:
parent
c1fccef53b
commit
d0039241d3
28 changed files with 134 additions and 100 deletions
|
@ -38,7 +38,7 @@
|
|||
#include "crypto/chacha20.h"
|
||||
#include "util/rsprint.h"
|
||||
#include "util/rsrandom.h"
|
||||
#include "util/rsscopetimer.h"
|
||||
#include "util/rstime.h"
|
||||
|
||||
#define rotl(x,n) { x = (x << n) | (x >> (-n & 31)) ;}
|
||||
|
||||
|
@ -1385,27 +1385,27 @@ bool perform_tests()
|
|||
uint8_t received_tag[16] ;
|
||||
|
||||
{
|
||||
RsScopeTimer s("AEAD1") ;
|
||||
rstime::RsScopeTimer s("AEAD1") ;
|
||||
chacha20_encrypt_rs(key, 1, nonce, ten_megabyte_data,SIZE) ;
|
||||
|
||||
std::cerr << " Chacha20 encryption speed : " << SIZE / (1024.0*1024.0) / s.duration() << " MB/s" << std::endl;
|
||||
}
|
||||
{
|
||||
RsScopeTimer s("AEAD2") ;
|
||||
rstime::RsScopeTimer s("AEAD2") ;
|
||||
AEAD_chacha20_poly1305_rs(key,nonce,ten_megabyte_data,SIZE,aad,12,received_tag,true) ;
|
||||
|
||||
std::cerr << " AEAD/poly1305 own encryption speed : " << SIZE / (1024.0*1024.0) / s.duration() << " MB/s" << std::endl;
|
||||
}
|
||||
#if OPENSSL_VERSION_NUMBER >= 0x010100000L && !defined(LIBRESSL_VERSION_NUMBER)
|
||||
{
|
||||
RsScopeTimer s("AEAD3") ;
|
||||
rstime::RsScopeTimer s("AEAD3") ;
|
||||
AEAD_chacha20_poly1305_openssl(key,nonce,ten_megabyte_data,SIZE,aad,12,received_tag,true) ;
|
||||
|
||||
std::cerr << " AEAD/poly1305 openssl encryption speed: " << SIZE / (1024.0*1024.0) / s.duration() << " MB/s" << std::endl;
|
||||
}
|
||||
#endif
|
||||
{
|
||||
RsScopeTimer s("AEAD4") ;
|
||||
rstime::RsScopeTimer s("AEAD4") ;
|
||||
AEAD_chacha20_sha256(key,nonce,ten_megabyte_data,SIZE,aad,12,received_tag,true) ;
|
||||
|
||||
std::cerr << " AEAD/sha256 encryption speed : " << SIZE / (1024.0*1024.0) / s.duration() << " MB/s" << std::endl;
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
*
|
||||
*/
|
||||
#include "util/folderiterator.h"
|
||||
#include "util/rstime.h"
|
||||
#include "rsserver/p3face.h"
|
||||
|
||||
#include "directory_storage.h"
|
||||
|
@ -92,7 +93,7 @@ void LocalDirectoryUpdater::data_tick()
|
|||
|
||||
for(uint32_t i=0;i<10;++i)
|
||||
{
|
||||
usleep(1*1000*1000);
|
||||
rstime::rs_usleep(1*1000*1000);
|
||||
|
||||
{
|
||||
if(mForceUpdate)
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
*/
|
||||
#include "util/rsdir.h"
|
||||
#include "util/rsprint.h"
|
||||
#include "util/rsscopetimer.h"
|
||||
#include "util/rstime.h"
|
||||
#include "rsserver/p3face.h"
|
||||
#include "pqi/authssl.h"
|
||||
#include "hash_cache.h"
|
||||
|
@ -125,7 +125,7 @@ void HashStorage::data_tick()
|
|||
std::cerr << "nothing to hash. Sleeping for " << st << " us" << std::endl;
|
||||
#endif
|
||||
|
||||
usleep(st); // when no files to hash, just wait for 2 secs. This avoids a dramatic loop.
|
||||
rstime::rs_usleep(st); // when no files to hash, just wait for 2 secs. This avoids a dramatic loop.
|
||||
|
||||
if(st > MAX_INACTIVITY_SLEEP_TIME)
|
||||
{
|
||||
|
@ -163,7 +163,7 @@ void HashStorage::data_tick()
|
|||
|
||||
if(paused) // we need to wait off mutex!!
|
||||
{
|
||||
usleep(MAX_INACTIVITY_SLEEP_TIME) ;
|
||||
rstime::rs_usleep(MAX_INACTIVITY_SLEEP_TIME) ;
|
||||
std::cerr << "Hashing process currently paused." << std::endl;
|
||||
return;
|
||||
}
|
||||
|
@ -190,7 +190,7 @@ void HashStorage::data_tick()
|
|||
|
||||
RsServer::notify()->notifyHashingInfo(NOTIFY_HASHTYPE_HASH_FILE, tmpout) ;
|
||||
|
||||
double seconds_origin = RsScopeTimer::currentTime() ;
|
||||
double seconds_origin = rstime::RsScopeTimer::currentTime() ;
|
||||
|
||||
if(RsDirUtil::getFileHash(job.full_path, hash,size, this))
|
||||
{
|
||||
|
@ -215,7 +215,7 @@ void HashStorage::data_tick()
|
|||
else
|
||||
std::cerr << "ERROR: cannot hash file " << job.full_path << std::endl;
|
||||
|
||||
mHashingTime += RsScopeTimer::currentTime() - seconds_origin ;
|
||||
mHashingTime += rstime::RsScopeTimer::currentTime() - seconds_origin ;
|
||||
mHashedBytes += size ;
|
||||
|
||||
if(mHashingTime > 3)
|
||||
|
|
|
@ -40,6 +40,7 @@
|
|||
#endif
|
||||
#include "util/rsdiscspace.h"
|
||||
#include "util/rsmemory.h"
|
||||
#include "util/rstime.h"
|
||||
|
||||
#include "ft/ftcontroller.h"
|
||||
|
||||
|
@ -219,7 +220,7 @@ void ftController::data_tick()
|
|||
/* check the queues */
|
||||
|
||||
//Waiting 1 sec before start
|
||||
usleep(1*1000*1000); // 1 sec
|
||||
rstime::rs_usleep(1*1000*1000); // 1 sec
|
||||
|
||||
#ifdef CONTROL_DEBUG
|
||||
//std::cerr << "ftController::run()";
|
||||
|
|
|
@ -32,6 +32,7 @@
|
|||
#include "ft/ftextralist.h"
|
||||
#include "rsitems/rsconfigitems.h"
|
||||
#include "util/rsdir.h"
|
||||
#include "util/rstime.h"
|
||||
#include <stdio.h>
|
||||
#include <unistd.h> /* for (u)sleep() */
|
||||
#include <time.h>
|
||||
|
@ -64,12 +65,8 @@ void ftExtraList::data_tick()
|
|||
/* Hash a file */
|
||||
hashAFile();
|
||||
|
||||
#ifdef WIN32
|
||||
Sleep(1);
|
||||
#else
|
||||
/* microsleep */
|
||||
usleep(10);
|
||||
#endif
|
||||
rstime::rs_usleep(10);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -513,16 +510,7 @@ bool ftExtraList::loadList(std::list<RsItem *>& load)
|
|||
delete (*it);
|
||||
|
||||
/* short sleep */
|
||||
#ifndef WINDOWS_SYS
|
||||
/********************************** WINDOWS/UNIX SPECIFIC PART ******************/
|
||||
usleep(1000); /* 1000 per second */
|
||||
|
||||
#else
|
||||
/********************************** WINDOWS/UNIX SPECIFIC PART ******************/
|
||||
Sleep(1);
|
||||
#endif
|
||||
/********************************** WINDOWS/UNIX SPECIFIC PART ******************/
|
||||
|
||||
rstime::rs_usleep(1000) ;
|
||||
}
|
||||
load.clear() ;
|
||||
return true;
|
||||
|
|
|
@ -35,7 +35,7 @@
|
|||
#include <algorithm>
|
||||
|
||||
#ifdef RS_DATA_SERVICE_DEBUG_TIME
|
||||
#include <util/rsscopetimer.h>
|
||||
#include <util/rstime.h>
|
||||
#endif
|
||||
|
||||
#include "rsdataservice.h"
|
||||
|
@ -1066,7 +1066,7 @@ bool RsDataService::validSize(RsNxsGrp* grp) const
|
|||
int RsDataService::retrieveNxsGrps(std::map<RsGxsGroupId, RsNxsGrp *> &grp, bool withMeta, bool /* cache */)
|
||||
{
|
||||
#ifdef RS_DATA_SERVICE_DEBUG_TIME
|
||||
RsScopeTimer timer("");
|
||||
rstime::RsScopeTimer timer("");
|
||||
int resultCount = 0;
|
||||
int requestedGroups = grp.size();
|
||||
#endif
|
||||
|
@ -1166,7 +1166,7 @@ void RsDataService::locked_retrieveGroups(RetroCursor* c, std::vector<RsNxsGrp*>
|
|||
int RsDataService::retrieveNxsMsgs(const GxsMsgReq &reqIds, GxsMsgResult &msg, bool /* cache */, bool withMeta)
|
||||
{
|
||||
#ifdef RS_DATA_SERVICE_DEBUG_TIME
|
||||
RsScopeTimer timer("");
|
||||
rstime::RsScopeTimer timer("");
|
||||
int resultCount = 0;
|
||||
#endif
|
||||
|
||||
|
@ -1254,7 +1254,7 @@ int RsDataService::retrieveGxsMsgMetaData(const GxsMsgReq& reqIds, GxsMsgMetaRes
|
|||
RsStackMutex stack(mDbMutex);
|
||||
|
||||
#ifdef RS_DATA_SERVICE_DEBUG_TIME
|
||||
RsScopeTimer timer("");
|
||||
rstime::RsScopeTimer timer("");
|
||||
int resultCount = 0;
|
||||
#endif
|
||||
|
||||
|
@ -1341,7 +1341,7 @@ int RsDataService::retrieveGxsGrpMetaData(RsGxsGrpMetaTemporaryMap& grp)
|
|||
RsStackMutex stack(mDbMutex);
|
||||
|
||||
#ifdef RS_DATA_SERVICE_DEBUG_TIME
|
||||
RsScopeTimer timer("");
|
||||
rstime::RsScopeTimer timer("");
|
||||
int resultCount = 0;
|
||||
int requestedGroups = grp.size();
|
||||
#endif
|
||||
|
@ -1549,7 +1549,7 @@ int RsDataService::retrieveGroupIds(std::vector<RsGxsGroupId> &grpIds)
|
|||
RsStackMutex stack(mDbMutex);
|
||||
|
||||
#ifdef RS_DATA_SERVICE_DEBUG_TIME
|
||||
RsScopeTimer timer("");
|
||||
rstime::RsScopeTimer timer("");
|
||||
int resultCount = 0;
|
||||
#endif
|
||||
|
||||
|
@ -1586,7 +1586,7 @@ int RsDataService::retrieveGroupIds(std::vector<RsGxsGroupId> &grpIds)
|
|||
int RsDataService::retrieveMsgIds(const RsGxsGroupId& grpId, RsGxsMessageId::std_vector& msgIds)
|
||||
{
|
||||
#ifdef RS_DATA_SERVICE_DEBUG_TIME
|
||||
RsScopeTimer timer("");
|
||||
rstime::RsScopeTimer timer("");
|
||||
int resultCount = 0;
|
||||
#endif
|
||||
|
||||
|
|
|
@ -31,6 +31,7 @@
|
|||
#include "gxssecurity.h"
|
||||
#include "util/contentvalue.h"
|
||||
#include "util/rsprint.h"
|
||||
#include "util/rstime.h"
|
||||
#include "retroshare/rsgxsflags.h"
|
||||
#include "retroshare/rsgxscircles.h"
|
||||
#include "retroshare/rsgrouter.h"
|
||||
|
@ -138,7 +139,7 @@ void RsGenExchange::data_tick()
|
|||
static const double timeDelta = 0.1; // slow tick in sec
|
||||
|
||||
tick();
|
||||
usleep((int) (timeDelta * 1000 *1000)); // timeDelta sec
|
||||
rstime::rs_usleep((int) (timeDelta * 1000 *1000)); // timeDelta sec
|
||||
}
|
||||
|
||||
void RsGenExchange::tick()
|
||||
|
|
|
@ -210,6 +210,7 @@
|
|||
#include "retroshare/rspeers.h"
|
||||
#include "pgp/pgpauxutils.h"
|
||||
#include "util/rsdir.h"
|
||||
#include "util/rstime.h"
|
||||
#include "util/rsmemory.h"
|
||||
#include "util/stacktrace.h"
|
||||
|
||||
|
@ -1787,7 +1788,7 @@ void RsGxsNetService::data_tick()
|
|||
static const double timeDelta = 0.5;
|
||||
|
||||
//Start waiting as nothing to do in runup
|
||||
usleep((int) (timeDelta * 1000 * 1000)); // timeDelta sec
|
||||
rstime::rs_usleep((int) (timeDelta * 1000 * 1000)); // timeDelta sec
|
||||
|
||||
if(mUpdateCounter >= 120) // 60 seconds
|
||||
{
|
||||
|
|
|
@ -547,7 +547,7 @@ HEADERS += util/folderiterator.h \
|
|||
util/rsmemcache.h \
|
||||
util/rstickevent.h \
|
||||
util/rsrecogn.h \
|
||||
util/rsscopetimer.h \
|
||||
util/rstime.h \
|
||||
util/stacktrace.h \
|
||||
util/rsdeprecate.h \
|
||||
util/cxx11retrocompat.h
|
||||
|
@ -695,7 +695,7 @@ SOURCES += util/folderiterator.cc \
|
|||
util/rsrandom.cc \
|
||||
util/rstickevent.cc \
|
||||
util/rsrecogn.cc \
|
||||
util/rsscopetimer.cc
|
||||
util/rstime.cc
|
||||
|
||||
|
||||
upnp_miniupnpc {
|
||||
|
|
|
@ -35,6 +35,7 @@
|
|||
#include "pgp/pgphandler.h"
|
||||
|
||||
#include <util/rsdir.h>
|
||||
#include <util/rstime.h>
|
||||
#include <pgp/pgpkeyutil.h>
|
||||
#include <unistd.h> /* for (u)sleep() */
|
||||
#include <iostream>
|
||||
|
@ -187,7 +188,7 @@ int AuthGPG::GPGInit(const RsPgpId &ownId)
|
|||
|
||||
void AuthGPG::data_tick()
|
||||
{
|
||||
usleep(100 * 1000); //100 msec
|
||||
rstime::rs_usleep(100 * 1000); //100 msec
|
||||
|
||||
/// every 100 milliseconds
|
||||
processServices();
|
||||
|
|
|
@ -35,6 +35,7 @@
|
|||
|
||||
#include "util/rsdebug.h"
|
||||
#include "util/rsnet.h"
|
||||
#include "util/rstime.h"
|
||||
#include "util/rsstring.h"
|
||||
|
||||
#include "pqi/p3linkmgr.h"
|
||||
|
@ -571,7 +572,7 @@ bool pqissludp::moretoread(uint32_t usec)
|
|||
{
|
||||
return true;
|
||||
}
|
||||
usleep(usec);
|
||||
rstime::rs_usleep(usec);
|
||||
}
|
||||
|
||||
/* check for more to read first ... if nothing... check error
|
||||
|
@ -655,7 +656,7 @@ bool pqissludp::cansend(uint32_t usec)
|
|||
return true;
|
||||
}
|
||||
|
||||
usleep(usec);
|
||||
rstime::rs_usleep(usec);
|
||||
}
|
||||
|
||||
rslog(RSL_DEBUG_ALL, pqissludpzone,
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
*/
|
||||
|
||||
|
||||
#include "util/rstime.h"
|
||||
#include "pqi/pqithreadstreamer.h"
|
||||
#include <unistd.h>
|
||||
|
||||
|
@ -69,7 +70,7 @@ void pqithreadstreamer::data_tick()
|
|||
|
||||
if (!isactive)
|
||||
{
|
||||
usleep(DEFAULT_STREAMER_IDLE_SLEEP);
|
||||
rstime::rs_usleep(DEFAULT_STREAMER_IDLE_SLEEP);
|
||||
return ;
|
||||
}
|
||||
|
||||
|
@ -92,7 +93,7 @@ void pqithreadstreamer::data_tick()
|
|||
|
||||
if (sleep_period)
|
||||
{
|
||||
usleep(sleep_period);
|
||||
rstime::rs_usleep(sleep_period);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
*/
|
||||
|
||||
|
||||
#include "util/rstime.h"
|
||||
#include "rsserver/p3face.h"
|
||||
#include "retroshare/rsplugin.h"
|
||||
|
||||
|
@ -134,11 +135,7 @@ RsServer::~RsServer()
|
|||
/* Thread Fn: Run the Core */
|
||||
void RsServer::data_tick()
|
||||
{
|
||||
#ifndef WINDOWS_SYS
|
||||
usleep((int) (mTimeDelta * 1000000));
|
||||
#else
|
||||
Sleep((int) (mTimeDelta * 1000));
|
||||
#endif
|
||||
rstime::rs_usleep(mTimeDelta * 1000000);
|
||||
|
||||
double ts = getCurrentTS();
|
||||
double delta = ts - mLastts;
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
#include "util/radix32.h"
|
||||
#include "util/radix64.h"
|
||||
#include "util/rsdebug.h"
|
||||
#include "util/rstime.h"
|
||||
#include "util/rsprint.h"
|
||||
#include "util/rsrandom.h"
|
||||
|
||||
|
@ -39,7 +40,7 @@ static struct RsLog::logInfo i2pBobLogInfo = {RsLog::Default, "p3I2pBob"};
|
|||
static const time_t selfCheckPeroid = 30;
|
||||
|
||||
void doSleep(useconds_t timeToSleepMS) {
|
||||
usleep((useconds_t) (timeToSleepMS * 1000));
|
||||
rstime::rs_usleep((useconds_t) (timeToSleepMS * 1000));
|
||||
}
|
||||
|
||||
p3I2pBob::p3I2pBob(p3PeerMgr *peerMgr)
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#include "rsautoproxymonitor.h"
|
||||
|
||||
#include <unistd.h> /* for usleep() */
|
||||
#include "util/rstime.h"
|
||||
|
||||
rsAutoProxyMonitor *rsAutoProxyMonitor::mInstance = NULL;
|
||||
|
||||
|
@ -93,7 +94,7 @@ void rsAutoProxyMonitor::stopAllRSShutdown()
|
|||
// wait for shutdown of all services
|
||||
uint32_t t = 0, timeout = 15;
|
||||
do {
|
||||
usleep(1000 * 1000);
|
||||
rstime::rs_usleep(1000 * 1000);
|
||||
RS_STACK_MUTEX(mLock);
|
||||
std::cout << "(II) waiting for auto proxy service(s) to shut down " << t << "/" << timeout << " (remaining: " << mProxies.size() << ")" << std::endl;
|
||||
if (mProxies.empty())
|
||||
|
|
|
@ -34,6 +34,7 @@
|
|||
#include "util/rsstring.h"
|
||||
#include "util/radix64.h"
|
||||
#include "util/rsdir.h"
|
||||
#include "util/rstime.h"
|
||||
#include "crypto/hashstream.h"
|
||||
#include "gxs/gxssecurity.h"
|
||||
#include "retroshare/rspeers.h"
|
||||
|
@ -1071,7 +1072,7 @@ bool p3IdService::signData(const uint8_t *data,uint32_t data_size,const RsGxsId&
|
|||
#ifdef DEBUG_IDS
|
||||
std::cerr << " Cannot get key. Waiting for caching. try " << i << "/6" << std::endl;
|
||||
#endif
|
||||
usleep(500 * 1000) ; // sleep for 500 msec.
|
||||
rstime::rs_usleep(500 * 1000) ; // sleep for 500 msec.
|
||||
}
|
||||
else
|
||||
break ;
|
||||
|
@ -1110,7 +1111,7 @@ bool p3IdService::validateData(const uint8_t *data,uint32_t data_size,const RsTl
|
|||
#ifdef DEBUG_IDS
|
||||
std::cerr << " Cannot get key. Waiting for caching. try " << i << "/6" << std::endl;
|
||||
#endif
|
||||
if(force_load) usleep(500 * 1000) ; // sleep for 500 msec.
|
||||
if(force_load) rstime::rs_usleep(500 * 1000) ; // sleep for 500 msec.
|
||||
}
|
||||
else
|
||||
break ;
|
||||
|
@ -1151,7 +1152,7 @@ bool p3IdService::encryptData( const uint8_t *decrypted_data,
|
|||
if(getKey(encryption_key_id,encryption_key))
|
||||
break ;
|
||||
else
|
||||
usleep(500*1000) ; // sleep half a sec.
|
||||
rstime::rs_usleep(500*1000) ; // sleep half a sec.
|
||||
|
||||
if(encryption_key.keyId.isNull())
|
||||
{
|
||||
|
@ -1222,7 +1223,7 @@ bool p3IdService::encryptData( const uint8_t* decrypted_data,
|
|||
}
|
||||
|
||||
if(keyNotYetFoundIds.empty()) break;
|
||||
else usleep(500*1000);
|
||||
else rstime::rs_usleep(500*1000);
|
||||
}
|
||||
|
||||
if(!keyNotYetFoundIds.empty())
|
||||
|
@ -1279,7 +1280,7 @@ bool p3IdService::decryptData( const uint8_t *encrypted_data,
|
|||
int maxRounds = force_load ? 6 : 1;
|
||||
for(int i=0; i<maxRounds ;++i)
|
||||
if(getPrivateKey(key_id,encryption_key)) break;
|
||||
else usleep(500*1000) ; // sleep half a sec.
|
||||
else rstime::rs_usleep(500*1000) ; // sleep half a sec.
|
||||
|
||||
if(encryption_key.keyId.isNull())
|
||||
{
|
||||
|
@ -1356,7 +1357,7 @@ bool p3IdService::decryptData( const uint8_t* encrypted_data,
|
|||
}
|
||||
|
||||
if(keyNotYetFoundIds.empty()) break;
|
||||
else usleep(500*1000);
|
||||
else rstime::rs_usleep(500*1000);
|
||||
}
|
||||
|
||||
if(!keyNotYetFoundIds.empty())
|
||||
|
|
|
@ -33,6 +33,7 @@
|
|||
#include "util/rsdir.h"
|
||||
#include "util/rsstring.h"
|
||||
#include "util/rsrandom.h"
|
||||
#include "util/rstime.h"
|
||||
#include "util/rsmemory.h"
|
||||
#include "util/folderiterator.h"
|
||||
#include "retroshare/rstypes.h"
|
||||
|
@ -711,7 +712,7 @@ bool RsDirUtil::renameFile(const std::string& from, const std::string& to)
|
|||
#endif
|
||||
/* set errno? */
|
||||
return false ;
|
||||
usleep(100 * 1000); // 100 msec
|
||||
rstime::rs_usleep(100 * 1000); // 100 msec
|
||||
|
||||
if (loops >= 30)
|
||||
return false ;
|
||||
|
@ -917,7 +918,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;
|
||||
usleep(1 * 1000 * 1000) ; // 1 sec
|
||||
rstime::rs_usleep(1 * 1000 * 1000) ; // 1 sec
|
||||
}
|
||||
#ifdef RSDIR_DEBUG
|
||||
std::cerr << "Acquired file handle " << _file_handle << ", lock file:" << file_path << std::endl;
|
||||
|
@ -1321,7 +1322,7 @@ bool RsDirUtil::renameWideFile(const std::wstring& from, const std::wstring& to)
|
|||
#endif
|
||||
/* set errno? */
|
||||
return false ;
|
||||
usleep(100 * 1000); //100 msec
|
||||
rstime::rs_usleep(100 * 1000); //100 msec
|
||||
|
||||
if (loops >= 30)
|
||||
return false ;
|
||||
|
|
|
@ -30,6 +30,8 @@
|
|||
#include <iostream>
|
||||
#include <time.h>
|
||||
|
||||
#include "util/rstime.h"
|
||||
|
||||
#ifdef __APPLE__
|
||||
int __attribute__((weak)) pthread_setname_np(const char *__buf) ;
|
||||
int RS_pthread_setname_np(pthread_t /*__target_thread*/, const char *__buf) {
|
||||
|
@ -289,7 +291,7 @@ void RsQueueThread::data_tick()
|
|||
THREAD_DEBUG << "RsQueueThread::data_tick() no work: sleeping for: " << mLastSleep << " ms" << std::endl;
|
||||
#endif
|
||||
}
|
||||
usleep(mLastSleep * 1000); // mLastSleep msec
|
||||
rstime::rs_usleep(mLastSleep * 1000); // mLastSleep msec
|
||||
}
|
||||
|
||||
void RsMutex::unlock()
|
||||
|
|
|
@ -24,8 +24,28 @@
|
|||
*/
|
||||
|
||||
#include <iostream>
|
||||
#include <thread>
|
||||
#include <sys/time.h>
|
||||
#include "rsscopetimer.h"
|
||||
#include <sys/unistd.h>
|
||||
#include "rstime.h"
|
||||
|
||||
namespace rstime {
|
||||
|
||||
int rs_usleep(uint32_t micro_seconds)
|
||||
{
|
||||
while(micro_seconds >= 1000000)
|
||||
{
|
||||
// usleep cannot be called with 1000000 or more.
|
||||
|
||||
usleep(500000) ;
|
||||
usleep(500000) ;
|
||||
|
||||
micro_seconds -= 1000000 ;
|
||||
}
|
||||
usleep(micro_seconds) ;
|
||||
|
||||
return 0 ;
|
||||
}
|
||||
|
||||
RsScopeTimer::RsScopeTimer(const std::string& name)
|
||||
{
|
||||
|
@ -57,3 +77,5 @@ double RsScopeTimer::duration()
|
|||
{
|
||||
return currentTime() - _seconds;
|
||||
}
|
||||
|
||||
}
|
|
@ -23,29 +23,40 @@
|
|||
*
|
||||
*/
|
||||
|
||||
// Use this class to measure and display time duration of a given environment:
|
||||
//
|
||||
// {
|
||||
// RsScopeTimer timer("callToMeasure()") ;
|
||||
//
|
||||
// callToMeasure() ;
|
||||
// }
|
||||
//
|
||||
|
||||
#include <string>
|
||||
|
||||
class RsScopeTimer
|
||||
{
|
||||
public:
|
||||
RsScopeTimer(const std::string& name);
|
||||
~RsScopeTimer();
|
||||
namespace rstime {
|
||||
|
||||
void start();
|
||||
double duration();
|
||||
/*!
|
||||
* \brief This is a cross-system definition of usleep, which accepts any 32 bits number of micro-seconds.
|
||||
*/
|
||||
|
||||
static double currentTime();
|
||||
int rs_usleep(uint32_t micro_seconds);
|
||||
|
||||
private:
|
||||
std::string _name ;
|
||||
double _seconds ;
|
||||
};
|
||||
/* Use this class to measure and display time duration of a given environment:
|
||||
|
||||
{
|
||||
RsScopeTimer timer("callToMeasure()") ;
|
||||
|
||||
callToMeasure() ;
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
class RsScopeTimer
|
||||
{
|
||||
public:
|
||||
RsScopeTimer(const std::string& name);
|
||||
~RsScopeTimer();
|
||||
|
||||
void start();
|
||||
double duration();
|
||||
|
||||
static double currentTime();
|
||||
|
||||
private:
|
||||
std::string _name ;
|
||||
double _seconds ;
|
||||
};
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue