Пример #1
0
void IOService::post(const Duration& waitFor, const IOCallback& handler, const char* tag, const char* tagStat) {
#if BOOST_VERSION==103900
    static bool warnOnce=true;
    if (warnOnce) {
        warnOnce=false;
        SILOG(core,error,"Using buggy version of boost (1.39.0), leaking deadline_timer to avoid crash");
    }
#endif
    deadline_timer_ptr timer(new deadline_timer(*mImpl, posix_microseconds(waitFor.toMicroseconds())));

#ifdef SIRIKATA_TRACK_EVENT_QUEUES
    mTimersEnqueued++;
    {
        LockGuard lock(mMutex);
        if (mTagCounts.find(tag) == mTagCounts.end())
            mTagCounts[tag] = 0;
        mTagCounts[tag]++;
    }
    IOCallbackWithError orig_cb = std::tr1::bind(&handle_deadline_timer, _1, timer, handler);
    timer->async_wait(
        std::tr1::bind(&IOService::decrementTimerCount, this,
            _1, Timer::now(), waitFor, orig_cb, tag,tagStat
        )
    );
#else
    timer->async_wait(std::tr1::bind(&handle_deadline_timer, _1, timer, handler));
#endif
}
Пример #2
0
void TimerHandle::wait(
        const std::tr1::shared_ptr<TimerHandle> &thisPtr,
        const Duration &num_seconds) {
    mTimer->expires_from_now(boost::posix_time::microseconds(num_seconds.toMicroseconds()));
    std::tr1::weak_ptr<TimerHandle> weakThisPtr(thisPtr);
    mTimer->async_wait(
        boost::bind(
            &TimerHandle::TimedOut::timedOut,
            boost::asio::placeholders::error,
            weakThisPtr));
}
Пример #3
0
void TimerSpeedBenchmark::start() {
    mForceStop = false;

    // Check throughput of timer calls
    Time start_time = Timer::now();

    Time dummy_t = Time::null();
    for(uint32 ii = 0; ii < ITERATIONS && !mForceStop; ii++)
        dummy_t = Timer::now();

    if (mForceStop)
        return;

    Time end_time = Timer::now();
    Duration dur = end_time - start_time;

    SILOG(benchmark,info,
          ITERATIONS << " timer invokations, " << dur << ": "
          << (dur.toMicroseconds()*1000/float(ITERATIONS)) << "ns/call, "
          << float(ITERATIONS)/dur.toSeconds() << " calls/s");

    notifyFinished();
}
Пример #4
0
    TimerHandler(Network::IOService *io, SentMessage *messageInfo, const Duration& num_seconds)
        : mTimer(*static_cast<boost::asio::io_service*>(io), boost::posix_time::microseconds(num_seconds.toMicroseconds())) {

        mSentMessage = messageInfo;
        mTimer.async_wait(
            boost::bind(&TimerHandler::timedOut, this, boost::asio::placeholders::error));
    }
Пример #5
0
void IOService::post(const Duration& waitFor, const IOCallback& handler) {
    deadline_timer_ptr timer(new deadline_timer(*mImpl, posix_microseconds(waitFor.toMicroseconds())));
    timer->async_wait(std::tr1::bind(&handle_deadline_timer, _1, timer, handler));
}
Пример #6
0
void IOServiceFactory::dispatchServiceMessage(IOService*ios,const Duration&waitFor,const std::tr1::function<void()>&f){
    std::tr1::shared_ptr<boost::asio::deadline_timer> t(new boost::asio::deadline_timer(*ios,boost::posix_time::microseconds(waitFor.toMicroseconds())));
    using std::tr1::placeholders::_1;
    t->async_wait(std::tr1::bind(&handle_deadline_timer,_1,t,f));
}