xiaoxiang781216 commented on code in PR #14578: URL: https://github.com/apache/nuttx/pull/14578#discussion_r1926505855
########## sched/sched/sched_unlock.c: ########## @@ -53,48 +53,25 @@ * ****************************************************************************/ -#ifdef CONFIG_SMP - -int sched_unlock(void) +void sched_unlock(void) { - FAR struct tcb_s *rtcb; - - /* This operation is safe because the scheduler is locked and no context - * switch may occur. - */ - - rtcb = this_task(); - - /* Check for some special cases: (1) rtcb may be NULL only during - * early boot-up phases, and (2) sched_unlock() should have no - * effect if called from the interrupt level. - */ + /* sched_unlock should have no effect if called from the interrupt level. */ - if (rtcb != NULL && !up_interrupt_context()) + if (!up_interrupt_context()) { - /* Prevent context switches throughout the following. */ - - irqstate_t flags = enter_critical_section(); - int cpu = this_cpu(); - - DEBUGASSERT(rtcb->lockcount > 0); - - /* Decrement the preemption lock counter */ + FAR struct tcb_s *rtcb = this_task(); - rtcb->lockcount--; + DEBUGASSERT(rtcb == NULL || rtcb->lockcount > 0); - /* Check if the lock counter has decremented to zero. If so, - * then pre-emption has been re-enabled. - */ + /* rtcb may be NULL only during early boot-up phases */ - if (rtcb->lockcount <= 0) + if (rtcb != NULL && rtcb->lockcount-- == 1) Review Comment: if (rtcb != NULL && --rtcb->lockcount == 0) ########## sched/sched/sched_unlock.c: ########## @@ -53,48 +53,25 @@ * ****************************************************************************/ -#ifdef CONFIG_SMP - -int sched_unlock(void) +void sched_unlock(void) { - FAR struct tcb_s *rtcb; - - /* This operation is safe because the scheduler is locked and no context - * switch may occur. - */ - - rtcb = this_task(); - - /* Check for some special cases: (1) rtcb may be NULL only during - * early boot-up phases, and (2) sched_unlock() should have no - * effect if called from the interrupt level. - */ + /* sched_unlock should have no effect if called from the interrupt level. */ - if (rtcb != NULL && !up_interrupt_context()) + if (!up_interrupt_context()) { - /* Prevent context switches throughout the following. */ - - irqstate_t flags = enter_critical_section(); - int cpu = this_cpu(); - - DEBUGASSERT(rtcb->lockcount > 0); - - /* Decrement the preemption lock counter */ + FAR struct tcb_s *rtcb = this_task(); - rtcb->lockcount--; + DEBUGASSERT(rtcb == NULL || rtcb->lockcount > 0); - /* Check if the lock counter has decremented to zero. If so, - * then pre-emption has been re-enabled. - */ + /* rtcb may be NULL only during early boot-up phases */ - if (rtcb->lockcount <= 0) + if (rtcb != NULL && rtcb->lockcount-- == 1) { - /* Note that we no longer have pre-emption disabled. */ + irqstate_t flags = enter_critical_section_wo_note(); -#if CONFIG_SCHED_CRITMONITOR_MAXTIME_PREEMPTION >= 0 +#if (CONFIG_SCHED_CRITMONITOR_MAXTIME_PREEMPTION >= 0) || \ Review Comment: remove #if/#endif ########## sched/sched/sched_unlock.c: ########## @@ -288,30 +137,23 @@ int sched_unlock(void) if ((rtcb->flags & TCB_FLAG_POLICY_MASK) == TCB_FLAG_SCHED_SPORADIC && rtcb->timeslice < 0) { - /* Yes.. that is the situation. Force the low-priority state - * now - */ - - nxsched_sporadic_lowpriority(rtcb); Review Comment: why remove ########## sched/sched/sched_unlock.c: ########## @@ -53,48 +53,25 @@ * ****************************************************************************/ -#ifdef CONFIG_SMP - -int sched_unlock(void) +void sched_unlock(void) { - FAR struct tcb_s *rtcb; - - /* This operation is safe because the scheduler is locked and no context - * switch may occur. - */ - - rtcb = this_task(); - - /* Check for some special cases: (1) rtcb may be NULL only during - * early boot-up phases, and (2) sched_unlock() should have no - * effect if called from the interrupt level. - */ + /* sched_unlock should have no effect if called from the interrupt level. */ - if (rtcb != NULL && !up_interrupt_context()) + if (!up_interrupt_context()) { - /* Prevent context switches throughout the following. */ - - irqstate_t flags = enter_critical_section(); - int cpu = this_cpu(); - - DEBUGASSERT(rtcb->lockcount > 0); - - /* Decrement the preemption lock counter */ + FAR struct tcb_s *rtcb = this_task(); - rtcb->lockcount--; + DEBUGASSERT(rtcb == NULL || rtcb->lockcount > 0); - /* Check if the lock counter has decremented to zero. If so, Review Comment: keep ########## sched/sched/sched_unlock.c: ########## @@ -53,48 +53,25 @@ * ****************************************************************************/ -#ifdef CONFIG_SMP - -int sched_unlock(void) +void sched_unlock(void) { - FAR struct tcb_s *rtcb; - - /* This operation is safe because the scheduler is locked and no context - * switch may occur. - */ - - rtcb = this_task(); - - /* Check for some special cases: (1) rtcb may be NULL only during - * early boot-up phases, and (2) sched_unlock() should have no - * effect if called from the interrupt level. - */ + /* sched_unlock should have no effect if called from the interrupt level. */ - if (rtcb != NULL && !up_interrupt_context()) + if (!up_interrupt_context()) { - /* Prevent context switches throughout the following. */ - - irqstate_t flags = enter_critical_section(); - int cpu = this_cpu(); - - DEBUGASSERT(rtcb->lockcount > 0); - - /* Decrement the preemption lock counter */ + FAR struct tcb_s *rtcb = this_task(); - rtcb->lockcount--; + DEBUGASSERT(rtcb == NULL || rtcb->lockcount > 0); - /* Check if the lock counter has decremented to zero. If so, - * then pre-emption has been re-enabled. - */ + /* rtcb may be NULL only during early boot-up phases */ - if (rtcb->lockcount <= 0) + if (rtcb != NULL && rtcb->lockcount-- == 1) { - /* Note that we no longer have pre-emption disabled. */ Review Comment: move after line 71 -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@nuttx.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org