wangchdo commented on code in PR #17642:
URL: https://github.com/apache/nuttx/pull/17642#discussion_r2663639139


##########
sched/hrtimer/hrtimer_cancel.c:
##########
@@ -83,59 +117,29 @@
 int hrtimer_cancel(FAR hrtimer_t *hrtimer)
 {
   FAR hrtimer_t *first;
-  irqstate_t     flags;
-  int            ret = OK;
+  irqstate_t flags;
+  int ret = OK;
 
   DEBUGASSERT(hrtimer != NULL);
 
   /* Enter critical section to protect the hrtimer tree and state */
 
   flags = spin_lock_irqsave(&g_hrtimer_spinlock);
 
-  /* Capture the current earliest timer before any modification */
-
-  first = (FAR hrtimer_t *)RB_MIN(hrtimer_tree_s, &g_hrtimer_tree);
-
-  switch (hrtimer->state)
+  if (hrtimer_is_armed(hrtimer))
     {
-      case HRTIMER_STATE_ARMED:
-        {
-          /* Remove the timer from the active tree */
-
-          RB_REMOVE(hrtimer_tree_s, &g_hrtimer_tree, &hrtimer->node);
-          hrtimer->state = HRTIMER_STATE_INACTIVE;
-          break;
-        }
+      hrtimer_remove(hrtimer);
+    }
 
-      case HRTIMER_STATE_RUNNING:
-        {
-          /* The callback is currently executing.
-           *
-           * Mark the timer as canceled so it will not be re-armed or
-           * executed again.  The running callback is allowed to complete.
-           *
-           * NOTE: The timer node is expected to have already been removed
-           *       from the tree when the callback started executing.
-           */
-
-          hrtimer->state = HRTIMER_STATE_CANCELED;
-          break;
-        }
+  /* Mark the timer as cancelled */
 
-      case HRTIMER_STATE_INACTIVE:
-      case HRTIMER_STATE_CANCELED:
-      default:
-        {
-          ret = -EINVAL;
-          break;
-        }
-    }
+  hrtimer->expired = UINT64_MAX;

Review Comment:
   Done



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to