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