📄 semclib.html
字号:
<html><head><!-- /vobs/wpwr/docs/vxworks/ref/semCLib.html - generated by refgen from semCLib.c --> <title> semCLib </title></head><body bgcolor="#FFFFFF"> <hr><a name="top"></a><p align=right><a href="libIndex.htm"><i>VxWorks API Reference : OS Libraries</i></a></p></blockquote><h1>semCLib</h1> <blockquote></a></blockquote><h4>NAME</h4><blockquote> <p><strong>semCLib</strong> - counting semaphore library </p></blockquote><h4>ROUTINES</h4><blockquote><p><p><b><a href="./semCLib.html#semCCreate">semCCreate</a>( )</b> - create and initialize a counting semaphore<br><p></blockquote><h4>DESCRIPTION</h4><blockquote><p>This library provides the interface to VxWorks countingsemaphores. Counting semaphores are useful for guarding multipleinstances of a resource.<p>A counting semaphore may be viewed as a cell in memory whose contentskeep track of a count. When a task takes a counting semaphore, using<b><a href="./semLib.html#semTake">semTake</a>( )</b>, subsequent action depends on the state of the count:<table></tr><tr valign=top><td>(1)<td>If the count is non-zero, it is decremented and the calling taskcontinues executing.</tr><tr valign=top><td>(2)<td>If the count is zero, the task will be blocked, pending the availabilityof the semaphore. If a timeout is specified and the timeout expires, thepended task will be removed from the queue of pended tasks and enter theready state with an ERROR status. A pended task is ineligible for CPUallocation. Any number of tasks may be pended simultaneously on the samecounting semaphore.</table>When a task gives a semaphore, using <b><a href="./semLib.html#semGive">semGive</a>( )</b>, the next available task inthe pend queue is unblocked. If no task is pending on this semaphore, thesemaphore count is incremented. Note that if a semaphore is given, and atask is unblocked that is of higher priority than the task that called<b><a href="./semLib.html#semGive">semGive</a>( )</b>, the unblocked task will preempt the calling task.<p>A <b><a href="./semLib.html#semFlush">semFlush</a>( )</b> on a counting semaphore will atomically unblock all pendedtasks in the semaphore queue. So all tasks will be made ready before anytask actually executes. The count of the semaphore will remain unchanged.<p></blockquote><h4>INTERRUPT USAGE</h4><blockquote><p>Counting semaphores may be given but not taken from interrupt level.<p></blockquote><h4>CAVEATS</h4><blockquote><p>There is no mechanism to give back or reclaim semaphores automatically whentasks are suspended or deleted. Such a mechanism, though desirable, is notcurrently feasible. Without explicit knowledge of the state of the guardedresource or region, reckless automatic reclamation of a semaphore couldleave the resource in a partial state. Thus, if a task ceases executionunexpectedly, as with a bus error, currently owned semaphores will not begiven back, effectively leaving a resource permanently unavailable. Themutual-exclusion semaphores provided by <b><a href="./semMLib.html#top">semMLib</a></b> offer protection fromunexpected task deletion.<p></blockquote><h4>INCLUDE FILES</h4><blockquote><p><b>semLib.h</b><p></blockquote><h4>SEE ALSO</h4><blockquote><p><b><a href="./semLib.html#top">semLib</a></b>, <b><a href="./semBLib.html#top">semBLib</a></b>, <b><a href="./semMLib.html#top">semMLib</a></b>,<i>VxWorks Programmer's Guide: Basic OS </i><hr><a name="semCCreate"></a><p align=right><a href="rtnIndex.htm"><i>OS Libraries : Routines</i></a></p></blockquote><h1>semCCreate( )</h1> <blockquote></a></blockquote><h4>NAME</h4><blockquote> <p><strong>semCCreate( )</strong> - create and initialize a counting semaphore</p></blockquote><h4>SYNOPSIS</h4><blockquote><p><pre>SEM_ID semCCreate ( int options, /* semaphore option modes */ int initialCount /* initial count */ )</pre></blockquote><h4>DESCRIPTION</h4><blockquote><p>This routine allocates and initializes a counting semaphore. Thesemaphore is initialized to the specified initial count.<p>The <i>options</i> parameter specifies the queuing style for blocked tasks.Tasks may be queued on a priority basis or a first-in-first-out basis.These options are <b>SEM_Q_PRIORITY</b> (0x1) and <b>SEM_Q_FIFO</b> (0x0), respectively.That parameter also specifies if <b><a href="./semLib.html#semGive">semGive</a>( )</b> should return ERROR whenthe semaphore fails to send events. This option is turned off by default;it is activated by doing a bitwise-OR of <b>SEM_EVENTSEND_ERR_NOTIFY</b> (0x10) with the queuing style of the semaphore.<p></blockquote><h4>RETURNS</h4><blockquote><p>The semaphore ID, or NULL if memory cannot be allocated.</blockquote><h4>SEE ALSO</h4><blockquote><p><b><a href="./semCLib.html#top">semCLib</a></b></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -