pkarashchenko commented on code in PR #6318: URL: https://github.com/apache/incubator-nuttx/pull/6318#discussion_r978966096
########## sched/semaphore/sem_holder.c: ########## @@ -489,117 +410,55 @@ static int nxsem_restoreholderprio(FAR struct semholder_s *pholder, nxsem_freeholder(sem, pholder); } + /* We attempt to restore thread priority to its base priority. If + * there is any thread with the higher priority waiting for the + * semaphore held by htcb then this value will be overwritten. + */ + + hpriority = htcb->boost_priority > htcb->base_priority ? + htcb->boost_priority : htcb->base_priority; + /* Was the priority of the holder thread boosted? If so, then drop its * priority back to the correct level. What is the correct level? */ - if (htcb->sched_priority != htcb->base_priority) + if (htcb->sched_priority != hpriority) { -#if CONFIG_SEM_NNESTPRIO > 0 - /* Are there other, pending priority levels to revert to? */ - - if (htcb->npend_reprio < 1) - { - /* No... the holder thread has only been boosted once. - * npend_reprio should be 0 and the boosted priority should be the - * priority of the task that just got the semaphore - * (stcb->sched_priority) - * - * That latter assumption may not be true if the stcb's priority - * was also boosted so that it no longer matches the htcb's - * sched_priority. Or if CONFIG_SEM_NNESTPRIO is too small (so - * that we do not have a proper record of the reprioritizations). - */ - - DEBUGASSERT(/* htcb->sched_priority == stcb->sched_priority && */ - htcb->npend_reprio == 0); - - /* Reset the holder's priority back to the base priority. */ - - nxsched_reprioritize(htcb, htcb->base_priority); - } - - /* There are multiple pending priority levels. The holder thread's - * "boosted" priority could greater than or equal to - * "stcb->sched_priority" (it could be greater if its priority was - * boosted because it also holds another semaphore). + /* Try to find the highest priority across all the threads that are + * waiting for any semaphore held by htcb. Skip search if htcb does + * not hold any semaphore. */ - else if (htcb->sched_priority <= stcb->sched_priority) + if (htcb->holdsem != NULL) { - /* The holder thread has been boosted to the same priority as the - * waiter thread that just received the count. We will simply - * reprioritize to the next highest priority that we have in - * rpriority. - */ + FAR struct tcb_s *stcb; - /* Find the highest pending priority and remove it from the list */ - - for (i = 1, j = 0; i < htcb->npend_reprio; i++) + for (stcb = (FAR struct tcb_s *)g_waitingforsemaphore.head; + stcb != NULL && stcb->sched_priority > hpriority; + stcb = stcb->flink) { - if (htcb->pend_reprios[i] > htcb->pend_reprios[j]) - { - j = i; - } - } + FAR sem_t *sem = stcb->waitobj; Review Comment: fixed -- 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