feat: m核新增posix接口sem_getvalue

【背景】
 m核新增posix接口适配

【修改方案】
 接口新增sem_getvalue,并在内核适配相应接口

【影响】
 无

 re #I3WW8S

 Signed-off-by: x_xiny <1301913191@qq.com>
 Change-Id: I65a4baa242aaedc2fec9b6ed705dbb1ddb6e70c9

Change-Id: Id4c38a5dd4ac4e90f1bd032a39dcb97ce29de5f9
This commit is contained in:
x_xiny 2021-06-22 10:55:23 +08:00
parent 9fc34614d1
commit 8649b14591
3 changed files with 32 additions and 0 deletions

View File

@ -186,3 +186,21 @@ int sem_timedwait(sem_t *sem, const struct timespec *timeout)
return 0;
}
int sem_getvalue(sem_t *sem, int *currVal)
{
UINT32 ret;
if ((sem == NULL) || (currVal == NULL)) {
errno = EINVAL;
return -1;
}
ret = LOS_SemGetValue(sem->s_handle, currVal);
if (ret) {
errno = EINVAL;
return -1;
}
return LOS_OK;
}

View File

@ -285,6 +285,8 @@ extern UINT32 LOS_SemPend(UINT32 semHandle, UINT32 timeout);
*/
extern UINT32 LOS_SemPost(UINT32 semHandle);
extern UINT32 LOS_SemGetValue(UINT32 semHandle, INT32 *currVal);
/**
* @ingroup los_sem
* Semaphore control structure.

View File

@ -312,4 +312,16 @@ LITE_OS_SEC_TEXT UINT32 LOS_SemPost(UINT32 semHandle)
return LOS_OK;
}
LITE_OS_SEC_TEXT UINT32 LOS_SemGetValue(UINT32 semHandle, INT32 *currVal)
{
LosSemCB *sem = GET_SEM(semHandle);
if (semHandle >= (UINT32)LOSCFG_BASE_IPC_SEM_LIMIT) {
OS_RETURN_ERROR(LOS_ERRNO_SEM_INVALID);
}
*currVal = sem->semCount;
return 0;
}
#endif /* (LOSCFG_BASE_IPC_SEM == 1) */