Esempio n. 1
0
void utl::ProfilePass::run()
{
	//size_t j = 0;

	auto compare = _countUp ?
				[](const Dim& lhs, const Dim& rhs){ return (lhs < 1) == 0 && lhs <= rhs; } :
	[](const Dim& lhs, const Dim& rhs){ return (lhs < 1) == 0 && lhs >= rhs; };

	auto advance = _countUp ?
				[](Dim& lhs, const Dim& rhs){ lhs += rhs; } :
	[](Dim& lhs, const Dim& rhs){ lhs -= rhs; } ;

	for(Dim i = _start; compare(i, _end); advance(i,_step))
	{
		//			TRUE_COMMENT("start : " << this->_start.toString() << ", _end : " << this->_end.toString() << ", _step = " << this->_step.toString() << ", i " << i.toString() << ", comp = "  << compare(i,_end));

		Seconds time = this->prof(i);
		double op = this->ops(i);
		double perf = double(op)  / double(time.count());

		this->_elems.push_back(i.prod());
		this->_times.push_back(time) ;
		this->_ops.push_back(op) ; // 2 * n^2 + n
		this->_perf.push_back(perf);
	}

}
Esempio n. 2
0
std::string MovieSeconds::AsString() const
{
	Seconds curSeconds = GetSeconds();
	std::string theString;
	curSeconds.GetTCString(theString, fTCMode, true);

	return theString;
}
Esempio n. 3
0
    //-----------------------------------------------------------------------
    String timeToString(const Time &value)
    {
      if (Time() == value) return String();

      Microseconds sinceEpoch = zsLib::timeSinceEpoch<Microseconds>(value);
      Seconds asSeconds = toSeconds(sinceEpoch);

      if (asSeconds < sinceEpoch) {
        return durationToString<Microseconds>(sinceEpoch);
      }

      return std::to_string(asSeconds.count());
    }
Esempio n. 4
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();
    }
}
Esempio n. 5
0
void SQLiteCache::Impl::refresh(const Resource& resource, Seconds expires) {
    try {
        if (!db) {
            createDatabase();
        }

        if (!schema) {
            createSchema();
        }

        if (!refreshStmt) {
            refreshStmt = std::make_unique<Statement>( //        1               2
                db->prepare("UPDATE `http_cache` SET `expires` = ? WHERE `url` = ?"));
        } else {
            refreshStmt->reset();
        }

        const auto canonicalURL = util::mapbox::canonicalURL(resource.url);
        refreshStmt->bind(1, expires.count());
        refreshStmt->bind(2, canonicalURL.c_str());
        refreshStmt->run();
    } catch (mapbox::sqlite::Exception& ex) {
        Log::Error(Event::Database, ex.code, ex.what());
    }
}
Esempio n. 6
0
bool OplogBufferCollection::waitForData(Seconds waitDuration) {
    stdx::unique_lock<stdx::mutex> lk(_mutex);
    if (!_cvNoLongerEmpty.wait_for(
            lk, waitDuration.toSystemDuration(), [&]() { return _count != 0; })) {
        return false;
    }
    return _count != 0;
}
Esempio n. 7
0
std::string Timer::elapsedTime() const
{
    auto dur(end_ - start_);
    std::ostringstream sout;

    Hours hours = std::chrono::duration_cast<Hours>(dur);
    dur -= hours;

    Minutes minutes = std::chrono::duration_cast<Minutes>(dur);
    dur -= minutes;

    Seconds seconds = std::chrono::duration_cast<Seconds>(dur);

    sout << hours.count() << ":" << minutes.count() << ":" << seconds.count();

    return sout.str();
}
Esempio n. 8
0
std::string Timer::elapsedCpuTime(const Communicator &comm) const
{
    std::chrono::duration<double, std::nano> dur(comm.sum((end_ - start_).count()));
    std::ostringstream sout;

    Hours hours = std::chrono::duration_cast<Hours>(dur);
    dur -= hours;

    Minutes minutes = std::chrono::duration_cast<Minutes>(dur);
    dur -= minutes;

    Seconds seconds = std::chrono::duration_cast<Seconds>(dur);

    sout << hours.count() << ":" << minutes.count() << ":" << seconds.count();

    return sout.str();
}
bool OplogBufferCollection::blockingPeek(OperationContext* txn,
        Value* value,
        Seconds waitDuration) {
    stdx::unique_lock<stdx::mutex> lk(_mutex);
    if (!_cvNoLongerEmpty.wait_for(
    lk, waitDuration.toSystemDuration(), [&]() {
    return _count != 0;
})) {
        return false;
    }
    return _peekOneSide_inlock(txn, value, true);
}
Esempio n. 10
0
    //-----------------------------------------------------------------------
    String durationToString(
                            const Seconds &secPart,
                            std::intmax_t fractionalPart,
                            std::intmax_t den
                            )
    {

      if (den < 1) {
        return string(secPart.count());
      }

      char buffer[100] {};
      char format[50] {};

      std::intmax_t secValue = static_cast<std::intmax_t>(secPart.count());

      int digits = static_cast<int>(log10(den));

      snprintf(format, sizeof(format)-1, "%%lli.%%0%illi", digits);
      snprintf(buffer, sizeof(buffer)-1, format, (long long)secValue, (long long)fractionalPart);

      return buffer;
    }
