From 3a4e465bc318cf0eefe112679ed3c13b0a10d69f Mon Sep 17 00:00:00 2001 From: Jiuzhu Dong Date: Mon, 18 Jan 2021 20:09:25 +0800 Subject: [PATCH] pthread/cond: enhance pthread_cond_destroy MIRTOS-115 follow: https://pubs.opengroup.org/onlinepubs/009695399/functions/pthread_cond_destroy.html Change-Id: If645120cbac72975671768159d03f211c4940cca Signed-off-by: Jiuzhu Dong --- libs/libc/pthread/pthread_conddestroy.c | 26 +++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/libs/libc/pthread/pthread_conddestroy.c b/libs/libc/pthread/pthread_conddestroy.c index 53c7f907246..67ceb8d064c 100644 --- a/libs/libc/pthread/pthread_conddestroy.c +++ b/libs/libc/pthread/pthread_conddestroy.c @@ -57,7 +57,10 @@ * None * * Returned Value: - * None + * OK (0) on success; a (non-negated) errno value on failure. The errno + * variable is not set. EBUSY is returned when the implementation has + * detected an attempt to destroy the object referenced by cond while + * it is referenced. EINVAL is returned when cond is invalid. * * Assumptions: * @@ -66,6 +69,7 @@ int pthread_cond_destroy(FAR pthread_cond_t *cond) { int ret = OK; + int sval = 0; sinfo("cond=0x%p\n", cond); @@ -75,10 +79,24 @@ int pthread_cond_destroy(FAR pthread_cond_t *cond) } /* Destroy the semaphore contained in the structure */ - - else if (sem_destroy((FAR sem_t *)&cond->sem) != OK) + else { - ret = EINVAL; + ret = sem_get_value(&cond->sem, &sval); + if (ret < 0) + { + ret = -ret; + } + else + { + if (sval < 0) + { + ret = EBUSY; + } + else if (sem_destroy(&cond->sem) != OK) + { + ret = EINVAL; + } + } } sinfo("Returning %d\n", ret);