글

라벨이 timer인 게시물 표시

OS/2 codes: Implement nano timer

All the OS/2 APIs releated to time, work in milliseconds. But sometimes a more precise timer is needed. How can this timer implemented on OS/2 ? Fortunately, OS/2 have APIs for this purpose. They are DosTmrQueryCount() and DosTmrQueryFreq(). Let's see their prototype, first. APIRET DosTmrQueryFreq(PULONG pulTmrFreq) APIRET DosTmrQueryTime(PQWORD pqwTmrTime) These APIs are releated to IRQ0 high resolution timer(Intel 8254). DosTmrQueryFreq() provides its frequency, DosTmrQueryTime provides its time snapshot. So you can get a time in seconds if you divide a time snapshot by a frequency. And if you multiply this value by 10^9, then you can get a time in nano seconds. That's it. However, you should be careful. Because the used values are integer numbers. So the reaminder can be ignored when dividing and the overflow can occur when multiplying. To avoid this, you can use 'double'. But if you mind using float pointing numbers, adjust the order of operations carefu...