v xworks vxTas函数源码
时间: 2024-05-12 20:14:08 浏览: 9
vxTas 函数源码如下:
```c
/*******************************************************************************
*
* vxTas - lock a semaphore (VxWorks 5.x version)
*
* This routine locks a semaphore.
*
* If the semaphore is already locked, vxTas() returns a nonzero value.
* If the semaphore is unlocked, vxTas() locks the semaphore and returns zero.
*
* NOTE
* This routine is not appropriate for use on multiprocessor systems.
* On a uniprocessor system, it is more efficient than semTake(), since
* it avoids the overhead of task rescheduling.
*
* RETURNS: TRUE, or FALSE if the semaphore is already locked.
*
* SEE ALSO: semTake()
*/
int vxTas
(
FAST SEM_ID semId /* semaphore to lock */
)
{
int oldIntLev; /* old interrupt level mask */
BOOL status; /* lock status */
oldIntLev = intLock (); /* LOCK INTERRUPTS */
if (semId->semCount == 0)/* if already locked */
status = TRUE; /* indicate failure */
else /* else lock it */
{
semId->semCount = 0; /* take the semaphore */
semId->semOwner = taskIdCurrent; /* record owner */
status = FALSE; /* indicate success */
}
intUnlock (oldIntLev); /* UNLOCK INTERRUPTS */
return (status); /* return the status */
}
```
注:这是 VxWorks 5.x 版本的 vxTas 函数源码,不同版本的 VxWorks 可能会有不同的实现。