mirror of
https://github.com/apache/nuttx.git
synced 2026-05-22 22:20:01 +08:00
sem_rw.c: coverity HIS_metric_violation: RETURN
This change consolidates multiple return statements in down_write_trylock() into a single exit point to reduce cyclomatic complexity and comply with MISRA HIS coding standards for safety-critical embedded systems. Signed-off-by: hujun5 <hujun5@xiaomi.com>
This commit is contained in:
@@ -205,23 +205,26 @@ out:
|
||||
int down_write_trylock(FAR rw_semaphore_t *rwsem)
|
||||
{
|
||||
pid_t tid = _SCHED_GETTID();
|
||||
int ret = 1;
|
||||
|
||||
nxmutex_lock(&rwsem->protected);
|
||||
|
||||
if (rwsem->reader > 0 || (rwsem->writer > 0 && tid != rwsem->holder))
|
||||
{
|
||||
nxmutex_unlock(&rwsem->protected);
|
||||
return 0;
|
||||
ret = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* The check passes, then we just need the writer reference + 1 */
|
||||
|
||||
rwsem->writer++;
|
||||
rwsem->holder = tid;
|
||||
|
||||
nxmutex_unlock(&rwsem->protected);
|
||||
}
|
||||
|
||||
/* The check passes, then we just need the writer reference + 1 */
|
||||
|
||||
rwsem->writer++;
|
||||
rwsem->holder = tid;
|
||||
|
||||
nxmutex_unlock(&rwsem->protected);
|
||||
|
||||
return 1;
|
||||
return ret;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
|
||||
Reference in New Issue
Block a user