Esempio n. 11
0
void WorkQueue::dispatchAfter(Seconds duration, Function<void()>&& function)
{
    ASSERT(m_timerQueue);
    ref();

    RefPtr<TimerContext> context = TimerContext::create();
    context->queue = this;
    context->function = WTFMove(function);

    {
        // The timer callback could fire before ::CreateTimerQueueTimer even returns, so we protect
        // context->timer with a mutex to ensure the timer callback doesn't access it before the
        // timer handle has been stored in it.
        MutexLocker lock(context->timerMutex);

        int64_t milliseconds = duration.milliseconds();

        // From empirical testing, we've seen CreateTimerQueueTimer() sometimes fire up to 5+ ms early.
        // This causes havoc for clients of this code that expect to not be called back until the
        // specified duration has expired. Other folks online have also observed some slop in the
        // firing times of CreateTimerQuqueTimer(). From the data posted at
        // http://omeg.pl/blog/2011/11/on-winapi-timers-and-their-resolution, it appears that the slop
        // can be up to about 10 ms. To ensure that we don't fire the timer early, we'll tack on a
        // slop adjustment to the duration, and we'll use double the worst amount of slop observed
        // so far.
        const int64_t slopAdjustment = 20;
        if (milliseconds) 
            milliseconds += slopAdjustment;

        // Since our timer callback is quick, we can execute in the timer thread itself and avoid
        // an extra thread switch over to a worker thread.
        if (!::CreateTimerQueueTimer(&context->timer, m_timerQueue, timerCallback, context.get(), clampTo<DWORD>(milliseconds), 0, WT_EXECUTEINTIMERTHREAD)) {
            ASSERT_WITH_MESSAGE(false, "::CreateTimerQueueTimer failed with error %lu", ::GetLastError());
            return;
        }
    }

    // The timer callback will handle destroying context.
    context.release().leakRef();
}
Esempio n. 12
0
void SQLiteCache::Impl::refresh(const Resource& resource, Seconds expires) {
    try {
        initializeDatabase();

        if (!refreshStmt) {
            refreshStmt = std::make_unique<Statement>(
                db->prepare("UPDATE `http_cache` SET "
                    //            1              2               3
                    "`accessed` = ?, `expires` = ? WHERE `url` = ?"));
        } else {
            refreshStmt->reset();
        }

        const auto canonicalURL = util::mapbox::canonicalURL(resource.url);
        refreshStmt->bind(1, int64_t(toSeconds(SystemClock::now()).count()));
        refreshStmt->bind(2, int64_t(expires.count()));
        refreshStmt->bind(3, canonicalURL.c_str());
        refreshStmt->run();
    } catch (mapbox::sqlite::Exception& ex) {
        Log::Error(Event::Database, ex.code, ex.what());
    }
}
bool CvHttpRequestAsync::Execute( CEventListener* apEventListener, const Seconds& aTimeout )
{
	if ( m_maxThreads == 0 )
	{
		LogMessage( enLogLevel_Error, "ERROR: CvHttpRequestAsync should be initialized with max concurrency > 0" );
		return false;
	}
	
	m_req.timeout = aTimeout.Value();
			
	m_pListener = apEventListener;
	m_bDone = false;
	
	CvMutexLock lock( m_mutexThreads );

	if ( m_countIdleThreads == 0 )
		CreateThread();

	m_queueExecute.Push( this );

	--m_countIdleThreads;		

	return true;
}
Esempio n. 14
0
void BossAI::_DespawnAtEvade(Seconds delayToRespawn, Creature* who)
{
    if (delayToRespawn < Seconds(2))
    {
        TC_LOG_ERROR("scripts", "_DespawnAtEvade called with delay of %ld seconds, defaulting to 2.", delayToRespawn.count());
        delayToRespawn = Seconds(2);
    }

    if (!who)
        who = me;

    if (TempSummon* whoSummon = who->ToTempSummon())
    {
        TC_LOG_WARN("scripts", "_DespawnAtEvade called on a temporary summon.");
        whoSummon->UnSummon();
        return;
    }

    who->DespawnOrUnsummon(0, Seconds(delayToRespawn));

    if (instance && who == me)
        instance->SetBossState(_bossId, FAIL);
}
Esempio n. 15
0
void Balancer::_sleepFor(OperationContext* txn, Seconds waitTimeout) {
    stdx::unique_lock<stdx::mutex> lock(_mutex);
    _condVar.wait_for(lock, waitTimeout.toSystemDuration(), [&] { return _state != kRunning; });
}
Esempio n. 16
0
 Days::Days(const Seconds &n) : m_value(double(n.toDays()))
 {
 }
