Interval Timing 编辑
NSPR defines a platform-dependent type, /wiki/en-US/docs/Mozilla/Projects/NSPR/Reference/PRIntervalTime
, for timing intervals of fewer than approximately 6 hours. This chapter describes /wiki/en-US/docs/Mozilla/Projects/NSPR/Reference/PRIntervalTime
and the functions that allow you to use it for timing purposes:
Interval Time Type and Constants
All timed functions in NSPR require a parameter that depicts the amount of time allowed to elapse before the operation is declared failed. The type of such arguments is /wiki/en-US/docs/Mozilla/Projects/NSPR/Reference/PRIntervalTime
. Such parameters are common in NSPR functions such as those used for I/O operations and operations on condition variables.
NSPR 2.0 provides interval times that are efficient in terms of performance and storage requirements. Conceptually, they are based on free-running counters that increment at a fixed rate without possibility of outside influence (as might be observed if one was using a time-of-day clock that gets reset due to some administrative action). The counters have no fixed epoch and have a finite period. To make use of these counters, the application must declare a point in time, the epoch, and an amount of time elapsed since that epoch, the interval. In almost all cases the epoch is defined as the value of the interval timer at the time it was sampled.
Interval Functions
Interval timing functions are divided into three groups:
- Getting the Current Interval and Ticks Per Second
- Converting Standard Clock Units to Platform-Dependent Intervals
- Converting Platform-Dependent Intervals to Standard Clock Units
Getting the Current Interval and Ticks Per Second
/wiki/en-US/docs/Mozilla/Projects/NSPR/Reference/PR_IntervalNow
/wiki/en-US/docs/Mozilla/Projects/NSPR/Reference/PR_TicksPerSecond
Converting Standard Clock Units to Platform-Dependent Intervals
/wiki/en-US/docs/Mozilla/Projects/NSPR/Reference/PR_SecondsToInterval
/wiki/en-US/docs/Mozilla/Projects/NSPR/Reference/PR_MillisecondsToInterval
/wiki/en-US/docs/Mozilla/Projects/NSPR/Reference/PR_MicrosecondsToInterval
Converting Platform-Dependent Intervals to Standard Clock Units
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论