mirror of
https://github.com/apache/nuttx.git
synced 2026-05-27 03:05:40 +08:00
sem_rw.c: down_read_trylock coverity HIS_metric_violation: RETURN
This change consolidates multiple return statements in down_read_trylock() into a single exit point and replaces goto with if-else structure to reduce cyclomatic complexity and comply with MISRA HIS coding standards. Signed-off-by: hujun5 <hujun5@xiaomi.com>
This commit is contained in:
+13
-14
@@ -65,6 +65,8 @@ static inline void up_wait(FAR rw_semaphore_t *rwsem)
|
|||||||
|
|
||||||
int down_read_trylock(FAR rw_semaphore_t *rwsem)
|
int down_read_trylock(FAR rw_semaphore_t *rwsem)
|
||||||
{
|
{
|
||||||
|
int ret = 1;
|
||||||
|
|
||||||
nxmutex_lock(&rwsem->protected);
|
nxmutex_lock(&rwsem->protected);
|
||||||
|
|
||||||
/* if the write lock is already held by oneself and since the write lock
|
/* if the write lock is already held by oneself and since the write lock
|
||||||
@@ -75,25 +77,22 @@ int down_read_trylock(FAR rw_semaphore_t *rwsem)
|
|||||||
if (rwsem->holder == _SCHED_GETTID())
|
if (rwsem->holder == _SCHED_GETTID())
|
||||||
{
|
{
|
||||||
rwsem->writer++;
|
rwsem->writer++;
|
||||||
goto out;
|
|
||||||
}
|
}
|
||||||
|
else if (rwsem->writer > 0)
|
||||||
if (rwsem->writer > 0)
|
|
||||||
{
|
{
|
||||||
nxmutex_unlock(&rwsem->protected);
|
ret = 0;
|
||||||
return 0;
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* 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);
|
nxmutex_unlock(&rwsem->protected);
|
||||||
|
return ret;
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
|
|||||||
Reference in New Issue
Block a user