1
0
Fork 0

remove TRI_usleep and TRI_sleep, and use std::this_thread::sleep_for … (#3817)

This commit is contained in:
Jan 2017-12-06 18:43:49 +01:00 committed by GitHub
parent 6bdc26e5c9
commit 282be208cc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
79 changed files with 273 additions and 572 deletions

View File

@ -988,7 +988,7 @@ uint64_t AgencyComm::uniqid(uint64_t count, double timeout) {
while (tries++ < maxTries) {
result = getValues("Sync/LatestID");
if (!result.successful()) {
usleep(500000);
std::this_thread::sleep_for(std::chrono::microseconds(500000));
continue;
}
@ -1024,7 +1024,7 @@ uint64_t AgencyComm::uniqid(uint64_t count, double timeout) {
try {
newBuilder.add(VPackValue(newValue));
} catch (...) {
usleep(500000);
std::this_thread::sleep_for(std::chrono::microseconds(500000));
continue;
}
@ -1189,7 +1189,7 @@ bool AgencyComm::ensureStructureInitialized() {
LOG_TOPIC(WARN, Logger::AGENCYCOMM)
<< "Initializing agency failed. We'll try again soon";
// We should really have exclusive access, here, this is strange!
sleep(1);
std::this_thread::sleep_for(std::chrono::seconds(1));
}
AgencyCommResult result = getValues("InitDone");
@ -1207,7 +1207,7 @@ bool AgencyComm::ensureStructureInitialized() {
LOG_TOPIC(TRACE, Logger::AGENCYCOMM)
<< "Waiting for agency to get initialized";
sleep(1);
std::this_thread::sleep_for(std::chrono::seconds(1));
}
return true;
@ -1248,7 +1248,7 @@ bool AgencyComm::lock(std::string const& key, double ttl, double timeout,
return true;
}
usleep((TRI_usleep_t) sleepTime);
std::this_thread::sleep_for(std::chrono::microseconds(sleepTime));
if (sleepTime < MAX_SLEEP_TIME) {
sleepTime += INITIAL_SLEEP_TIME;
@ -1289,7 +1289,7 @@ bool AgencyComm::unlock(std::string const& key, VPackSlice const& slice,
return true;
}
usleep((TRI_usleep_t)sleepTime);
std::this_thread::sleep_for(std::chrono::microseconds(sleepTime));
if (sleepTime < MAX_SLEEP_TIME) {
sleepTime += INITIAL_SLEEP_TIME;

View File

@ -315,7 +315,7 @@ void AgencyFeature::stop() {
if (_agent->inception() != nullptr) { // can only exist in resilient agents
int counter = 0;
while (_agent->inception()->isRunning()) {
usleep(100000);
std::this_thread::sleep_for(std::chrono::microseconds(100000));
// emit warning after 5 seconds
if (++counter == 10 * 5) {
LOG_TOPIC(WARN, Logger::AGENCY) << "waiting for inception thread to finish";
@ -326,7 +326,7 @@ void AgencyFeature::stop() {
if (_agent != nullptr) {
int counter = 0;
while (_agent->isRunning()) {
usleep(100000);
std::this_thread::sleep_for(std::chrono::microseconds(100000));
// emit warning after 5 seconds
if (++counter == 10 * 5) {
LOG_TOPIC(WARN, Logger::AGENCY) << "waiting for agent thread to finish";

View File

@ -102,7 +102,7 @@ void Agent::waitForThreadsStop() {
while (_constituent.isRunning() || _compactor.isRunning() ||
(_config.supervision() && _supervision.isRunning()) ||
(_inception != nullptr && _inception->isRunning())) {
usleep(100000);
std::this_thread::sleep_for(std::chrono::microseconds(100000));
// fail fatally after 5 mins:
if (++counter >= 10 * 60 * 5) {

View File

@ -403,7 +403,7 @@ void Inception::reportVersionForEp(std::string const& endpoint, size_t version)
void Inception::run() {
while (ServerState::isMaintenance() &&
!this->isStopping() && !_agent->isStopping()) {
usleep(1000000);
std::this_thread::sleep_for(std::chrono::microseconds(1000000));
LOG_TOPIC(DEBUG, Logger::AGENCY)
<< "Waiting for RestHandlerFactory to exit maintenance mode before we "
" start gossip protocol...";

View File

@ -89,7 +89,7 @@ Result AqlTransaction::processCollectionNormal(aql::Collection* collection) {
auto startTime = TRI_microtime();
auto endTime = startTime + 60.0;
do {
usleep(10000);
std::this_thread::sleep_for(std::chrono::microseconds(10000));
if (TRI_microtime() > endTime) {
break;
}

View File

@ -78,7 +78,7 @@ int EnumerateCollectionBlock::initialize() {
if (endTime - now < waitInterval) {
waitInterval = static_cast<unsigned long>(endTime - now);
}
usleep((TRI_usleep_t)waitInterval);
std::this_thread::sleep_for(std::chrono::microseconds(waitInterval));
}
now = TRI_microtime();
if (now > endTime) {

View File

@ -1760,7 +1760,7 @@ AqlValue Functions::Sleep(arangodb::aql::Query* query,
double const until = TRI_microtime() + value.toDouble(trx);
while (TRI_microtime() < until) {
usleep(30000);
std::this_thread::sleep_for(std::chrono::microseconds(30000));
if (query->killed()) {
THROW_ARANGO_EXCEPTION(TRI_ERROR_QUERY_KILLED);

View File

@ -681,7 +681,7 @@ bool RestAqlHandler::findQuery(std::string const& idString, Query*& query) {
} catch (...) {
// we can only get here if the query is currently used by someone
// else. in this case we sleep for a while and re-try
usleep(SingleWaitPeriod);
std::this_thread::sleep_for(std::chrono::microseconds(SingleWaitPeriod));
}
}

View File

@ -959,11 +959,7 @@ size_t ClusterComm::performRequests(std::vector<ClusterCommRequest>& requests,
// is in flight, this is possible, since we might have scheduled
// a retry later than now and simply wait till then
if (now < actionNeeded) {
#ifdef _WIN32
usleep((unsigned long) ((actionNeeded - now) * 1000000));
#else
usleep((useconds_t) ((actionNeeded - now) * 1000000));
#endif
std::this_thread::sleep_for(std::chrono::microseconds((unsigned long long) ((actionNeeded - now) * 1000000.0)));
}
continue;
}
@ -1259,7 +1255,7 @@ void ClusterCommThread::run() {
_cc->communicator()->abortRequests();
LOG_TOPIC(DEBUG, Logger::CLUSTER) << "waiting for curl to stop remaining handles";
while (_cc->communicator()->work_once() > 0) {
usleep(10);
std::this_thread::sleep_for(std::chrono::microseconds(10));
}
LOG_TOPIC(DEBUG, Logger::CLUSTER) << "stopped ClusterComm thread";

View File

@ -348,7 +348,7 @@ void ClusterFeature::prepare() {
LOG_TOPIC(INFO, arangodb::Logger::CLUSTER) << "Found " << DBServers.size() << " DBservers.";
break;
}
sleep(1);
std::this_thread::sleep_for(std::chrono::seconds(1));
}
}
@ -435,7 +435,7 @@ void ClusterFeature::start() {
while (!_heartbeatThread->isReady()) {
// wait until heartbeat is ready
usleep(10000);
std::this_thread::sleep_for(std::chrono::microseconds(10000));
}
}
@ -463,7 +463,7 @@ void ClusterFeature::start() {
break;
}
sleep(1);
std::this_thread::sleep_for(std::chrono::seconds(1));
}
ServerState::instance()->setState(ServerState::STATE_SERVING);
@ -483,7 +483,7 @@ void ClusterFeature::stop() {
if (_heartbeatThread != nullptr) {
int counter = 0;
while (_heartbeatThread->isRunning()) {
usleep(100000);
std::this_thread::sleep_for(std::chrono::microseconds(100000));
// emit warning after 5 seconds
if (++counter == 10 * 5) {
LOG_TOPIC(WARN, arangodb::Logger::CLUSTER) << "waiting for heartbeat thread to finish";
@ -510,7 +510,7 @@ void ClusterFeature::unprepare() {
if (_heartbeatThread != nullptr) {
int counter = 0;
while (_heartbeatThread->isRunning()) {
usleep(100000);
std::this_thread::sleep_for(std::chrono::microseconds(100000));
// emit warning after 5 seconds
if (++counter == 10 * 5) {
LOG_TOPIC(WARN, arangodb::Logger::CLUSTER) << "waiting for heartbeat thread to finish";
@ -553,7 +553,7 @@ void ClusterFeature::unprepare() {
comm.sendTransactionWithFailover(unreg, 120.0);
while (_heartbeatThread->isRunning()) {
usleep(50000);
std::this_thread::sleep_for(std::chrono::microseconds(50000));
}
AgencyCommManager::MANAGER->stop();

View File

@ -2679,7 +2679,7 @@ std::shared_ptr<std::vector<ServerID>> ClusterInfo::getResponsibleServer(
}
}
}
usleep(500000);
std::this_thread::sleep_for(std::chrono::microseconds(500000));
}
if (++tries >= 2) {

View File

@ -168,7 +168,7 @@ void FollowerInfo::add(ServerID const& sid) {
LOG_TOPIC(ERR, Logger::CLUSTER) << "FollowerInfo::add, could not read "
<< path << " in agency.";
}
usleep(500000);
std::this_thread::sleep_for(std::chrono::microseconds(500000));
} while (TRI_microtime() < startTime + 30);
if (!success) {
LOG_TOPIC(ERR, Logger::CLUSTER)
@ -272,7 +272,7 @@ bool FollowerInfo::remove(ServerID const& sid) {
LOG_TOPIC(ERR, Logger::CLUSTER) << "FollowerInfo::remove, could not read "
<< path << " in agency.";
}
usleep(500000);
std::this_thread::sleep_for(std::chrono::microseconds(500000));
} while (TRI_microtime() < startTime + 30);
if (!success) {
_followers = _oldFollowers;

View File

@ -195,7 +195,7 @@ void HeartbeatThread::run() {
// startup aborted
return;
}
usleep(100000);
std::this_thread::sleep_for(std::chrono::microseconds(100000));
}
}
@ -264,7 +264,7 @@ void HeartbeatThread::runDBServer() {
if (!registered) {
LOG_TOPIC(ERR, Logger::HEARTBEAT)
<< "Couldn't register plan change in agency!";
sleep(1);
std::this_thread::sleep_for(std::chrono::seconds(1));
}
}
@ -456,10 +456,10 @@ void HeartbeatThread::runSingleServer() {
// like arguments greater than 1000000
while (remain > 0.0) {
if (remain >= 0.5) {
usleep(500000);
std::this_thread::sleep_for(std::chrono::microseconds(500000));
remain -= 0.5;
} else {
usleep(static_cast<TRI_usleep_t>(remain * 1000.0 * 1000.0));
std::this_thread::sleep_for(std::chrono::microseconds(uint64_t(remain * 1000.0 * 1000.0)));
remain = 0.0;
}
}
@ -600,7 +600,7 @@ void HeartbeatThread::runSingleServer() {
<< res.errorMessage();
}
// wait for everything to calm down for good measure
sleep(10);
std::this_thread::sleep_for(std::chrono::seconds(10));
}
if (applier->endpoint() != endpoint) {
@ -910,10 +910,10 @@ void HeartbeatThread::runCoordinator() {
// like arguments greater than 1000000
while (remain > 0.0) {
if (remain >= 0.5) {
usleep(500000);
std::this_thread::sleep_for(std::chrono::microseconds(500000));
remain -= 0.5;
} else {
usleep((TRI_usleep_t)(remain * 1000.0 * 1000.0));
std::this_thread::sleep_for(std::chrono::microseconds(uint64_t(remain * 1000.0 * 1000.0)));
remain = 0.0;
}
}
@ -964,8 +964,8 @@ void HeartbeatThread::dispatchedJobResult(DBServerAgencySyncResult result) {
if (doSleep) {
// Sleep a little longer, since this might be due to some synchronisation
// of shards going on in the background
usleep(500000);
usleep(500000);
std::this_thread::sleep_for(std::chrono::microseconds(500000));
std::this_thread::sleep_for(std::chrono::microseconds(500000));
}
CONDITION_LOCKER(guard, _condition);
_wasNotified = true;

View File

@ -110,7 +110,7 @@ ClusterSelectivityEstimates::ValueType ClusterSelectivityEstimates::fetch() {
}
now = TRI_microtime();
usleep(10000);
std::this_thread::sleep_for(std::chrono::microseconds(10000));
}
}

View File

@ -356,7 +356,7 @@ static int LookupLocalInfoToId(std::string const& localInfo,
}
}
}
sleep(1);
std::this_thread::sleep_for(std::chrono::seconds(1));
};
return TRI_ERROR_CLUSTER_COULD_NOT_DETERMINE_ID;
}
@ -567,7 +567,7 @@ bool ServerState::registerAtAgency(AgencyComm& comm,
if (!result.successful()) {
LOG_TOPIC(WARN, Logger::CLUSTER) << "Couldn't fetch " << targetIdStr
<< " and " << targetUrl;
sleep(1);
std::this_thread::sleep_for(std::chrono::seconds(1));
continue;
}
@ -627,7 +627,7 @@ bool ServerState::registerAtAgency(AgencyComm& comm,
if (result.successful()) {
return true;
}
sleep(1);
std::this_thread::sleep_for(std::chrono::seconds(1));
}
LOG_TOPIC(FATAL, Logger::STARTUP) << "Couldn't register shortname for " << id;

View File

@ -113,7 +113,7 @@ void MMFilesCleanupThread::run() {
locker.wait(cleanupInterval());
} else {
// prevent busy waiting
usleep(10000);
std::this_thread::sleep_for(std::chrono::microseconds(10000));
}
} catch (...) {

View File

@ -598,7 +598,7 @@ int MMFilesCollection::close() {
while (_ditches.contains(MMFilesDitch::TRI_DITCH_DATAFILE_DROP) ||
_ditches.contains(MMFilesDitch::TRI_DITCH_DATAFILE_RENAME) ||
_ditches.contains(MMFilesDitch::TRI_DITCH_COMPACTION)) {
usleep(20000);
std::this_thread::sleep_for(std::chrono::microseconds(20000));
}
{
@ -2552,7 +2552,7 @@ int MMFilesCollection::lockRead(bool useDeadlockDetector, double timeout) {
if (now - startTime < 0.001) {
std::this_thread::yield();
} else {
usleep(static_cast<TRI_usleep_t>(waitTime));
std::this_thread::sleep_for(std::chrono::microseconds(waitTime));
if (waitTime < 32) {
waitTime *= 2;
}
@ -2665,7 +2665,7 @@ int MMFilesCollection::lockWrite(bool useDeadlockDetector, double timeout) {
if (now - startTime < 0.001) {
std::this_thread::yield();
} else {
usleep(static_cast<TRI_usleep_t>(waitTime));
std::this_thread::sleep_for(std::chrono::microseconds(waitTime));
if (waitTime < 32) {
waitTime *= 2;
}

View File

@ -88,7 +88,7 @@ void MMFilesCollectionExport::run(uint64_t maxWaitTime, size_t limit) {
if (mmColl->isFullyCollected()) {
break;
}
usleep(SleepTime);
std::this_thread::sleep_for(std::chrono::microseconds(SleepTime));
}
}

View File

@ -997,7 +997,7 @@ int MMFilesCollectorThread::queueOperations(arangodb::MMFilesWalLogfile* logfile
}
// wait outside the mutex for the flag to be cleared
usleep(10000);
std::this_thread::sleep_for(std::chrono::microseconds(10000));
}
if (maxNumPendingOperations > 0 &&

View File

@ -970,7 +970,7 @@ void MMFilesCompactorThread::run() {
if (numCompacted > 0) {
// no need to sleep long or go into wait state if we worked.
// maybe there's still work left
usleep(1000);
std::this_thread::sleep_for(std::chrono::microseconds(1000));
} else if (state != TRI_vocbase_t::State::SHUTDOWN_COMPACTOR && _vocbase->state() == TRI_vocbase_t::State::NORMAL) {
// only sleep while server is still running
CONDITION_LOCKER(locker, _condition);

View File

@ -176,14 +176,14 @@ Result MMFilesEngine::dropDatabase(TRI_vocbase_t* database) {
// queued operations, a service which it offers:
auto callback = [&database]() {
database->shutdown();
usleep(10000);
std::this_thread::sleep_for(std::chrono::microseconds(10000));
};
while (
!MMFilesLogfileManager::instance()->executeWhileNothingQueued(callback)) {
LOG_TOPIC(TRACE, Logger::FIXME)
<< "Trying to shutdown dropped database, waiting for phase in which "
"the collector thread does not have queued operations.";
usleep(500000);
std::this_thread::sleep_for(std::chrono::microseconds(500000));
}
// stop compactor thread
shutdownDatabase(database);
@ -805,7 +805,7 @@ void MMFilesEngine::waitUntilDeletion(TRI_voc_tick_t id, bool force,
}
++iterations;
usleep(50000);
std::this_thread::sleep_for(std::chrono::microseconds(50000));
}
status = TRI_ERROR_NO_ERROR;
@ -2675,7 +2675,7 @@ int MMFilesEngine::stopCleanup(TRI_vocbase_t* vocbase) {
thread->signal();
while (thread->isRunning()) {
usleep(5000);
std::this_thread::sleep_for(std::chrono::microseconds(5000));
}
return TRI_ERROR_NO_ERROR;
@ -2757,7 +2757,7 @@ int MMFilesEngine::stopCompactor(TRI_vocbase_t* vocbase) {
thread->signal();
while (thread->isRunning()) {
usleep(5000);
std::this_thread::sleep_for(std::chrono::microseconds(5000));
}
return TRI_ERROR_NO_ERROR;

View File

@ -493,7 +493,7 @@ void MMFilesLogfileManager::unprepare() {
if (_allocatorThread != nullptr) {
LOG_TOPIC(TRACE, arangodb::Logger::FIXME) << "stopping allocator thread";
while (_allocatorThread->isRunning()) {
usleep(10000);
std::this_thread::sleep_for(std::chrono::microseconds(10000));
}
delete _allocatorThread;
_allocatorThread = nullptr;
@ -514,7 +514,7 @@ void MMFilesLogfileManager::unprepare() {
if (_removerThread != nullptr) {
LOG_TOPIC(TRACE, arangodb::Logger::FIXME) << "stopping remover thread";
while (_removerThread->isRunning()) {
usleep(10000);
std::this_thread::sleep_for(std::chrono::microseconds(10000));
}
delete _removerThread;
_removerThread = nullptr;
@ -528,7 +528,7 @@ void MMFilesLogfileManager::unprepare() {
_collectorThread->forceStop();
while (_collectorThread->isRunning()) {
locker.unlock();
usleep(10000);
std::this_thread::sleep_for(std::chrono::microseconds(10000));
locker.lock();
}
delete _collectorThread;
@ -539,7 +539,7 @@ void MMFilesLogfileManager::unprepare() {
if (_synchronizerThread != nullptr) {
LOG_TOPIC(TRACE, arangodb::Logger::FIXME) << "stopping synchronizer thread";
while (_synchronizerThread->isRunning()) {
usleep(10000);
std::this_thread::sleep_for(std::chrono::microseconds(10000));
}
delete _synchronizerThread;
_synchronizerThread = nullptr;
@ -819,7 +819,7 @@ int MMFilesLogfileManager::waitForCollectorQueue(TRI_voc_cid_t cid, double timeo
// sleep without holding the lock
locker.unlock();
usleep(10000);
std::this_thread::sleep_for(std::chrono::microseconds(10000));
if (TRI_microtime() > end) {
return TRI_ERROR_LOCKED;
@ -932,7 +932,7 @@ bool MMFilesLogfileManager::waitForSync(double maxWait) {
}
// not everything was committed yet. wait a bit
usleep(10000);
std::this_thread::sleep_for(std::chrono::microseconds(10000));
if (TRI_microtime() >= end) {
// time's up!
@ -1593,7 +1593,7 @@ MMFilesLogfileManagerState MMFilesLogfileManager::state() {
if (application_features::ApplicationServer::isStopping()) {
break;
}
usleep(10000);
std::this_thread::sleep_for(std::chrono::microseconds(10000));
}
TRI_ASSERT(state.lastCommittedTick > 0);
@ -1691,7 +1691,7 @@ void MMFilesLogfileManager::waitForCollector() {
locker.unlock();
LOG_TOPIC(TRACE, arangodb::Logger::FIXME) << "waiting for WAL collector";
usleep(50000);
std::this_thread::sleep_for(std::chrono::microseconds(50000));
}
}
@ -1752,7 +1752,7 @@ int MMFilesLogfileManager::waitForCollector(MMFilesWalLogfile::IdType logfileId,
break;
}
usleep(20000);
std::this_thread::sleep_for(std::chrono::microseconds(20000));
// try again
}
@ -2041,7 +2041,7 @@ void MMFilesLogfileManager::stopMMFilesCollectorThread() {
}
}
usleep(50000);
std::this_thread::sleep_for(std::chrono::microseconds(50000));
}
_collectorThread->beginShutdown();

View File

@ -95,7 +95,7 @@ Result MMFilesTransactionState::beginTransaction(transaction::Hints hints) {
return TRI_ERROR_ARANGO_WRITE_THROTTLE_TIMEOUT;
}
usleep(WaitTime);
std::this_thread::sleep_for(std::chrono::microseconds(WaitTime));
}
}

View File

@ -224,7 +224,7 @@ MMFilesWalSlotInfo MMFilesWalSlots::nextUnused(TRI_voc_tick_t databaseId, TRI_vo
return MMFilesWalSlotInfo(res);
}
usleep(10 * 1000);
std::this_thread::sleep_for(std::chrono::microseconds(10 * 1000));
// try again in next iteration
} else {
TRI_ASSERT(_logfile != nullptr);
@ -578,7 +578,7 @@ int MMFilesWalSlots::closeLogfile(MMFilesWalSlot::TickType& lastCommittedTick, b
return res;
}
usleep(10 * 1000);
std::this_thread::sleep_for(std::chrono::microseconds(10 * 1000));
// try again in next iteration
} else {
TRI_ASSERT(_logfile != nullptr);

View File

@ -79,7 +79,7 @@ GraphStore<V, E>::GraphStore(TRI_vocbase_t* vb, GraphFormat<V, E>* graphFormat)
template <typename V, typename E>
GraphStore<V, E>::~GraphStore() {
_destroyed = true;
usleep(25 * 1000);
std::this_thread::sleep_for(std::chrono::microseconds(25 * 1000));
delete _vertexData;
delete _edges;
}
@ -210,7 +210,7 @@ void GraphStore<V, E>::loadShards(WorkerConfig* config,
}
while (_runningThreads > 0) {
usleep(5000);
std::this_thread::sleep_for(std::chrono::microseconds(5000));
}
}
scheduler->post(callback);

View File

@ -140,7 +140,7 @@ void ArrayInCache<M>::mergeCache(WorkerConfig const& config,
TRY_MUTEX_LOCKER(guard, this->_bucketLocker[shardId]);
if (guard.isLocked() == false) {
if (i == 0) { // eventually we hit the last one
usleep(100); // don't busy wait
std::this_thread::sleep_for(std::chrono::microseconds(100)); // don't busy wait
}
continue;
}
@ -255,7 +255,7 @@ void CombiningInCache<M>::mergeCache(WorkerConfig const& config,
TRY_MUTEX_LOCKER(guard, this->_bucketLocker[shardId]);
if (guard.isLocked() == false) {
if (i == 0) { // eventually we hit the last one
usleep(100); // don't busy wait
std::this_thread::sleep_for(std::chrono::microseconds(100)); // don't busy wait
}
continue;
}

View File

@ -160,7 +160,7 @@ void PregelFeature::cleanupAll() {
for (auto it : _workers) {
it.second->cancelGlobalStep(VPackSlice());
}
usleep(1000 * 100); // 100ms to send out cancel calls
std::this_thread::sleep_for(std::chrono::microseconds(1000 * 100)); // 100ms to send out cancel calls
_workers.clear();
}

View File

@ -186,7 +186,7 @@ void RecoveryManager::_renewPrimaryServer(ShardID const& shard) {
break;
}
}
usleep(100000); // 100ms
std::this_thread::sleep_for(std::chrono::microseconds(100000)); // 100ms
tries++;
} while (tries < 3);
}

View File

@ -118,7 +118,7 @@ template <typename V, typename E, typename M>
Worker<V, E, M>::~Worker() {
LOG_TOPIC(DEBUG, Logger::PREGEL) << "Called ~Worker()";
_state = WorkerState::DONE;
usleep(50000); // 50ms wait for threads to die
std::this_thread::sleep_for(std::chrono::microseconds(50000)); // 50ms wait for threads to die
delete _readCache;
delete _writeCache;
delete _writeCacheNextGSS;

View File

@ -176,7 +176,7 @@ void ReplicationApplier::start(TRI_voc_tick_t initialTick, bool useTick, TRI_voc
while (_state.isShuttingDown()) {
// another instance is still around
writeLocker.unlock();
usleep(50 * 1000);
std::this_thread::sleep_for(std::chrono::microseconds(50 * 1000));
writeLocker.lock();
}
@ -209,7 +209,7 @@ void ReplicationApplier::start(TRI_voc_tick_t initialTick, bool useTick, TRI_voc
}
while (!_thread->hasStarted()) {
usleep(20000);
std::this_thread::sleep_for(std::chrono::microseconds(20000));
}
TRI_ASSERT(!_state.isRunning() && !_state.isShuttingDown());
@ -257,7 +257,7 @@ bool ReplicationApplier::sleepIfStillActive(uint64_t sleepTime) {
if (sleepChunk > sleepTime) {
sleepChunk = sleepTime;
}
usleep(static_cast<TRI_usleep_t>(sleepChunk));
std::this_thread::sleep_for(std::chrono::microseconds(sleepChunk));
sleepTime -= sleepChunk;
}
@ -490,7 +490,7 @@ void ReplicationApplier::doStop(Result const& r, bool joinThread) {
if (joinThread) {
while (_state.isShuttingDown()) {
writeLocker.unlock();
usleep(50 * 1000);
std::this_thread::sleep_for(std::chrono::microseconds(50 * 1000));
writeLocker.lock();
}

View File

@ -397,7 +397,7 @@ Result Syncer::applyCollectionDumpMarker(
return res;
}
usleep(50000);
std::this_thread::sleep_for(std::chrono::microseconds(50000));
// retry
}
} else {

View File

@ -78,7 +78,7 @@ class Syncer {
/// @brief sleeps (nanoseconds)
void sleep(uint64_t time) {
usleep(static_cast<TRI_usleep_t>(time));
std::this_thread::sleep_for(std::chrono::microseconds(time));
}
/// @brief request location rewriter (injects database name)

View File

@ -21,13 +21,15 @@
////////////////////////////////////////////////////////////////////////////////
#include "RestDemoHandler.h"
#include "Rest/HttpRequest.h"
#include "Rest/Version.h"
#include <thread>
#include <chrono>
#include <velocypack/Builder.h>
#include <velocypack/velocypack-aliases.h>
#include "Rest/HttpRequest.h"
#include "Rest/Version.h"
using namespace arangodb;
using namespace arangodb::basics;
using namespace arangodb::rest;
@ -39,7 +41,7 @@ RestDemoHandler::RestDemoHandler(GeneralRequest* request,
RestStatus RestDemoHandler::execute() {
return RestStatus::QUEUE
.then([]() { LOG_TOPIC(INFO, arangodb::Logger::FIXME) << "demo handler going to sleep"; })
.then([]() { sleep(5); })
.then([]() { std::this_thread::sleep_for(std::chrono::seconds(5)); })
.then([]() { LOG_TOPIC(INFO, arangodb::Logger::FIXME) << "demo handler done sleeping"; })
.then([this]() { doSomeMoreWork(); })
.then([this]() { return evenMoreWork(); });
@ -62,7 +64,7 @@ RestStatus RestDemoHandler::evenMoreWork() {
return RestStatus::DONE
.then([]() { LOG_TOPIC(INFO, arangodb::Logger::FIXME) << "demo handler keeps working"; })
.then([]() { sleep(5); })
.then([]() { std::this_thread::sleep_for(std::chrono::seconds(5)); })
.then(
[]() { LOG_TOPIC(INFO, arangodb::Logger::FIXME) << "even if the result has already been returned"; })
.then([]() { LOG_TOPIC(INFO, arangodb::Logger::FIXME) << "finally done"; });

View File

@ -108,7 +108,7 @@ void AqlFeature::stop() {
<< o << " registered traverser engines to terminate and for "
<< n << " registered queries to terminate and for "
<< m << " feature leases to be released";
usleep(500000);
std::this_thread::sleep_for(std::chrono::microseconds(500000));
}
MUTEX_LOCKER(locker, AqlFeature::_aqlFeatureMutex);
AqlFeature::_AQL = nullptr;

View File

@ -71,7 +71,7 @@ static void raceForClusterBootstrap() {
// Error in communication, note that value not found is not an error
LOG_TOPIC(TRACE, Logger::STARTUP)
<< "raceForClusterBootstrap: no agency communication";
sleep(1);
std::this_thread::sleep_for(std::chrono::seconds(1));
continue;
}
@ -90,7 +90,7 @@ static void raceForClusterBootstrap() {
}
LOG_TOPIC(DEBUG, Logger::STARTUP)
<< "raceForClusterBootstrap: somebody else does the bootstrap";
sleep(1);
std::this_thread::sleep_for(std::chrono::seconds(1));
continue;
}
@ -102,7 +102,7 @@ static void raceForClusterBootstrap() {
LOG_TOPIC(DEBUG, Logger::STARTUP)
<< "raceForClusterBootstrap: lost race, somebody else will bootstrap";
// Cannot get foot into the door, try again later:
sleep(1);
std::this_thread::sleep_for(std::chrono::seconds(1));
continue;
}
// OK, we handle things now
@ -115,7 +115,7 @@ static void raceForClusterBootstrap() {
LOG_TOPIC(TRACE, Logger::STARTUP)
<< "raceForClusterBootstrap: no DBservers, waiting";
agency.removeValues(boostrapKey, false);
sleep(1);
std::this_thread::sleep_for(std::chrono::seconds(1));
continue;
}
@ -135,7 +135,7 @@ static void raceForClusterBootstrap() {
LOG_TOPIC(ERR, Logger::STARTUP) << "Empty returned value.";
}
agency.removeValues(boostrapKey, false);
sleep(1);
std::this_thread::sleep_for(std::chrono::seconds(1));
continue;
}
@ -154,7 +154,7 @@ static void raceForClusterBootstrap() {
LOG_TOPIC(TRACE, Logger::STARTUP)
<< "raceForClusterBootstrap: could not indicate success";
sleep(1);
std::this_thread::sleep_for(std::chrono::seconds(1));
}
}
@ -200,7 +200,7 @@ void BootstrapFeature::start() {
<< "result of bootstrap was not an array: " << slice.typeName() << ". retrying bootstrap in 1s.";
}
if (!success) {
sleep(1);
std::this_thread::sleep_for(std::chrono::seconds(1));
}
}
} else if (ServerState::isDBServer(role)) {

View File

@ -104,7 +104,7 @@ void CheckVersionFeature::start() {
// and force shutdown
server()->beginShutdown();
usleep(1 * 1000 * 1000);
std::this_thread::sleep_for(std::chrono::microseconds(1 * 1000 * 1000));
TRI_EXIT_FUNCTION(EXIT_SUCCESS, nullptr);
}

View File

@ -74,7 +74,7 @@ void ConsoleFeature::unprepare() {
int iterations = 0;
while (_consoleThread->isRunning() && ++iterations < 30) {
usleep(100 * 1000); // spin while console is still needed
std::this_thread::sleep_for(std::chrono::microseconds(100 * 1000)); // spin while console is still needed
}
std::cout << std::endl << TRI_BYE_MESSAGE << std::endl;

View File

@ -58,7 +58,7 @@ ConsoleThread::~ConsoleThread() { shutdown(); }
static char const* USER_ABORTED = "user aborted";
void ConsoleThread::run() {
usleep(100 * 1000);
std::this_thread::sleep_for(std::chrono::microseconds(100 * 1000));
// enter V8 context
_context = V8DealerFeature::DEALER->enterContext(_vocbase, true);

View File

@ -180,7 +180,7 @@ void DatabaseManagerThread::run() {
break;
}
usleep(waitTime());
std::this_thread::sleep_for(std::chrono::microseconds(waitTime()));
// The following is only necessary after a wait:
auto queryRegistry = QueryRegistryFeature::QUERY_REGISTRY;
@ -398,7 +398,7 @@ void DatabaseFeature::unprepare() {
_databaseManager->beginShutdown();
while (_databaseManager->isRunning()) {
usleep(5000);
std::this_thread::sleep_for(std::chrono::microseconds(5000));
}
}

View File

@ -208,7 +208,7 @@ void ServerFeature::waitForHeartbeat() {
if (HeartbeatThread::hasRunOnce()) {
break;
}
usleep(100 * 1000);
std::this_thread::sleep_for(std::chrono::microseconds(100 * 1000));
}
}

View File

@ -1745,7 +1745,7 @@ int RocksDBCollection::lockWrite(double timeout) {
if (now - startTime < 0.001) {
std::this_thread::yield();
} else {
usleep(static_cast<TRI_usleep_t>(waitTime));
std::this_thread::sleep_for(std::chrono::microseconds(waitTime));
if (waitTime < 32) {
waitTime *= 2;
}
@ -1796,7 +1796,7 @@ int RocksDBCollection::lockRead(double timeout) {
if (now - startTime < 0.001) {
std::this_thread::yield();
} else {
usleep(static_cast<TRI_usleep_t>(waitTime));
std::this_thread::sleep_for(std::chrono::microseconds(waitTime));
if (waitTime < 32) {
waitTime *= 2;
}

View File

@ -196,7 +196,7 @@ Result RocksDBCounterManager::sync(bool force) {
if (res) {
break;
}
usleep(10000);
std::this_thread::sleep_for(std::chrono::microseconds(10000));
}
} else {
bool expected = false;

View File

@ -797,7 +797,7 @@ void RocksDBEdgeIndex::warmupInternal(transaction::Methods* trx,
while (cc->isBusy()) {
// We should wait here, the cache will reject
// any inserts anyways.
usleep(10000);
std::this_thread::sleep_for(std::chrono::microseconds(10000));
}
auto entry = cache::CachedValue::construct(

View File

@ -595,7 +595,7 @@ void RocksDBEngine::stop() {
// wait until background thread stops
while (_backgroundThread->isRunning()) {
usleep(10000);
std::this_thread::sleep_for(std::chrono::microseconds(10000));
}
_backgroundThread.reset();
}

View File

@ -74,7 +74,7 @@ RocksDBReplicationManager::~RocksDBReplicationManager() {
<< "giving up waiting for unused contexts";
}
usleep(500000);
std::this_thread::sleep_for(std::chrono::microseconds(500000));
++tries;
}

View File

@ -445,10 +445,10 @@ void Scheduler::rebalanceThreads() {
}
// add an extra sleep so the system has a chance to recover and provide
// the needed resources
usleep(20000);
std::this_thread::sleep_for(std::chrono::microseconds(20000));
}
usleep(5000);
std::this_thread::sleep_for(std::chrono::microseconds(5000));
}
}
@ -484,7 +484,7 @@ void Scheduler::shutdown() {
// we can be quite generous here with waiting...
// as we are in the shutdown already, we do not care if we need to wait for a
// bit longer
usleep(20000);
std::this_thread::sleep_for(std::chrono::microseconds(20000));
}
// remove all queued work descriptions in the work monitor first

View File

@ -40,6 +40,9 @@
#include "V8Server/V8DealerFeature.h"
#include "V8Server/v8-dispatcher.h"
#include <thread>
#include <chrono>
using namespace arangodb;
using namespace arangodb::application_features;
using namespace arangodb::basics;
@ -176,7 +179,7 @@ void SchedulerFeature::stop() {
for (size_t count = 0; count < MAX_TRIES && _scheduler->isRunning();
++count) {
LOG_TOPIC(TRACE, Logger::STARTUP) << "waiting for scheduler to stop";
usleep(100000);
std::this_thread::sleep_for(std::chrono::microseconds(100000));
}
// shutdown user jobs again, in case new ones appear

View File

@ -29,6 +29,9 @@
#include <boost/asio/serial_port_service.hpp>
#include <boost/asio/ssl.hpp>
#include <thread>
#include <chrono>
#include "Basics/StringBuffer.h"
#include "Basics/asio-helper.h"
#include "Logger/Logger.h"
@ -82,7 +85,7 @@ bool doSslHandshake(T& socket) {
LOG_TOPIC(DEBUG, Logger::COMMUNICATION) << "forcefully shutting down connection after wait time";
break;
} else {
usleep(10000);
std::this_thread::sleep_for(std::chrono::microseconds(10000));
}
}

View File

@ -164,7 +164,7 @@ void RequestStatistics::process(RequestStatistics* statistics) {
if (_freeList.push(statistics)) {
break;
}
usleep(10000);
std::this_thread::sleep_for(std::chrono::microseconds(10000));
}
if (tries > 1) {

View File

@ -22,7 +22,6 @@
#include "StatisticsFeature.h"
#include "Logger/Logger.h"
#include "ProgramOptions/ProgramOptions.h"
#include "ProgramOptions/Section.h"
@ -30,6 +29,9 @@
#include "Statistics/RequestStatistics.h"
#include "Statistics/ServerStatistics.h"
#include <thread>
#include <chrono>
using namespace arangodb;
using namespace arangodb::application_features;
using namespace arangodb::basics;
@ -89,14 +91,14 @@ class arangodb::StatisticsThread final : public Thread {
}
}
usleep(static_cast<TRI_usleep_t>(sleepTime));
std::this_thread::sleep_for(std::chrono::microseconds(sleepTime));
} else {
nothingHappened = 0;
if (count < 10) {
usleep(10 * 1000);
std::this_thread::sleep_for(std::chrono::microseconds(10 * 1000));
} else if (count < 100) {
usleep(1 * 1000);
std::this_thread::sleep_for(std::chrono::microseconds(1 * 1000));
}
}
}
@ -196,7 +198,7 @@ void StatisticsFeature::unprepare() {
_statisticsThread->beginShutdown();
while (_statisticsThread->isRunning()) {
usleep(10000);
std::this_thread::sleep_for(std::chrono::microseconds(10000));
}
}

View File

@ -62,7 +62,7 @@ CollectionKeysRepository::~CollectionKeysRepository() {
LOG_TOPIC(WARN, arangodb::Logger::FIXME) << "giving up waiting for unused keys";
}
usleep(500000);
std::this_thread::sleep_for(std::chrono::microseconds(500000));
++tries;
}

View File

@ -67,7 +67,7 @@ CursorRepository::~CursorRepository() {
LOG_TOPIC(WARN, arangodb::Logger::FIXME) << "giving up waiting for unused cursors";
}
usleep(500000);
std::this_thread::sleep_for(std::chrono::microseconds(500000));
++tries;
}

View File

@ -708,7 +708,7 @@ V8Context* V8DealerFeature::enterContext(TRI_vocbase_t* vocbase,
}
LOG_TOPIC(DEBUG, arangodb::Logger::V8) << "waiting for V8 context #" << id << " to become available";
usleep(50 * 1000);
std::this_thread::sleep_for(std::chrono::microseconds(50 * 1000));
}
if (context == nullptr) {
@ -1088,7 +1088,7 @@ void V8DealerFeature::shutdownContexts() {
// wait until garbage collector thread is done
while (!_gcFinished) {
usleep(10000);
std::this_thread::sleep_for(std::chrono::microseconds(10000));
}
LOG_TOPIC(DEBUG, arangodb::Logger::V8) << "commanding GC Thread to terminate";

View File

@ -1248,7 +1248,7 @@ static void JS_QuerySleepAql(v8::FunctionCallbackInfo<v8::Value> const& args) {
double const until = TRI_microtime() + n;
while (TRI_microtime() < until) {
usleep(10000);
std::this_thread::sleep_for(std::chrono::microseconds(10000));
if (query != nullptr) {
if (query->killed()) {

View File

@ -248,7 +248,7 @@ arangodb::Result Databases::create(std::string const& dbName,
break;
}
// sleep
usleep(10000);
std::this_thread::sleep_for(std::chrono::microseconds(10000));
}
if (vocbase == nullptr) {
@ -434,7 +434,7 @@ arangodb::Result Databases::drop(TRI_vocbase_t* systemVocbase,
vocbase->release();
// sleep
usleep(10000);
std::this_thread::sleep_for(std::chrono::microseconds(10000));
}
} else {

View File

@ -489,7 +489,7 @@ int TRI_vocbase_t::loadCollection(arangodb::LogicalCollection* collection,
return TRI_ERROR_ARANGO_COLLECTION_NOT_LOADED;
}
usleep(collectionStatusPollInterval());
std::this_thread::sleep_for(std::chrono::microseconds(collectionStatusPollInterval()));
}
return loadCollection(collection, status, false);
@ -598,7 +598,7 @@ int TRI_vocbase_t::dropCollectionWorker(arangodb::LogicalCollection* collection,
// sleep for a while
std::this_thread::yield();
usleep(10000);
std::this_thread::sleep_for(std::chrono::microseconds(10000));
}
TRI_ASSERT(writeLocker.isLocked());
@ -1073,7 +1073,7 @@ int TRI_vocbase_t::unloadCollection(arangodb::LogicalCollection* collection,
break;
}
// sleep without lock
usleep(collectionStatusPollInterval());
std::this_thread::sleep_for(std::chrono::microseconds(collectionStatusPollInterval()));
}
// if we get here, the status has changed
return unloadCollection(collection, force);
@ -1138,7 +1138,7 @@ int TRI_vocbase_t::dropCollection(arangodb::LogicalCollection* collection,
// try again in next iteration
TRI_ASSERT(state == DROP_AGAIN);
usleep(collectionStatusPollInterval());
std::this_thread::sleep_for(std::chrono::microseconds(collectionStatusPollInterval()));
}
}
@ -1207,7 +1207,7 @@ int TRI_vocbase_t::renameCollection(arangodb::LogicalCollection* collection,
// sleep for a while
std::this_thread::yield();
usleep(10000);
std::this_thread::sleep_for(std::chrono::microseconds(10000));
}
TRI_ASSERT(writeLocker.isLocked());
@ -1465,7 +1465,7 @@ int TRI_vocbase_t::dropView(std::shared_ptr<arangodb::LogicalView> view) {
// sleep for a while
std::this_thread::yield();
usleep(10000);
std::this_thread::sleep_for(std::chrono::microseconds(10000));
}
TRI_ASSERT(writeLocker.isLocked());

View File

@ -234,12 +234,12 @@ void BenchFeature::start() {
// give all threads a chance to start so they will not miss the broadcast
while (getStartCounter() < (int)_concurreny) {
usleep(5000);
std::this_thread::sleep_for(std::chrono::microseconds(5000));
}
if (_delay) {
status("sleeping (startup delay)...");
sleep(10);
std::this_thread::sleep_for(std::chrono::seconds(10));
}
status("executing tests...");
@ -270,7 +270,7 @@ void BenchFeature::start() {
nextReportValue += stepValue;
}
usleep(10000);
std::this_thread::sleep_for(std::chrono::microseconds(10000));
}
double time = TRI_microtime() - start;

View File

@ -886,7 +886,7 @@ void ImportHelper::waitForSenders() {
if (numIdle == _senderThreads.size()) {
return;
}
usleep(10000);
std::this_thread::sleep_for(std::chrono::microseconds(10000));
}
}
}

View File

@ -33,6 +33,8 @@
#include "Ssl/ssl-helper.h"
#include <iostream>
#include <thread>
#include <chrono>
using namespace arangodb;
using namespace arangodb::application_features;
@ -150,7 +152,7 @@ void ClientFeature::prepare() {
if (_authentication &&
isEnabled() &&
_haveServerPassword) {
usleep(10 * 1000);
std::this_thread::sleep_for(std::chrono::microseconds(10 * 1000));
try {
ConsoleFeature* console =

View File

@ -24,6 +24,8 @@
#include <fstream>
#include <iostream>
#include <thread>
#include <chrono>
#include "Basics/FileUtils.h"
#include "Logger/LogAppender.h"
@ -370,7 +372,7 @@ int DaemonFeature::waitForChildProcess(int pid) {
}
// sleep a while and retry
usleep(500 * 1000);
std::this_thread::sleep_for(std::chrono::microseconds(500 * 1000));
}
// enough time has elapsed... we now abort our loop

View File

@ -25,6 +25,8 @@
#define ARANGODB_BASICS_DATA_PROTECTOR_H 1
#include "Basics/Common.h"
#include <thread>
#include <chrono>
namespace arangodb {
namespace basics {
@ -140,7 +142,7 @@ class DataProtector {
for (int i = 0; i < DATA_PROTECTOR_MULTIPLICITY; i++) {
while (reinterpret_cast<Entry*>(_list + i)->_count > 0) {
// let other threads do some work while we're waiting
usleep(250);
std::this_thread::sleep_for(std::chrono::microseconds(250));
}
}
}

View File

@ -18,115 +18,86 @@
///
/// Copyright holder is ArangoDB GmbH, Cologne, Germany
///
/// @author Frank Celler
/// @author Achim Brandt
/// @author Max Neunhoeffer
////////////////////////////////////////////////////////////////////////////////
#include "ReadWriteLock.h"
#if 0
using namespace arangodb::basics;
////////////////////////////////////////////////////////////////////////////////
/// @brief constructs a read-write lock
////////////////////////////////////////////////////////////////////////////////
ReadWriteLock::ReadWriteLock() : _rwlock(), _writeLocked(false) {
TRI_InitReadWriteLock(&_rwlock);
}
////////////////////////////////////////////////////////////////////////////////
/// @brief deletes read-write lock
////////////////////////////////////////////////////////////////////////////////
ReadWriteLock::~ReadWriteLock() { TRI_DestroyReadWriteLock(&_rwlock); }
////////////////////////////////////////////////////////////////////////////////
/// @brief locks for reading
////////////////////////////////////////////////////////////////////////////////
void ReadWriteLock::readLock() { TRI_ReadLockReadWriteLock(&_rwlock); }
////////////////////////////////////////////////////////////////////////////////
/// @brief tries to lock for reading
////////////////////////////////////////////////////////////////////////////////
bool ReadWriteLock::tryReadLock() {
return TRI_TryReadLockReadWriteLock(&_rwlock);
}
////////////////////////////////////////////////////////////////////////////////
/// @brief tries to lock for reading, sleeping if the lock cannot be
/// acquired instantly, sleepTime is in microseconds
////////////////////////////////////////////////////////////////////////////////
bool ReadWriteLock::tryReadLock(uint64_t sleepTime) {
while (true) {
if (tryReadLock()) {
return true;
}
usleep(static_cast<TRI_usleep_t>(sleepTime));
}
}
////////////////////////////////////////////////////////////////////////////////
/// @brief locks for writing
////////////////////////////////////////////////////////////////////////////////
void ReadWriteLock::writeLock() {
TRI_WriteLockReadWriteLock(&_rwlock);
_writeLocked = true;
std::unique_lock<std::mutex> guard(_mut);
if (_state == 0) {
_state = -1;
return;
}
do {
_wantWrite = true;
_bell.wait(guard);
} while (_state != 0);
_state = -1;
_wantWrite = false;
}
////////////////////////////////////////////////////////////////////////////////
/// @brief tries to lock for writing
////////////////////////////////////////////////////////////////////////////////
/// @brief locks for writing, but only tries
bool ReadWriteLock::tryWriteLock() {
if (!TRI_TryWriteLockReadWriteLock(&_rwlock)) {
return false;
std::unique_lock<std::mutex> guard(_mut);
if (_state == 0) {
_state = -1;
return true;
}
_writeLocked = true;
return true;
return false;
}
////////////////////////////////////////////////////////////////////////////////
/// @brief tries to lock for writing, sleeping if the lock cannot be
/// acquired instantly, sleepTime is in microseconds
////////////////////////////////////////////////////////////////////////////////
bool ReadWriteLock::tryWriteLock(uint64_t sleepTime) {
/// @brief locks for reading
void ReadWriteLock::readLock() {
std::unique_lock<std::mutex> guard(_mut);
if (!_wantWrite && _state >= 0) {
_state += 1;
return;
}
while (true) {
if (tryWriteLock()) {
return true;
while (_wantWrite || _state < 0) {
_bell.wait(guard);
}
if (!_wantWrite) {
break;
}
usleep(static_cast<TRI_usleep_t>(sleepTime));
}
_state += 1;
}
/// @brief locks for reading, tries only
bool ReadWriteLock::tryReadLock() {
std::unique_lock<std::mutex> guard(_mut);
if (!_wantWrite && _state >= 0) {
_state += 1;
return true;
}
return false;
}
////////////////////////////////////////////////////////////////////////////////
/// @brief releases the read-lock or write-lock
////////////////////////////////////////////////////////////////////////////////
void ReadWriteLock::unlock() {
if (_writeLocked) {
_writeLocked = false;
unlockWrite();
std::unique_lock<std::mutex> guard(_mut);
if (_state == -1) {
_state = 0;
_bell.notify_all();
} else {
unlockRead();
_state -= 1;
if (_state == 0) {
_bell.notify_all();
}
}
}
/// @brief releases the read-lock
void ReadWriteLock::unlockRead() {
TRI_ReadUnlockReadWriteLock(&_rwlock);
unlock();
}
/// @brief releases the write-lock
void ReadWriteLock::unlockWrite() {
TRI_WriteUnlockReadWriteLock(&_rwlock);
unlock();
}
#endif

View File

@ -18,61 +18,53 @@
///
/// Copyright holder is ArangoDB GmbH, Cologne, Germany
///
/// @author Frank Celler
/// @author Achim Brandt
/// @author Max Neunhoeffer
////////////////////////////////////////////////////////////////////////////////
#ifndef ARANGODB_BASICS_READ_WRITE_LOCK_H
#define ARANGODB_BASICS_READ_WRITE_LOCK_H 1
#include "Basics/Common.h"
#include "Basics/locks.h"
#include "Basics/ReadWriteLockCPP11.h"
#include <mutex>
#include <condition_variable>
#include <thread>
namespace arangodb {
namespace basics {
typedef ReadWriteLockCPP11 ReadWriteLock;
#if 0
/// @brief read-write lock
/// @brief read-write lock, slow but just using CPP11
/// This class has two other advantages:
/// (1) it is possible that a thread tries to acquire a lock even if it
/// has it already. This is important when we are running a thread
/// pool that works on task groups and a task group needs to acquire
/// a lock across multiple (non-concurrent) tasks. This must work,
/// even if tasks from different groups that fight for a lock are
/// actually executed by the same thread! POSIX RW-locks do not have
/// this property.
/// (2) write locks have a preference over read locks: as long as a task
/// wants to get a write lock, no other task can get a (new) read lock.
/// This is necessary to avoid starvation of writers by many readers.
/// The current implementation can starve readers, though.
class ReadWriteLock {
ReadWriteLock(ReadWriteLock const&) = delete;
ReadWriteLock& operator=(ReadWriteLock const&) = delete;
ReadWriteLock(ReadWriteLock&&) = delete;
ReadWriteLock& operator=(ReadWriteLock&&) = delete;
public:
/// @brief constructs a read-write lock
ReadWriteLock();
/// @brief deletes read-write lock
~ReadWriteLock();
public:
/// @brief locks for reading
void readLock();
/// @brief tries to lock for reading
bool tryReadLock();
/// @brief tries to lock for reading, sleeping if the lock cannot be
/// acquired instantly, sleepTime is in microseconds
bool tryReadLock(uint64_t sleepTime);
ReadWriteLock() : _state(0), _wantWrite(false) {}
/// @brief locks for writing
void writeLock();
/// @brief tries to lock for writing
/// @brief locks for writing, but only tries
bool tryWriteLock();
/// @brief tries to lock for writing, sleeping if the lock cannot be
/// acquired instantly, sleepTime is in microseconds
bool tryWriteLock(uint64_t sleepTime);
/// @brief locks for reading
void readLock();
/// @brief locks for reading, tries only
bool tryReadLock();
/// @brief releases the read-lock or write-lock
void unlock();
/// @brief releases the read-lock
void unlockRead();
@ -80,15 +72,19 @@ class ReadWriteLock {
void unlockWrite();
private:
/// @brief read-write lock variable
TRI_read_write_lock_t _rwlock;
/// @brief a mutex
std::mutex _mut;
/// @brief write lock marker
bool _writeLocked;
/// @brief a condition variable to wake up threads
std::condition_variable _bell;
/// @brief _state, 0 means unlocked, -1 means write locked, positive means
/// a number of read locks
int _state;
/// @brief _wantWrite, is set if somebody is waiting for the write lock
bool _wantWrite;
};
#endif
}
}

View File

@ -1,103 +0,0 @@
////////////////////////////////////////////////////////////////////////////////
/// DISCLAIMER
///
/// Copyright 2014-2016 ArangoDB GmbH, Cologne, Germany
/// Copyright 2004-2014 triAGENS GmbH, Cologne, Germany
///
/// Licensed under the Apache License, Version 2.0 (the "License");
/// you may not use this file except in compliance with the License.
/// You may obtain a copy of the License at
///
/// http://www.apache.org/licenses/LICENSE-2.0
///
/// Unless required by applicable law or agreed to in writing, software
/// distributed under the License is distributed on an "AS IS" BASIS,
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
/// See the License for the specific language governing permissions and
/// limitations under the License.
///
/// Copyright holder is ArangoDB GmbH, Cologne, Germany
///
/// @author Max Neunhoeffer
////////////////////////////////////////////////////////////////////////////////
#include "ReadWriteLockCPP11.h"
using namespace arangodb::basics;
/// @brief locks for writing
void ReadWriteLockCPP11::writeLock() {
std::unique_lock<std::mutex> guard(_mut);
if (_state == 0) {
_state = -1;
return;
}
do {
_wantWrite = true;
_bell.wait(guard);
} while (_state != 0);
_state = -1;
_wantWrite = false;
}
/// @brief locks for writing, but only tries
bool ReadWriteLockCPP11::tryWriteLock() {
std::unique_lock<std::mutex> guard(_mut);
if (_state == 0) {
_state = -1;
return true;
}
return false;
}
/// @brief locks for reading
void ReadWriteLockCPP11::readLock() {
std::unique_lock<std::mutex> guard(_mut);
if (!_wantWrite && _state >= 0) {
_state += 1;
return;
}
while (true) {
while (_wantWrite || _state < 0) {
_bell.wait(guard);
}
if (!_wantWrite) {
break;
}
}
_state += 1;
}
/// @brief locks for reading, tries only
bool ReadWriteLockCPP11::tryReadLock() {
std::unique_lock<std::mutex> guard(_mut);
if (!_wantWrite && _state >= 0) {
_state += 1;
return true;
}
return false;
}
/// @brief releases the read-lock or write-lock
void ReadWriteLockCPP11::unlock() {
std::unique_lock<std::mutex> guard(_mut);
if (_state == -1) {
_state = 0;
_bell.notify_all();
} else {
_state -= 1;
if (_state == 0) {
_bell.notify_all();
}
}
}
/// @brief releases the read-lock
void ReadWriteLockCPP11::unlockRead() {
unlock();
}
/// @brief releases the write-lock
void ReadWriteLockCPP11::unlockWrite() {
unlock();
}

View File

@ -1,91 +0,0 @@
////////////////////////////////////////////////////////////////////////////////
/// DISCLAIMER
///
/// Copyright 2014-2016 ArangoDB GmbH, Cologne, Germany
/// Copyright 2004-2014 triAGENS GmbH, Cologne, Germany
///
/// Licensed under the Apache License, Version 2.0 (the "License");
/// you may not use this file except in compliance with the License.
/// You may obtain a copy of the License at
///
/// http://www.apache.org/licenses/LICENSE-2.0
///
/// Unless required by applicable law or agreed to in writing, software
/// distributed under the License is distributed on an "AS IS" BASIS,
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
/// See the License for the specific language governing permissions and
/// limitations under the License.
///
/// Copyright holder is ArangoDB GmbH, Cologne, Germany
///
/// @author Max Neunhoeffer
////////////////////////////////////////////////////////////////////////////////
#ifndef ARANGODB_BASICS_READ_WRITE_LOCK_CPP11_H
#define ARANGODB_BASICS_READ_WRITE_LOCK_CPP11_H 1
#include "Basics/Common.h"
#include <mutex>
#include <condition_variable>
#include <thread>
namespace arangodb {
namespace basics {
/// @brief read-write lock, slow but just using CPP11
/// This class has two other advantages:
/// (1) it is possible that a thread tries to acquire a lock even if it
/// has it already. This is important when we are running a thread
/// pool that works on task groups and a task group needs to acquire
/// a lock across multiple (non-concurrent) tasks. This must work,
/// even if tasks from different groups that fight for a lock are
/// actually executed by the same thread! POSIX RW-locks do not have
/// this property.
/// (2) write locks have a preference over read locks: as long as a task
/// wants to get a write lock, no other task can get a (new) read lock.
/// This is necessary to avoid starvation of writers by many readers.
/// The current implementation can starve readers, though.
class ReadWriteLockCPP11 {
public:
ReadWriteLockCPP11() : _state(0), _wantWrite(false) {}
/// @brief locks for writing
void writeLock();
/// @brief locks for writing, but only tries
bool tryWriteLock();
/// @brief locks for reading
void readLock();
/// @brief locks for reading, tries only
bool tryReadLock();
/// @brief releases the read-lock or write-lock
void unlock();
/// @brief releases the read-lock
void unlockRead();
/// @brief releases the write-lock
void unlockWrite();
private:
/// @brief a mutex
std::mutex _mut;
/// @brief a condition variable to wake up threads
std::condition_variable _bell;
/// @brief _state, 0 means unlocked, -1 means write locked, positive means
/// a number of read locks
int _state;
/// @brief _wantWrite, is set if somebody is waiting for the write lock
bool _wantWrite;
};
}
}
#endif

View File

@ -36,6 +36,9 @@
#include <velocypack/Builder.h>
#include <velocypack/velocypack-aliases.h>
#include <thread>
#include <chrono>
using namespace arangodb;
using namespace arangodb::application_features;
using namespace arangodb::basics;
@ -282,7 +285,7 @@ void Thread::shutdown() {
break;
}
usleep(100 * 1000);
std::this_thread::sleep_for(std::chrono::microseconds(100 * 1000));
}
if (_state.load() != ThreadState::STOPPED) {

View File

@ -22,6 +22,8 @@
////////////////////////////////////////////////////////////////////////////////
#include "locks.h"
#include <thread>
#include <chrono>
#ifdef TRI_HAVE_POSIX_THREADS
@ -92,7 +94,7 @@ again:
LOG_TOPIC(WARN, arangodb::Logger::FIXME) << "too many read-locks on read-write lock";
complained = true;
}
usleep(BUSY_LOCK_DELAY);
std::this_thread::sleep_for(std::chrono::microseconds(BUSY_LOCK_DELAY));
#ifdef TRI_HAVE_SCHED_H
// let other threads do things
sched_yield();

View File

@ -180,7 +180,6 @@
#define TRI_WRITE ::write
#define TRI_FDOPEN(a, b) ::fdopen((a), (b))
#define TRI_usleep_t useconds_t
#define TRI_lseek_t off_t
#define TRI_read_t size_t
#define TRI_stat_t struct stat
@ -338,7 +337,6 @@
#define TRI_WRITE ::write
#define TRI_FDOPEN(a, b) ::fdopen((a), (b))
#define TRI_usleep_t useconds_t
#define TRI_lseek_t off_t
#define TRI_read_t size_t
#define TRI_stat_t struct stat
@ -483,7 +481,6 @@
#define TRI_WRITE ::write
#define TRI_FDOPEN(a, b) ::fdopen((a), (b))
#define TRI_usleep_t useconds_t
#define TRI_lseek_t off_t
#define TRI_read_t size_t
#define TRI_stat_t struct stat
@ -647,7 +644,6 @@
#define TRI_WRITE ::write
#define TRI_FDOPEN(a, b) ::fdopen((a), (b))
#define TRI_usleep_t useconds_t
#define TRI_lseek_t off_t
#define TRI_read_t size_t
#define TRI_stat_t struct stat
@ -752,7 +748,6 @@
#define putenv _putenv
#define sleep TRI_sleep
#define tzset _tzset
#define usleep TRI_usleep
// available features
@ -844,7 +839,6 @@ typedef unsigned char bool;
#define TRI_WRITE ::_write
#define TRI_FDOPEN(a, b) ::_fdopen((a), (b))
#define TRI_usleep_t unsigned long
#define TRI_lseek_t __int64
#define TRI_read_t unsigned int
#define TRI_stat_t struct _stat64

View File

@ -1389,7 +1389,7 @@ ExternalProcessStatus TRI_KillExternalProcess(ExternalId pid, int signal, bool i
}
return status;
}
sleep(1);
std::this_thread::sleep_for(std::chrono::seconds(1));
if (count >= 8) {
TRI_ASSERT(external != nullptr);
killProcess(external, SIGKILL);

View File

@ -69,61 +69,6 @@ int getpagesize(void) {
return pageSize;
}
////////////////////////////////////////////////////////////////////////////////
// Calls the windows Sleep function which always sleeps for milliseconds
////////////////////////////////////////////////////////////////////////////////
void TRI_sleep(unsigned long waitTime) { Sleep(waitTime * 1000); }
////////////////////////////////////////////////////////////////////////////////
// Calls a timer which waits for a signal after the elapsed time in
// microseconds. The timer is accurate to 100nanoseconds.
// This is only a Windows workaround, use usleep, which is mapped to
// TRI_usleep on Windows!
////////////////////////////////////////////////////////////////////////////////
void TRI_usleep(unsigned long waitTime) {
int result;
HANDLE hTimer = NULL; // stores the handle of the timer object
LARGE_INTEGER wTime; // essentially a 64bit number
wTime.QuadPart = waitTime * 10; // *10 to change to microseconds
wTime.QuadPart =
-wTime.QuadPart; // negative indicates relative time elapsed,
// Create an unnamed waitable timer.
hTimer = CreateWaitableTimer(NULL, 1, NULL);
if (hTimer == NULL) {
// not much we can do at this low level
return;
}
if (GetLastError() == ERROR_ALREADY_EXISTS) {
LOG_TOPIC(FATAL, arangodb::Logger::FIXME) << "internal error in TRI_usleep()";
FATAL_ERROR_EXIT();
}
// Set timer to wait for indicated micro seconds.
if (!SetWaitableTimer(hTimer, &wTime, 0, NULL, NULL, 0)) {
// not much we can do at this low level
CloseHandle(hTimer);
return;
}
// Wait for the timer
result = WaitForSingleObject(hTimer, INFINITE);
if (result != WAIT_OBJECT_0) {
CloseHandle(hTimer);
LOG_TOPIC(FATAL, arangodb::Logger::FIXME) << "couldn't wait for timer in TRI_usleep()";
FATAL_ERROR_EXIT();
}
CloseHandle(hTimer);
// todo: go through what the result is e.g. WAIT_OBJECT_0
return;
}
////////////////////////////////////////////////////////////////////////////////
// Sets up a handler when invalid (win) handles are passed to a windows
// function.

View File

@ -70,21 +70,6 @@ int TRI_createFile(char const* filename, int openFlags, int modeFlags);
int TRI_OPEN_WIN32(char const* filename, int openFlags);
// .............................................................................
// the sleep function in windows is for milliseconds, on linux it is for seconds
// this provides a translation
// .............................................................................
void TRI_sleep(unsigned long);
// .............................................................................
// there is no usleep (micro sleep) in windows, so we create one here
// This is only a Windows workaround, use usleep, which is mapped to
// TRI_usleep on Windows!
// .............................................................................
void TRI_usleep(unsigned long);
////////////////////////////////////////////////////////////////////////////////
/// @brief converts a Windows error to a *nix system error
////////////////////////////////////////////////////////////////////////////////

View File

@ -139,7 +139,7 @@ add_library(${LIB_ARANGO} STATIC
Basics/Mutex.cpp
Basics/Nonce.cpp
Basics/OpenFilesTracker.cpp
Basics/ReadWriteLockCPP11.cpp
Basics/ReadWriteLock.cpp
Basics/RocksDBLogger.cpp
Basics/RocksDBUtils.cpp
Basics/SharedPRNG.cpp

View File

@ -421,7 +421,7 @@ void Logger::shutdown() {
int tries = 0;
while (_loggingThread->hasMessages() && ++tries < 1000) {
_loggingThread->wakeup();
usleep(10000);
std::this_thread::sleep_for(std::chrono::microseconds(10000));
}
_loggingThread->beginShutdown();
_loggingThread.reset();

View File

@ -34,6 +34,9 @@
#include <velocypack/Parser.h>
#include <velocypack/velocypack-aliases.h>
#include <thread>
#include <chrono>
using namespace arangodb;
using namespace arangodb::basics;
@ -173,7 +176,7 @@ SimpleHttpResult* SimpleHttpClient::retryRequest(
<< " - retries left: " << (_params._maxRetries - tries);
}
usleep(static_cast<TRI_usleep_t>(_params._retryWaitTime));
std::this_thread::sleep_for(std::chrono::microseconds(_params._retryWaitTime));
}
return result;

View File

@ -3209,7 +3209,7 @@ static void JS_Sleep(v8::FunctionCallbackInfo<v8::Value> const& args) {
? 500000
: static_cast<uint64_t>((until - now) * 1000000);
usleep(static_cast<TRI_usleep_t>(duration));
std::this_thread::sleep_for(std::chrono::microseconds(duration));
}
TRI_V8_RETURN_UNDEFINED();
@ -3266,7 +3266,7 @@ static void JS_Wait(v8::FunctionCallbackInfo<v8::Value> const& args) {
// wait without gc
double until = TRI_microtime() + n;
while (TRI_microtime() < until) {
usleep(1000);
std::this_thread::sleep_for(std::chrono::microseconds(1000));
}
TRI_V8_RETURN_UNDEFINED();
@ -4523,7 +4523,7 @@ bool TRI_RunGarbageCollectionV8(v8::Isolate* isolate, double availableTime) {
}
}
usleep(1000);
std::this_thread::sleep_for(std::chrono::microseconds(1000));
}
return true;

View File

@ -198,6 +198,7 @@ TEST_CASE("cache::Manager", "[cache][!hide][longRunning]") {
caches.emplace(res);
}
}
// intentionally falls through
case 1:
default: {
if (!caches.empty()) {

View File

@ -69,9 +69,9 @@ TEST_CASE("cache::Rebalancer", "[cache][!hide][longRunning]") {
while (!doneRebalancing) {
int status = rebalancer.rebalance();
if (status != TRI_ERROR_ARANGO_BUSY) {
usleep(500 * 1000);
std::this_thread::sleep_for(std::chrono::microseconds(500 * 1000));
} else {
usleep(10 * 1000);
std::this_thread::sleep_for(std::chrono::microseconds(10 * 1000));
}
}
};
@ -195,9 +195,9 @@ TEST_CASE("cache::Rebalancer", "[cache][!hide][longRunning]") {
while (!doneRebalancing) {
int status = rebalancer.rebalance();
if (status != TRI_ERROR_ARANGO_BUSY) {
usleep(500 * 1000);
std::this_thread::sleep_for(std::chrono::microseconds(500 * 1000));
} else {
usleep(10 * 1000);
std::this_thread::sleep_for(std::chrono::microseconds(10 * 1000));
}
}
};

View File

@ -194,11 +194,7 @@ TEST_CASE("ClusterComm::wait", "[cluster][mev]") {
std::future<void> f1(std::async(std::launch::async, [&]{
timespec ts={0,15000000};
#if defined(_WIN32)
usleep(ts.tv_nsec / 1000L);
#else
nanosleep(&ts, nullptr);
#endif
std::this_thread::sleep_for(std::chrono::microseconds(ts.tv_nsec / 1000L));
testme.getResponse(0).result->status = CL_COMM_RECEIVED;
testme.signalResponse();
} // lambda
@ -216,11 +212,7 @@ TEST_CASE("ClusterComm::wait", "[cluster][mev]") {
// do second time to get other response
std::future<void> f2(std::async(std::launch::async, [&]{
timespec ts={0, 30000000};
#if defined(_WIN32)
usleep(ts.tv_nsec / 1000L);
#else
nanosleep(&ts, nullptr);
#endif
std::this_thread::sleep_for(std::chrono::microseconds(ts.tv_nsec / 1000L));
testme.getResponse(0).result->status = CL_COMM_RECEIVED;
testme.signalResponse();
} // lambda
@ -251,11 +243,7 @@ TEST_CASE("ClusterComm::wait", "[cluster][mev]") {
std::future<void> f3(std::async(std::launch::async, [&]{
timespec ts={0,15000000};
#if defined(_WIN32)
usleep(ts.tv_nsec / 1000L);
#else
nanosleep(&ts, nullptr);
#endif
std::this_thread::sleep_for(std::chrono::microseconds(ts.tv_nsec / 1000L));
testme.getResponse(1).result->status = CL_COMM_RECEIVED;
testme.signalResponse();
} // lambda
@ -273,11 +261,7 @@ TEST_CASE("ClusterComm::wait", "[cluster][mev]") {
// do second time to get other response
std::future<void> f4(std::async(std::launch::async, [&]{
timespec ts={0, 30000000};
#if defined(_WIN32)
usleep(ts.tv_nsec / 1000L);
#else
nanosleep(&ts, nullptr);
#endif
std::this_thread::sleep_for(std::chrono::microseconds(ts.tv_nsec / 1000L));
testme.getResponse(0).result->status = CL_COMM_RECEIVED;
testme.signalResponse();
} // lambda
@ -296,11 +280,7 @@ TEST_CASE("ClusterComm::wait", "[cluster][mev]") {
id_first = testme.addSimpleRequest(transId, CL_COMM_SUBMITTED);
std::future<void> f5(std::async(std::launch::async, [&]{
timespec ts={0, 500000000}; //0.5 seconds
#if defined(_WIN32)
usleep(ts.tv_nsec / 1000L);
#else
nanosleep(&ts, nullptr);
#endif
std::this_thread::sleep_for(std::chrono::microseconds(ts.tv_nsec / 1000L));
testme.getResponse(0).result->status = CL_COMM_RECEIVED;
testme.signalResponse();
} // lambda

View File

@ -32,6 +32,9 @@
#include "SimpleHttpClient/Callbacks.h"
#include "SimpleHttpClient/Destination.h"
#include <thread>
#include <chrono>
using namespace arangodb;
using namespace arangodb::communicator;
@ -57,7 +60,7 @@ TEST_CASE("requests are properly aborted", "[communicator]" ) {
communicator.work_once();
communicator.abortRequests();
while (communicator.work_once() > 0) {
usleep(1);
std::this_thread::sleep_for(std::chrono::microseconds(1));
}
REQUIRE(callbacksCalled);
}
@ -84,7 +87,7 @@ TEST_CASE("requests will call the progress callback", "[communicator]") {
communicator.work_once();
communicator.abortRequests();
while (communicator.work_once() > 0) {
usleep(1);
std::this_thread::sleep_for(std::chrono::microseconds(1));
}
REQUIRE(curlRc == CURLE_ABORTED_BY_CALLBACK); // curlRcFn was called
}
}