当前位置: 首页>>代码示例>>C++>>正文


C++ TimeStamp::getEpoch方法代码示例

本文整理汇总了C++中TimeStamp::getEpoch方法的典型用法代码示例。如果您正苦于以下问题:C++ TimeStamp::getEpoch方法的具体用法?C++ TimeStamp::getEpoch怎么用?C++ TimeStamp::getEpoch使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在TimeStamp的用法示例。


在下文中一共展示了TimeStamp::getEpoch方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: main

int main()
{
    {
        struct timeval tv;
        TimeStampQueue tsq;
        TimeStamp now;
        cout << "Start Time: " << now << endl;
        for(int i=100; i<=900; i+=100)
            tsq.push( new TimeStamp(6, i MILLISEC) );
        tsq.push( new TimeStamp(10, 0) );
        tsq.push( new TimeStamp(3, 00 MILLISEC) );
        tsq.push( new TimeStamp(14, 950 MILLISEC) );
        cout << "      Expected time       \t         Real Time        \t  Delta  \tFlag" << endl;
        cout << "==========================\t==========================\t=========\t====" << endl;
        while( 1 )
        {
            now.setNow();
            if( ! tsq.empty() )
            {
                // schedule next event
                tv.tv_sec = tsq.top()->getEpoch() - now.getEpoch();
                tv.tv_usec = tsq.top()->getMicroSecond() - now.getMicroSecond();
                // adjust for carry
                if( tv.tv_usec < 0 )
                {
                    tv.tv_sec -= 1;
                    tv.tv_usec = 1000000L + tv.tv_usec;
                }
                if( tv.tv_sec < 0 )
                    tv.tv_sec = 0;
                cout << "wakeup set in " << tv.tv_sec << " seconds " << tv.tv_usec/1000 << " msec" << endl;
            }
            else
            {
                break;
                tv.tv_sec = 1;
                tv.tv_usec = 50 MILLISEC;
            }
            select(0, NULL, NULL, NULL, &tv);  // used as sleep
            while( ! tsq.empty() )
            {
                TimeStamp * tstmp = tsq.top();
                now.setNow();
                long int secdelta = tstmp->getEpoch() - now.getEpoch();
                long int usecdelta = tstmp->getMicroSecond() - now.getMicroSecond(); // negative delta if late
                if( secdelta == 0 )
                {
                    if( usecdelta <= 50 MILLISEC && usecdelta >= -50 MILLISEC) // +/-50msec is considered "on-time"
                    {
                        cout << tstmp << "\t" << now << "\t" << secdelta << "." << usecdelta << "\t\t----" << endl;
                        tsq.pop();
                        delete(tstmp);
                    }
                    else if( usecdelta < -50 MILLISEC )  // late more than 50 msec but less than 1 sec
                    {
                        cout << tstmp << "\t" << now << "\t" << secdelta << "." << usecdelta << "\tlate" << endl;
                        tsq.pop();
                        delete(tstmp);
                    }
                    else  // > 50 msec but < 1sec => reschedule
                        break;
                }
                else if ( secdelta < 0 )  // negative seconds means at least one second LATE
                {
                    cout << tstmp << "\t" << now << "\t" << secdelta << "." << usecdelta << "\tLATE" << endl;
                    tsq.pop();
                    delete(tstmp);
                }
                else
                    break;
            }
        }
    }
}
开发者ID:jetmaint,项目名称:phcc,代码行数:74,代码来源:timertest.cpp


注:本文中的TimeStamp::getEpoch方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。