Esempio n. 17
0
void MovieSeconds::Set(const Seconds &time, const Seconds &fieldDuration)
{
	double	dif23967=std::abs(fieldDuration.AsDouble() - videoFieldRate23976);	// 23.976
	double	dif24  = std::abs(fieldDuration.AsDouble() - videoFieldRate6_24);	// 24
	double	dif525 = std::abs(fieldDuration.AsDouble() - videoFieldRate525_60);	// 25
	double	dif625 = std::abs(fieldDuration.AsDouble() - videoFieldRate625_50);	// 29.97
	double	dif630 = std::abs(fieldDuration.AsDouble() - videoFieldRate630_60);	// 30
	double	dif50  = std::abs(fieldDuration.AsDouble() - videoFieldRate50);		// 50
	double	dif5994= std::abs(fieldDuration.AsDouble() - videoFieldRate5994);	// 59.94
	double	dif60  = std::abs(fieldDuration.AsDouble() - videoFieldRate60);		// 60
	double compareDiff = 1;

	if (dif23967 < .001)
	{
		compareDiff = dif23967;
		fInitialized = true;
		fVideoRate = eVideoRate23976;
	}
	else if (dif24 < .001)
	{
		compareDiff = dif24;
		fInitialized = true;
		fVideoRate = eVideoRate6_24;
	}
	else if (dif525 < .001)
	{
		compareDiff = dif525;
		fInitialized = true;
		fVideoRate = eVideoRate525_60;
	}
	else if (dif625 < .001)
	{
		compareDiff = dif625;
		fInitialized = true;
		fVideoRate = eVideoRate625_50;
	}
	else if (dif630 < .001)
	{
		compareDiff = dif630;
		fInitialized = true;
		fVideoRate = eVideoRate630_60;
	}
	else if (dif50 < .001)
	{
		compareDiff = dif50;
		fInitialized = true;
		fVideoRate = eVideoRate50;
	}
	else if (dif5994 < .001)
	{
		compareDiff = dif5994;
		fInitialized = true;
		fVideoRate = eVideoRate5994;
	}
	else if (dif60 < .001)
	{
		compareDiff = dif60;
		fInitialized = true;
		fVideoRate = eVideoRate60;
	}

	assert(fInitialized);
	if (fInitialized)
	{
		if (compareDiff > .0000001)
		{
			assert(0);
			std::cout << "Suspicious field duration " << fieldDuration.AsDouble() << std::endl;
		}

		fFieldDuration = fieldDuration;
		SetFieldsFromSeconds(time);
		fTCMode = ::VideoRateToTCMode(fVideoRate);
	}
}
Esempio n. 18
0
int main()
{
	{
		Months months(23);
		cout << months.getValue() << " months" << endl;
		Days days = months;
		cout << days.getValue() << " days" << endl;
		Hours hrs(months);
		cout << hrs.getValue() << " hrs." << endl;
		Minutes m(hrs);
		cout << m.getValue() << " min." << endl;
		Seconds s(m);
		cout << s.getValue() << " sec." << endl;
		Milliseconds ms;
		ms = s;
		cout << ms.getValue() << " ms" << endl;
	}

	cout << "---------------------\n";

	{
		Minutes min(10);
		cout << min.getValue() << " min. " << endl;
		Seconds sec = min;
		cout << sec.getValue() << " sec. " << endl;
	}

	cout << "---------------------\n";

	{
		Miles miles(24859); //circumfrence of the Earth
		cout << miles.getValue() << " miles" << endl;
		Yards yards(miles);
		cout << yards.getValue() << " yd." << endl;
		Feet feet(miles);
		cout << feet.getValue() << " ft." << endl;
		Inches inches(miles);
		cout << inches.getValue() << " in." << endl;
	}

	cout << "---------------------\n";

	{
		Minutes minutes(1000000ULL);
		Yards yards(minutes);
		cout << "There are " << (yards.getValue()/1000000.0) << " yards in a minute!\n";
	}

	cout << "---------------------\n";

	{
		Inches inches;
		Feet feet;
		Yards yards;

		string s = "12 12 12";

		std::istringstream iss(s);

		iss >> inches >> feet >> yards;

		cout << inches << ' ' << feet << ' ' << yards << endl;

		cout << inches << ' ' << ((Inches)feet) << ' ' << ((Inches)yards) << endl;
	}

	cout << "---------------------\n";

	{
		Radians r;

		r = 3.14159;

		cout << r << " radians is " << (Degrees)r << " degrees\n";

		Degrees d(r);

		Degrees d2;

		d2 = r;

		cout << (Degrees)r << " == " << d << " == " << d2 << endl;
	}

	system("PAUSE");

	return 0;
}
Esempio n. 19
0
	inline void Formatter(FormatData& formatData, const Seconds& seconds)
	{
		Formatter(formatData, seconds.count());

		formatData.string.push_back(U's');
	}