pthread: move pthread_cond to userspace

Move pthread condition variable implementation from kernel (sched/pthread)
to userspace library (libs/libc/pthread). This allows userspace to handle
condition variable operations directly, reducing syscall overhead and
improving performance for pthread applications.

Signed-off-by: hujun5 <hujun5@xiaomi.com>
This commit is contained in:
hujun5
2025-06-19 15:19:35 +08:00
committed by GUIDINGLI
parent ae85903f71
commit 217e685beb
25 changed files with 209 additions and 172 deletions
+72
View File
@@ -200,3 +200,75 @@ int nxsem_wait(FAR sem_t *sem)
return nxsem_wait_slow(sem);
}
/****************************************************************************
* Name: nxsem_wait_uninterruptible
*
* Description:
* This function is wrapped version of nxsem_wait(), which is
* uninterruptible and convenient for use.
*
* Parameters:
* sem - Semaphore descriptor.
*
* Return Value:
* Zero(OK) - On success
* EINVAL - Invalid attempt to get the semaphore
* ECANCELED - May be returned if the thread is canceled while waiting.
*
****************************************************************************/
int nxsem_wait_uninterruptible(FAR sem_t *sem)
{
int ret;
do
{
/* Take the semaphore (perhaps waiting) */
ret = nxsem_wait(sem);
}
while (ret == -EINTR);
return ret;
}
/****************************************************************************
* Name: nxsem_clockwait_uninterruptible
*
* Description:
* This function is wrapped version of nxsem_clockwait(), which is
* uninterruptible and convenient for use.
*
* Input Parameters:
* sem - Semaphore object
* clockid - The timing source to use in the conversion
* abstime - The absolute time to wait until a timeout is declared.
*
* Returned Value:
* EINVAL The sem argument does not refer to a valid semaphore. Or the
* thread would have blocked, and the abstime parameter specified
* a nanoseconds field value less than zero or greater than or
* equal to 1000 million.
* ETIMEDOUT The semaphore could not be locked before the specified timeout
* expired.
* EDEADLK A deadlock condition was detected.
* ECANCELED May be returned if the thread is canceled while waiting.
*
****************************************************************************/
int nxsem_clockwait_uninterruptible(FAR sem_t *sem, clockid_t clockid,
FAR const struct timespec *abstime)
{
int ret;
do
{
/* Take the semaphore (perhaps waiting) */
ret = nxsem_clockwait(sem, clockid, abstime);
}
while (ret == -EINTR);
return ret;
}