Example #1
0
    void PeriodicTaskRunner::run() {
        // Use a shorter cycle time in debug mode to help catch race conditions.
        const std::chrono::seconds waitTime(kDebugBuild ? 5 : 60);

        std::unique_lock<std::mutex> lock(_mutex);
        while (!_shutdownRequested) {
            if (std::cv_status::timeout == _cond.wait_for(lock, waitTime))
                _runTasks();
        }
    }
Example #2
0
void PeriodicTaskRunner::run() {
    // Use a shorter cycle time in debug mode to help catch race conditions.
    const Seconds waitTime(kDebugBuild ? 5 : 60);

    stdx::unique_lock<stdx::mutex> lock(_mutex);
    while (!_shutdownRequested) {
        {
            MONGO_IDLE_THREAD_BLOCK;
            if (stdx::cv_status::timeout != _cond.wait_for(lock, waitTime.toSystemDuration()))
                continue;
        }
        _runTasks();
    }
}
Example #3
0
    void PeriodicTaskRunner::run() {
        // Use a shorter cycle time in debug mode to help catch race conditions.
        const size_t waitMillis = (debug ? 5 : 60) * 1000;

        const stdx::function<bool()> predicate =
            stdx::bind( &PeriodicTaskRunner::_isShutdownRequested, this );

        mutex::scoped_lock lock( _mutex );
        while ( !predicate() ) {
            const boost::xtime deadline = incxtimemillis( waitMillis );
            if ( !_cond.timed_wait( lock.boost(), deadline, predicate ) )
                _runTasks();
        }
    }
Example #4
0
void TaskRunner::schedule(const Task& task) {
    invariant(task);

    stdx::lock_guard<stdx::mutex> lk(_mutex);

    _tasks.push_back(task);
    _condition.notify_all();

    if (_active) {
        return;
    }

    _threadPool->schedule([this] { _runTasks(); });

    _active = true;
    _cancelRequested = false;
}