clock_setres()
http://www.users.pjwstk.edu.pl/~jms/qnx/help/watcom/clibref/qnx/clock_setres.htmlの日本語訳。
訳してはみたものの・・・なんですかこれ?
本文
1クロックあたりの分解能を設定する。
set the resolution of a clock
概要 - Synopsis:
#includeint clock_setres( clockid_t clock_id, struct timespec *res );
詳細 - Description:
clock_setres()関数はクロックの分解能を設定します。クロックはclock_idで指定します。設定する分解能はresが指すバッファの内容です。サポートされるクロックIDはCLOCK_REALTIMEだけです。
The clock_setres() function sets the resolution of the clock specified by clock_id from the buffer pointed to by res. The only supported clock ID is CLOCK_REALTIME.
resパラメータの指す構造体は、最低限以下のメンバを含みます。
The res parameter points to a structure containing at least the following members:
time_t tv_sec 無視される - Ignored. time_t tv_nsec クロックの分解能をナノ秒で指定 - The resolution of the clock, in nanoseconds.
サポートされない値をクロックとして指定した場合、サポートされる値のうち指定値より大きい直近のものに修正されます。サポートされる値は、0.5 msec、1 msec、2 msec、5 msec、10 msec、25 msec、50 msec、そして55 msecです。
If the specified clock isn't a supported value, an adjustment is made to the next lowest supported value. The supported values include 0.5 msec, 1 msec, 2 msec, 5 msec, 10 msec, 25 msec, 50 msec, and 55 msec.
ナノ秒に変換するには、ミリ秒(=msec)に1000000を描けます。
To convert to nanoseconds multiply the number of milliseconds (that is, msec) by 1000000.
タイマーの周期は、デフォルトではプロセッサのCPU速度が基準になります。これは、sinユーティリティかqnx_osinfo()関数を使って調べられます。
The default timer period is set based upon the CPU speed of the processor. This can be queried using the sin utility or the qnx_osinfo() function.
CPU速度 | 周期 |
< 300 | 50 msec |
>= 300 | 10 msec |
CPU speed Period < 300 50 msec >= 300 10 msec
非常に短い間隔(例えば、1 msec)を設定すると、遅いマシンでは重大なシステムオーバヘッドを引き起こすことがあります。
Setting a very short period (for example, 1 msec) on a slow machine may significantly increase system overhead.
戻り値- Returns:
0 成功 - Success -1 エラー発生。eronoにエラーを示す番号が設定される。 - An error occurred. errno is set to indicate the error.
エラー - Errors:
EINVAL clock_idがCLOCK_REALTIMEでない - The clock_id isn't CLOCK_REALTIME.
例 - Examples:
/* * クロック分解能を表示するプログラム - This program prints out the clock resolution. */ #include#include #include #define MSEC ( 1000000 ) int main( void ) { struct timespec res; /* 分解能を設定する - Set the resolution */ res.tv_nsec = 10 * MSEC; if( clock_setres( CLOCK_REALTIME, &res) == -1 ) { perror( "clock set resolution" ); exit( EXIT_FAILURE ); } printf( "Old resolution is %ld milliseconds.\n", res.tv_nsec / MSEC ); /* 分解能を取得する - Get the new resolution */ if( clock_getres( CLOCK_REALTIME, &res) == -1 ) { perror( "clock get resolution" ); exit( EXIT_FAILURE ); } printf( "New resolution is %ld milliseconds.\n", res.tv_nsec / MSEC ); return( EXIT_SUCCESS ); }
分類 - Classification:
安全か: | |
割り込みハンドラ | いいえ |
シグナルハンドラ | はい。しかし、errnoが変わる |
スレッド | はい |
Safety: Interrupt handler No Signal handler Yes, but modifies errno Thread Yes