sem_rw.c: coverity: HIS_metric_violation(HIS_GOTO)

This change replaces goto-based control flow with structured if-else blocks
in the down_read() function to comply with MISRA HIS coding standards while
maintaining identical functional behavior.

Signed-off-by: hujun5 <hujun5@xiaomi.com>
This commit is contained in:
hujun5
2025-08-14 19:25:21 +08:00
committed by Donny(董九柱)
parent 3200185665
commit 437cdfac8d
+15 -15
View File
@@ -123,25 +123,25 @@ void down_read(FAR rw_semaphore_t *rwsem)
if (rwsem->holder == _SCHED_GETTID())
{
rwsem->writer++;
goto out;
}
while (rwsem->writer > 0)
else
{
rwsem->waiter++;
nxmutex_unlock(&rwsem->protected);
nxsem_wait(&rwsem->waiting);
nxmutex_lock(&rwsem->protected);
rwsem->waiter--;
while (rwsem->writer > 0)
{
rwsem->waiter++;
nxmutex_unlock(&rwsem->protected);
nxsem_wait(&rwsem->waiting);
nxmutex_lock(&rwsem->protected);
rwsem->waiter--;
}
/* In a scenario where there is no write lock, we just need to make the
* read base +1.
*/
rwsem->reader++;
}
/* In a scenario where there is no write lock, we just need to make the
* read base +1.
*/
rwsem->reader++;
out:
nxmutex_unlock(&rwsem->protected);
}