📄 c-basic7.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"><html><head><link rel="STYLESHEET" type="text/css" href="wrs.css"><title> Basic OS </title></head><body bgcolor="FFFFFF"><p class="navbar" align="right"><a href="index.html"><img border="0" alt="[Contents]" src="icons/contents.gif"></a><a href="GuideIX.html"><img border="0" alt="[Index]" src="icons/index.gif"></a><a href="c-basic.html"><img border="0" alt="[Top]" src="icons/top.gif"></a><a href="c-basic6.html"><img border="0" alt="[Prev]" src="icons/prev.gif"></a><a href="c-basic8.html"><img border="0" alt="[Next]" src="icons/next.gif"></a></p><font face="Helvetica, sans-serif" class="sans"><h3 class="H2"><i><a name="86917">2.7 POSIX Clocks and Timers</a></i></h3></font><dl class="margin"><dl class="margin"><dd><p class="Body"><a name="86919"> </a>A <i class="term">clock</i> is a software construct (<b>struct timespec</b>, defined in <b class="file">time.h</b>) that keeps time in seconds and nanoseconds. The software clock is updated by system-clock ticks. VxWorks provides a POSIX 1003.1b standard clock and timer interface. </p><dd><p class="Body"><a name="86920"> </a>The POSIX standard provides for identifying multiple virtual clocks, but only one clock is required--the system-wide real-time clock, identified in the clock and timer routines as <b class="symbol_UC">CLOCK_REALTIME</b> (also defined in <b class="file">time.h</b>). VxWorks provides routines to access the system-wide real-time clock; see the reference entry for <b class="library">clockLib</b>. (No virtual clocks are supported in VxWorks.)</p><dd><p class="Body"><a name="86923"> </a>The POSIX timer facility provides routines for tasks to signal themselves at some time in the future. Routines are provided to create, set, and delete a timer; see the reference entry for <b class="library">timerLib</b>. When a timer goes off, the default signal (<b class="symbol_UC">SIGALRM</b>) is sent to the task. Use <b class="routine"><i class="routine">sigaction</i></b><b>( )</b>to install a signal handler that executes when the timer expires (see <a href="c-basic4.html#86380"><i class="title">2.4.7 Signals</i></a>). </p></dl></dl><h4 class="EntityTitle"><a name="86928"><font face="Helvetica, sans-serif" size="-1" class="sans">Example 2-13: POSIX Timers </font></a></h4><dl class="margin"><dl class="margin"><dd><pre class="Code"><b><a name="86929">/* This example creates a new timer and stores it in timerid. */</a></b><dd> <b><a name="86931">/* includes */ #include "vxWorks.h" #include "time.h"</a></b><dd> <b><a name="86933">int createTimer (void) { timer_t timerid;</a></b><dd> <b><a name="86935"> /* create timer */ if (timer_create (CLOCK_REALTIME, NULL, &timerid) == ERROR) { printf ("create FAILED\n"); return (ERROR); }</a></b><dd> <b><a name="86937"> return (OK); }</a></b></pre></dl><dl class="margin"><dd><p class="Body"><a name="86939"> </a>An additional POSIX function, <b class="routine"><i class="routine">nanosleep</i></b><b>( )</b>, allows specification of sleep or delay time in units of seconds and nanoseconds, as opposed to the ticks used by the Wind <b class="routine"><i class="routine">taskDelay</i></b><b>( )</b> function. Only the units are different, however, not the precision: both delay routines have the same precision, determined by the system clock rate.</p></dl></dl><a name="foot"><hr></a><p class="navbar" align="right"><a href="index.html"><img border="0" alt="[Contents]" src="icons/contents.gif"></a><a href="GuideIX.html"><img border="0" alt="[Index]" src="icons/index.gif"></a><a href="c-basic.html"><img border="0" alt="[Top]" src="icons/top.gif"></a><a href="c-basic6.html"><img border="0" alt="[Prev]" src="icons/prev.gif"></a><a href="c-basic8.html"><img border="0" alt="[Next]" src="icons/next.gif"></a></p></body></html><!---by WRS Documentation (), Wind River Systems, Inc. conversion tool: Quadralay WebWorks Publisher 4.0.11 template: CSS Template, Jan 1998 - Jefro --->
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -