pkarashchenko commented on a change in pull request #5171:
URL: https://github.com/apache/incubator-nuttx/pull/5171#discussion_r782912065



##########
File path: sched/semaphore/sem_holder.c
##########
@@ -1035,18 +945,60 @@ void nxsem_release_holder(FAR sem_t *sem)
 {
   FAR struct tcb_s *rtcb = this_task();
   FAR struct semholder_s *pholder;
+  FAR struct semholder_s *candidate;
+  unsigned int total = 0;
 
   /* Find the container for this holder */
 
-  pholder = nxsem_findholder(sem, rtcb);
-  if (pholder != NULL && pholder->counts > 0)
+#if CONFIG_SEM_PREALLOCHOLDERS > 0
+  for (pholder = sem->hhead; pholder; pholder = pholder->flink)
+#else
+  int i;
+
+  /* We have two hard-allocated holder structures in sem_t */
+
+  for (i = 0; i < 2; i++)
+#endif
+    {
+#if CONFIG_SEM_PREALLOCHOLDERS == 0
+      pholder = &sem->holder[i];
+      if (pholder->counts <= 0)
+        {
+          continue;
+        }
+#endif
+
+      DEBUGASSERT(pholder->htcb != NULL);
+
+      if (pholder->htcb == rtcb)
+        {
+          /* Decrement the counts on this holder -- the holder will be freed
+           * later in nxsem_restore_baseprio.
+           */
+
+          pholder->counts--;
+          return;
+        }
+
+      total++;
+      candidate = pholder;
+    }
+
+  /* The current task is not a holder */
+
+  if (total == 1)

Review comment:
       ```suggestion
     if (candidate != NULL)
   ```

##########
File path: sched/semaphore/sem_holder.c
##########
@@ -1035,18 +945,60 @@ void nxsem_release_holder(FAR sem_t *sem)
 {
   FAR struct tcb_s *rtcb = this_task();
   FAR struct semholder_s *pholder;
+  FAR struct semholder_s *candidate;

Review comment:
       ```suggestion
     FAR struct semholder_s *candidate = NULL;
   ```

##########
File path: sched/semaphore/sem_holder.c
##########
@@ -1035,18 +945,60 @@ void nxsem_release_holder(FAR sem_t *sem)
 {
   FAR struct tcb_s *rtcb = this_task();
   FAR struct semholder_s *pholder;
+  FAR struct semholder_s *candidate;
+  unsigned int total = 0;
 
   /* Find the container for this holder */
 
-  pholder = nxsem_findholder(sem, rtcb);
-  if (pholder != NULL && pholder->counts > 0)
+#if CONFIG_SEM_PREALLOCHOLDERS > 0
+  for (pholder = sem->hhead; pholder; pholder = pholder->flink)
+#else
+  int i;
+
+  /* We have two hard-allocated holder structures in sem_t */
+
+  for (i = 0; i < 2; i++)
+#endif
+    {
+#if CONFIG_SEM_PREALLOCHOLDERS == 0
+      pholder = &sem->holder[i];
+      if (pholder->counts <= 0)
+        {
+          continue;
+        }
+#endif
+
+      DEBUGASSERT(pholder->htcb != NULL);
+
+      if (pholder->htcb == rtcb)
+        {
+          /* Decrement the counts on this holder -- the holder will be freed
+           * later in nxsem_restore_baseprio.
+           */
+
+          pholder->counts--;
+          return;
+        }
+
+      total++;

Review comment:
       ```suggestion
         candidate = (total == 0) ? pholder : NULL;
         total++;
   ```




-- 
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


Reply via email to