vxwsem.html

来自「vxworks相关论文」· HTML 代码 · 共 749 行 · 第 1/3 页

HTML
749
字号
<html><head><!-- /vobs/wpwr/docs/vxworks/ref/VXWSem.html - generated by refgen from /vobs/wpwr/docs/vxworks/ref/VXWSem.i --> <title> VXWSem </title></head><body bgcolor="#FFFFFF"> <hr><a name="top"></a><p align=right><a href="libIndex.html"><i>VxWorks Reference Manual :  Wind Foundation Classes</i></a></p></blockquote><h1>VXWSem</h1> <blockquote></a></blockquote><h4>NAME</h4><blockquote>  <p><strong>VXWSem</strong> - semaphore classes</p></blockquote><h4>METHODS</h4><blockquote><p><p><b><i><a href="./VXWSem.html#VXWSem::VXWSem">VXWSem::VXWSem</a></i>(&nbsp;)</b>  -  build semaphore object from semaphore ID<br><b><i><a href="./VXWSem.html#VXWSem::~VXWSem">VXWSem::~VXWSem</a></i>(&nbsp;)</b>  -  delete a semaphore<br><b><i><a href="./VXWSem.html#VXWSem::give">VXWSem::give</a></i>(&nbsp;)</b>  -  give a semaphore<br><b><i><a href="./VXWSem.html#VXWSem::take">VXWSem::take</a></i>(&nbsp;)</b>  -  take a semaphore<br><b><i><a href="./VXWSem.html#VXWSem::flush">VXWSem::flush</a></i>(&nbsp;)</b>  -  unblock every task pended on a semaphore<br><b><i><a href="./VXWSem.html#VXWSem::id">VXWSem::id</a></i>(&nbsp;)</b>  -  reveal underlying semaphore ID<br><b><i><a href="./VXWSem.html#VXWSem::info">VXWSem::info</a></i>(&nbsp;)</b>  -  get a list of task IDs that are blocked on a semaphore<br><b><i><a href="./VXWSem.html#VXWSem::show">VXWSem::show</a></i>(&nbsp;)</b>  -  show information about a semaphore<br><b><i><a href="./VXWSem.html#VXWCSem::VXWCSem">VXWCSem::VXWCSem</a></i>(&nbsp;)</b>  -  create and initialize a counting semaphore<br><b><i><a href="./VXWSem.html#VXWBSem::VXWBSem">VXWBSem::VXWBSem</a></i>(&nbsp;)</b>  -  create and initialize a binary semaphore<br><b><i><a href="./VXWSem.html#VXWMSem::VXWMSem">VXWMSem::VXWMSem</a></i>(&nbsp;)</b>  -  create and initialize a mutual-exclusion semaphore<br><b><i><a href="./VXWSem.html#VXWMSem::giveForce">VXWMSem::giveForce</a></i>(&nbsp;)</b>  -  give a mutual-exclusion semaphore without restrictions<br><p></blockquote><h4>DESCRIPTION</h4><blockquote><p>Semaphores are the basis for synchronization and mutual exclusion inVxWorks.  They are powerful in their simplicity and form the foundationfor numerous VxWorks facilities.<p>Different semaphore types serve different needs, and while thebehavior of the types differs, their basic interface is the same.The VXWSem class provides semaphore routines common to all VxWorkssemaphore types.  For all types, the two basic operations are<b><i><a href="./VXWSem.html#VXWSem::take">VXWSem::take</a></i>(&nbsp;)</b> and <b><i><a href="./VXWSem.html#VXWSem::give">VXWSem::give</a></i>(&nbsp;)</b>, the acquisition or relinquishingof a semaphore.<p>Semaphore creation and initialization is handled by the following classes,which inherit the basic operations from <b><a href="./VXWSem.html#top">VXWSem</a></b>:<p>&nbsp;&nbsp;&nbsp;&nbsp;<b>VXWBSem</b>&nbsp;&nbsp;-&nbsp;binary&nbsp;semaphores<br>&nbsp;&nbsp;&nbsp;&nbsp;<b>VXWCSem</b>&nbsp;&nbsp;-&nbsp;counting&nbsp;semaphores<br>&nbsp;&nbsp;&nbsp;&nbsp;<b>VXWMSem</b>&nbsp;&nbsp;-&nbsp;mutual&nbsp;exclusion&nbsp;semaphores<p>Two additional semaphore classes provide semaphores that operateover shared memory (with the optional product VxMP).  These classesalso inherit from <b>VXWSmNameLib</b>; they are described in vxwSmLib.The following are the class names for these shared-memorysemaphores:<p>&nbsp;&nbsp;&nbsp;&nbsp;<b>VXWSmBSem</b>&nbsp;&nbsp;-&nbsp;shared-memory&nbsp;binary&nbsp;semaphores<br>&nbsp;&nbsp;&nbsp;&nbsp;<b>VXWSmCSem</b>&nbsp;&nbsp;-&nbsp;shared-memory&nbsp;counting&nbsp;semaphores<p>Binary semaphores offer the greatest speed and the broadest applicability.<p>The <b><a href="./VXWSem.html#top">VXWSem</a></b> class provides all other semaphore operations, includingroutines for semaphore control, deletion, and information.<p></blockquote><h4>SEMAPHORE CONTROL</h4><blockquote><p>The <b><i><a href="./VXWSem.html#VXWSem::take">VXWSem::take</a></i>(&nbsp;)</b> call acquires a specified semaphore, blocking the callingtask or making the semaphore unavailable.  All semaphore types support atimeout on the <b><i><a href="./VXWSem.html#VXWSem::take">VXWSem::take</a></i>(&nbsp;)</b> operation.  The timeout is specified as thenumber of ticks to remain blocked on the semaphore.  Timeouts of<b>WAIT_FOREVER</b> and <b>NO_WAIT</b> codify common timeouts.  If a <b><i><a href="./VXWSem.html#VXWSem::take">VXWSem::take</a></i>(&nbsp;)</b> timesout, it returns ERROR.  Refer to the library of the specific semaphoretype for the exact behavior of this operation.<p>The <b><i><a href="./VXWSem.html#VXWSem::give">VXWSem::give</a></i>(&nbsp;)</b> call relinquishes a specified semaphore,unblocking a pended task or making the semaphore available.  Referto the library of the specific semaphore type for the exactbehavior of this operation.<p>The <b><i><a href="./VXWSem.html#VXWSem::flush">VXWSem::flush</a></i>(&nbsp;)</b> call may be used to atomically unblock alltasks pended on a semaphore queue; that is, it unblocks all tasksbefore any are allowed to run.  It may be thought of as abroadcast operation in synchronization applications.  The state ofthe semaphore is unchanged by the use of <b><i><a href="./VXWSem.html#VXWSem::flush">VXWSem::flush</a></i>(&nbsp;)</b>; it is notanalogous to <b><i><a href="./VXWSem.html#VXWSem::give">VXWSem::give</a></i>(&nbsp;)</b>.<p></blockquote><h4>SEMAPHORE DELETION</h4><blockquote><p>The <b><i><a href="./VXWSem.html#VXWSem::~VXWSem">VXWSem::~VXWSem</a></i>(&nbsp;)</b> destructor terminates a semaphore anddeallocates any associated memory.  The deletion of a semaphoreunblocks tasks pended on that semaphore; the routines which werepended return ERROR.  Take care when deleting semaphores,particularly those used for mutual exclusion, to avoid deleting asemaphore out from under a task that already has taken (owns) thatsemaphore.  Applications should adopt the protocol of only deletingsemaphores that the deleting task has successfully taken.<p></blockquote><h4>SEMAPHORE INFORMATION</h4><blockquote><p>The <b><i><a href="./VXWSem.html#VXWSem::info">VXWSem::info</a></i>(&nbsp;)</b> call is a useful debugging aid, reporting alltasks blocked on a specified semaphore.  It provides a snapshot ofthe queue at the time of the call, but because semaphores aredynamic, the information may be out of date by the time it isavailable.  As with the current state of the semaphore, use of thequeue of pended tasks should be restricted to debugging uses only.<p></blockquote><h4>INCLUDE FILES</h4><blockquote><p><b>vxwSemLib.h</b><p></blockquote><h4>SEE ALSO</h4><blockquote><p><b><a href="./VXWSem.html#top">VXWSem</a></b>, VXWTask, <b>vxwSmLib</b>,  <i>VxWorks Programmer's Guide: Basic OS</i><p><p><hr><a name="VXWSem::VXWSem"></a><p align=right><a href="rtnIndex.html"><i>Wind Foundation Classes :  Methods</i></a></p></blockquote><h1><i>VXWSem::VXWSem</i>(&nbsp;)</h1> <blockquote></a></blockquote><h4>NAME</h4><blockquote>  <p><strong><i>VXWSem::VXWSem</i>(&nbsp;)</strong> - build semaphore object from semaphore ID</p></blockquote><h4>SYNOPSIS</h4><blockquote><p><pre>VXWSem    (    SEM_ID id    )</pre></blockquote><h4>DESCRIPTION</h4><blockquote><p>Use this constructor to manipulate a semaphore that was not createdusing C++ interfaces.  The argument <i>id</i> is the semaphoreidentifier returned and used by the C interface to the VxWorkssemaphore facility.<p></blockquote><h4>RETURNS</h4><blockquote><p>N/A<p></blockquote><h4>SEE ALSO</h4><blockquote><p><b><a href="./VXWSem.html#top">VXWSem</a></b>, <b><a href="./semLib.html#top">semLib</a></b><hr><a name="VXWSem::~VXWSem"></a><p align=right><a href="rtnIndex.html"><i>Wind Foundation Classes :  Methods</i></a></p></blockquote><h1><i>VXWSem::~VXWSem</i>(&nbsp;)</h1> <blockquote></a></blockquote><h4>NAME</h4><blockquote>  <p><strong><i>VXWSem::~VXWSem</i>(&nbsp;)</strong> - delete a semaphore</p></blockquote><h4>SYNOPSIS</h4><blockquote><p><pre>    virtual ~VXWSem ()</pre></blockquote><h4>DESCRIPTION</h4><blockquote><p>This destructor terminates and deallocates any memory associated with aspecified semaphore.  Any pended tasks unblock and return ERROR.<p></blockquote><h4>WARNING</h4><blockquote><p>Take care when deleting semaphores, particularly those used formutual exclusion, to avoid deleting a semaphore out from under atask that already has taken (owns) that semaphore.  Applicationsshould adopt the protocol of only deleting semaphores that thedeleting task has successfully taken.<p></blockquote><h4>RETURNS</h4><blockquote><p>N/A<p></blockquote><h4>SEE ALSO</h4><blockquote><p><b><a href="./VXWSem.html#top">VXWSem</a></b>, <i>VxWorks Programmer's Guide: Basic OS</i><hr><a name="VXWSem::give"></a><p align=right><a href="rtnIndex.html"><i>Wind Foundation Classes :  Methods</i></a></p></blockquote><h1><i>VXWSem::give</i>(&nbsp;)</h1> <blockquote></a></blockquote><h4>NAME</h4><blockquote>  <p><strong><i>VXWSem::give</i>(&nbsp;)</strong> - give a semaphore</p></blockquote><h4>SYNOPSIS</h4><blockquote><p><pre>    STATUS give ()</pre></blockquote><h4>DESCRIPTION</h4><blockquote><p>This routine performs the give operation on a specified semaphore.Depending on the type of semaphore, the state of the semaphore and of thepending tasks may be affected.  The behavior of <b><i><a href="./VXWSem.html#VXWSem::give">VXWSem::give</a></i>(&nbsp;)</b> isdiscussed fully in the constructor description for the specific semaphore type being used.<p></blockquote><h4>RETURNS</h4><blockquote><p>OK.<p></blockquote><h4>SEE ALSO</h4><blockquote><p><b><a href="./VXWSem.html#top">VXWSem</a></b>, <b><i>VXWCSem::VXWCsem</i>(&nbsp;)</b>, <b><i>VXWBSem::VXWBsem</i>(&nbsp;)</b>, <b><i>VXWMSem::VXWMsem</i>(&nbsp;)</b>,  <i>VxWorks Programmer's Guide: Basic OS</i><hr><a name="VXWSem::take"></a><p align=right><a href="rtnIndex.html"><i>Wind Foundation Classes :  Methods</i></a></p></blockquote><h1><i>VXWSem::take</i>(&nbsp;)</h1> <blockquote></a></blockquote><h4>NAME</h4><blockquote>  <p><strong><i>VXWSem::take</i>(&nbsp;)</strong> - take a semaphore</p></blockquote><h4>SYNOPSIS</h4><blockquote><p><pre>STATUS take    (    int timeout    )</pre></blockquote><h4>DESCRIPTION</h4><blockquote><p>This routine performs the take operation on a specified semaphore.Depending on the type of semaphore, the state of the semaphore andthe calling task may be affected.  The behavior of <b><i><a href="./VXWSem.html#VXWSem::take">VXWSem::take</a></i>(&nbsp;)</b> isdiscussed fully in the constructor description for the specific semaphore type being used.<p>A timeout in ticks may be specified.  If a task times out, <b><i><a href="./VXWSem.html#VXWSem::take">VXWSem::take</a></i>(&nbsp;)</b>returns ERROR.  Timeouts of <b>WAIT_FOREVER</b> and <b>NO_WAIT</b> indicate to waitindefinitely or not to wait at all.<p>When <b><i><a href="./VXWSem.html#VXWSem::take">VXWSem::take</a></i>(&nbsp;)</b> returns due to timeout, it sets the errno toS_objLib_OBJ_TIMEOUT (defined in <b>objLib.h</b>).<p>The <b><i><a href="./VXWSem.html#VXWSem::take">VXWSem::take</a></i>(&nbsp;)</b> routine must not be called from interruptservice routines.<p></blockquote><h4>RETURNS</h4><blockquote><p>OK, or ERROR if the task timed out.<p></blockquote><h4>SEE ALSO</h4><blockquote><p><b><a href="./VXWSem.html#top">VXWSem</a></b>, <b><i>VXWCSem::VXWCsem</i>(&nbsp;)</b>, <b><i>VXWBSem::VXWBsem</i>(&nbsp;)</b>, <b><i>VXWMSem::VXWMsem</i>(&nbsp;)</b>,  <i>VxWorks Programmer's Guide: Basic OS</i><hr><a name="VXWSem::flush"></a><p align=right><a href="rtnIndex.html"><i>Wind Foundation Classes :  Methods</i></a></p></blockquote><h1><i>VXWSem::flush</i>(&nbsp;)</h1> <blockquote></a></blockquote><h4>NAME</h4><blockquote>  <p><strong><i>VXWSem::flush</i>(&nbsp;)</strong> - unblock every task pended on a semaphore</p></blockquote><h4>SYNOPSIS</h4><blockquote><p><pre>    STATUS flush ()</pre></blockquote><h4>DESCRIPTION</h4><blockquote><p>This routine atomically unblocks all tasks pended on a specifiedsemaphore; that is, all tasks are unblocked before any is allowedto run.  The state of the underlying semaphore is unchanged.  Allpended tasks will enter the ready queue before having a chance toexecute.<p>The flush operation is useful as a means of broadcast insynchronization applications.  Its use is illegal for mutual-exclusionsemaphores created with <b><i><a href="./VXWSem.html#VXWMSem::VXWMSem">VXWMSem::VXWMSem</a></i>(&nbsp;)</b>.

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?