📄 sempxlib.html
字号:
ENOENT<br> - the named semaphore does not exist and <b>O_CREAT</b> is not set.<br> ENOSPC<br> - the semaphore could not be initialized due to resource constraints.<p></blockquote><h4>SEE ALSO</h4><blockquote><p><b><a href="./semPxLib.html#top">semPxLib</a></b>, <b><a href="./semPxLib.html#sem_unlink">sem_unlink</a>( )</b><p><hr><a name="sem_close"></a><p align=right><a href="rtnIndex.htm"><i>OS Libraries : Routines</i></a></p></blockquote><h1>sem_close( )</h1> <blockquote></a></blockquote><h4>NAME</h4><blockquote> <p><strong>sem_close( )</strong> - close a named semaphore (POSIX)</p></blockquote><h4>SYNOPSIS</h4><blockquote><p><pre>int sem_close ( sem_t * sem /* semaphore descriptor */ )</pre></blockquote><h4>DESCRIPTION</h4><blockquote><p>This routine is called to indicate that the calling task is finished withthe specified named semaphore, <i>sem</i>. Do not call this routinewith an unnamed semaphore (i.e., one created by <b><a href="./semPxLib.html#sem_init">sem_init</a>( )</b>); theeffects are undefined. The <b><a href="./semPxLib.html#sem_close">sem_close</a>( )</b> call deallocates any systemresources allocated by the system for use by this task for this semaphore.<p>If the semaphore has not been removed with a call to <b><a href="./semPxLib.html#sem_unlink">sem_unlink</a>( )</b>,then <b><a href="./semPxLib.html#sem_close">sem_close</a>( )</b> has no effect on the state of the semaphore.However, if the semaphore has been unlinked, the semaphore vanisheswhen the last task closes it.<p></blockquote><h4>WARNING</h4><blockquote><p>Take care to avoid risking the deletion of a semaphore that anothertask has already locked. Applications should only close semaphoresthat the closing task has opened.<p></blockquote><h4>RETURNS</h4><blockquote><p>0 (OK), or -1 (ERROR) if unsuccessful.<p></blockquote><h4>ERRNO</h4><blockquote><p><p> EINVAL<br> - invalid semaphore descriptor.<p></blockquote><h4>SEE ALSO</h4><blockquote><p><b><a href="./semPxLib.html#top">semPxLib</a></b>, <b><a href="./semPxLib.html#sem_unlink">sem_unlink</a>( )</b>, <b><a href="./semPxLib.html#sem_open">sem_open</a>( )</b>, <b><a href="./semPxLib.html#sem_init">sem_init</a>( )</b><hr><a name="sem_unlink"></a><p align=right><a href="rtnIndex.htm"><i>OS Libraries : Routines</i></a></p></blockquote><h1>sem_unlink( )</h1> <blockquote></a></blockquote><h4>NAME</h4><blockquote> <p><strong>sem_unlink( )</strong> - remove a named semaphore (POSIX)</p></blockquote><h4>SYNOPSIS</h4><blockquote><p><pre>int sem_unlink ( const char * name /* semaphore name */ )</pre></blockquote><h4>DESCRIPTION</h4><blockquote><p>This routine removes the string <i>name</i> from the semaphore nametable, and marks the corresponding semaphore for destruction. Anunlinked semaphore is destroyed when the last task closes it with<b><a href="./semPxLib.html#sem_close">sem_close</a>( )</b>. After a particular name is removed from the table,calls to <b><a href="./semPxLib.html#sem_open">sem_open</a>( )</b> using the same name cannot connect to the samesemaphore, even if other tasks are still using it. Instead, suchcalls refer to a new semaphore with the same name.<p></blockquote><h4>RETURNS</h4><blockquote><p>0 (OK), or -1 (ERROR) if unsuccessful.<p></blockquote><h4>ERRNO</h4><blockquote><p><p> ENAMETOOLONG<br> - semaphore name too long.<br> ENOENT<br> - named semaphore does not exist.<p></blockquote><h4>SEE ALSO</h4><blockquote><p><b><a href="./semPxLib.html#top">semPxLib</a></b>, <b><a href="./semPxLib.html#sem_open">sem_open</a>( )</b>, <b><a href="./semPxLib.html#sem_close">sem_close</a>( )</b><p><hr><a name="sem_wait"></a><p align=right><a href="rtnIndex.htm"><i>OS Libraries : Routines</i></a></p></blockquote><h1>sem_wait( )</h1> <blockquote></a></blockquote><h4>NAME</h4><blockquote> <p><strong>sem_wait( )</strong> - lock (take) a semaphore, blocking if not available (POSIX)</p></blockquote><h4>SYNOPSIS</h4><blockquote><p><pre>int sem_wait ( sem_t * sem /* semaphore descriptor */ )</pre></blockquote><h4>DESCRIPTION</h4><blockquote><p>This routine locks the semaphore referenced by <i>sem</i> by performing thesemaphore lock operation on that semaphore. If the semaphore value iscurrently zero, the calling task will not return from the callto <b><a href="./semPxLib.html#sem_wait">sem_wait</a>( )</b> until it either locks the semaphore or the call isinterrupted by a signal. <p>On return, the state of the semaphore is locked and will remain lockeduntil <b><a href="./semPxLib.html#sem_post">sem_post</a>( )</b> is executed and returns successfully.<p>Deadlock detection is not implemented.<p>Note that the POSIX term <i>lock</i> corresponds to the term <i>take</i> usedin other VxWorks documentation regarding semaphores.<p></blockquote><h4>RETURNS</h4><blockquote><p>0 (OK), or -1 (ERROR) if unsuccessful.<p></blockquote><h4>ERRNO</h4><blockquote><p><p> EINVAL<br> - invalid semaphore descriptor, or semaphore destroyed while task waiting.<p></blockquote><h4>SEE ALSO</h4><blockquote><p><b><a href="./semPxLib.html#top">semPxLib</a></b>, <b><a href="./semPxLib.html#sem_trywait">sem_trywait</a>( )</b>, <b><a href="./semPxLib.html#sem_post">sem_post</a>( )</b><hr><a name="sem_trywait"></a><p align=right><a href="rtnIndex.htm"><i>OS Libraries : Routines</i></a></p></blockquote><h1>sem_trywait( )</h1> <blockquote></a></blockquote><h4>NAME</h4><blockquote> <p><strong>sem_trywait( )</strong> - lock (take) a semaphore, returning error if unavailable (POSIX)</p></blockquote><h4>SYNOPSIS</h4><blockquote><p><pre>int sem_trywait ( sem_t * sem /* semaphore descriptor */ )</pre></blockquote><h4>DESCRIPTION</h4><blockquote><p>This routine locks the semaphore referenced by <i>sem</i> only if the semaphore is currently not locked; that is, if the semaphore value iscurrently positive. Otherwise, it does not lock the semaphore.In either case, this call returns immediately without blocking.<p>Upon return, the state of the semaphore is always locked (either as a result of this call or by a previous <b><a href="./semPxLib.html#sem_wait">sem_wait</a>( )</b> or <b><a href="./semPxLib.html#sem_trywait">sem_trywait</a>( )</b>).The semaphore will remain locked until <b><a href="./semPxLib.html#sem_post">sem_post</a>( )</b> is executed and returnssuccessfully.<p>Deadlock detection is not implemented.<p>Note that the POSIX term <i>lock</i> corresponds to the term <i>take</i> usedin other VxWorks semaphore documentation.<p></blockquote><h4>RETURNS</h4><blockquote><p>0 (OK), or -1 (ERROR) if unsuccessful.<p></blockquote><h4>ERRNO</h4><blockquote><p><p> EAGAIN<br> - semaphore is already locked.<br> EINVAL<br> - invalid semaphore descriptor.<p></blockquote><h4>SEE ALSO</h4><blockquote><p><b><a href="./semPxLib.html#top">semPxLib</a></b>, <b><a href="./semPxLib.html#sem_wait">sem_wait</a>( )</b>, <b><a href="./semPxLib.html#sem_post">sem_post</a>( )</b><hr><a name="sem_post"></a><p align=right><a href="rtnIndex.htm"><i>OS Libraries : Routines</i></a></p></blockquote><h1>sem_post( )</h1> <blockquote></a></blockquote><h4>NAME</h4><blockquote> <p><strong>sem_post( )</strong> - unlock (give) a semaphore (POSIX)</p></blockquote><h4>SYNOPSIS</h4><blockquote><p><pre>int sem_post ( sem_t * sem /* semaphore descriptor */ )</pre></blockquote><h4>DESCRIPTION</h4><blockquote><p>This routine unlocks the semaphore referenced by <i>sem</i> by performingthe semaphore unlock operation on that semaphore.<p>If the semaphore value resulting from the operation is positive, then notasks were blocked waiting for the semaphore to become unlocked;the semaphore value is simply incremented.<p>If the value of the semaphore resulting from this semaphore is zero, thenone of the tasks blocked waiting for the semaphore willreturn successfully from its call to <b><a href="./semPxLib.html#sem_wait">sem_wait</a>( )</b>. <p></blockquote><h4>NOTE</h4><blockquote><p>The <b>_POSIX_PRIORITY_SCHEDULING</b> functionality is not yet supported.<p>Note that the POSIX terms <i>unlock</i> and <i>post</i> correspond tothe term <i>give</i> used in other VxWorks semaphore documentation.<p></blockquote><h4>RETURNS</h4><blockquote><p>0 (OK), or -1 (ERROR) if unsuccessful.<p></blockquote><h4>ERRNO</h4><blockquote><p><p> EINVAL<br> - invalid semaphore descriptor.<p></blockquote><h4>SEE ALSO</h4><blockquote><p><b><a href="./semPxLib.html#top">semPxLib</a></b>, <b><a href="./semPxLib.html#sem_wait">sem_wait</a>( )</b>, <b><a href="./semPxLib.html#sem_trywait">sem_trywait</a>( )</b><hr><a name="sem_getvalue"></a><p align=right><a href="rtnIndex.htm"><i>OS Libraries : Routines</i></a></p></blockquote><h1>sem_getvalue( )</h1> <blockquote></a></blockquote><h4>NAME</h4><blockquote> <p><strong>sem_getvalue( )</strong> - get the value of a semaphore (POSIX)</p></blockquote><h4>SYNOPSIS</h4><blockquote><p><pre>int sem_getvalue ( sem_t * sem, /* semaphore descriptor */ int * sval /* buffer by which the value is returned */ )</pre></blockquote><h4>DESCRIPTION</h4><blockquote><p>This routine updates the location referenced by the <i>sval</i> argumentto have the value of the semaphore referenced by <i>sem</i> without affectingthe state of the semaphore. The updated value represents an actual semaphorevalue that occurred at some unspecified time during the call, but maynot be the actual value of the semaphore when it is returned to the calling task.<p>If <i>sem</i> is locked, the value returned by <b><a href="./semPxLib.html#sem_getvalue">sem_getvalue</a>( )</b> will either be zero or a negative number whose absolute value represents the number of tasks waiting for the semaphore at some unspecified time during the call.<p></blockquote><h4>RETURNS</h4><blockquote><p>0 (OK), or -1 (ERROR) if unsuccessful.<p></blockquote><h4>ERRNO</h4><blockquote><p><p> EINVAL<br> - invalid semaphore descriptor.<p></blockquote><h4>SEE ALSO</h4><blockquote><p><b><a href="./semPxLib.html#top">semPxLib</a></b>, <b><a href="./semPxLib.html#sem_post">sem_post</a>( )</b>, <b><a href="./semPxLib.html#sem_trywait">sem_trywait</a>( )</b>, <b><a href="./semPxLib.html#sem_trywait">sem_trywait</a>( )</b></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -