Skip to content

Commit 4127cc1

Browse files
committed
[Kernel] Move the ++/-- operator outside of condition.
1 parent 6e89f70 commit 4127cc1

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/cpu.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,16 @@ rt_base_t rt_cpus_lock(void)
4242
pcpu = rt_cpu_self();
4343
if (pcpu->current_thread != RT_NULL)
4444
{
45-
if (pcpu->current_thread->cpus_lock_nest++ == 0)
45+
register rt_uint16_t lock_nest = pcpu->current_thread->cpus_lock_nest;
46+
47+
pcpu->current_thread->cpus_lock_nest++;
48+
if (lock_nest == 0)
4649
{
4750
pcpu->current_thread->scheduler_lock_nest++;
4851
rt_hw_spin_lock(&_cpus_lock);
4952
}
5053
}
54+
5155
return level;
5256
}
5357
RTM_EXPORT(rt_cpus_lock);
@@ -61,7 +65,9 @@ void rt_cpus_unlock(rt_base_t level)
6165

6266
if (pcpu->current_thread != RT_NULL)
6367
{
64-
if (--pcpu->current_thread->cpus_lock_nest == 0)
68+
pcpu->current_thread->cpus_lock_nest--;
69+
70+
if (pcpu->current_thread->cpus_lock_nest == 0)
6571
{
6672
pcpu->current_thread->scheduler_lock_nest--;
6773
rt_hw_spin_unlock(&_cpus_lock);

0 commit comments

Comments
 (0)