diff --git a/sched/sched/sched_smp.c b/sched/sched/sched_smp.c index f43cb08ac7..94aab39130 100644 --- a/sched/sched/sched_smp.c +++ b/sched/sched/sched_smp.c @@ -137,6 +137,14 @@ int nxsched_smp_call_handler(int irq, FAR void *context, ret = call_data->func(call_data->arg); flags = enter_critical_section(); + if (spin_is_locked(&call_data->lock)) + { + if (--call_data->refcount == 0) + { + spin_unlock(&call_data->lock); + } + } + if (call_data->cookie != NULL) { if (ret < 0) @@ -146,14 +154,6 @@ int nxsched_smp_call_handler(int irq, FAR void *context, nxsem_post(&call_data->cookie->sem); } - - if (spin_is_locked(&call_data->lock)) - { - if (--call_data->refcount == 0) - { - spin_unlock(&call_data->lock); - } - } } up_cpu_paused_restore();