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


##########
sched/hrtimer/hrtimer_start.c:
##########
@@ -0,0 +1,135 @@
+/****************************************************************************
+ * sched/hrtimer/hrtimer_start.c
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+#include <nuttx/arch.h>
+#include <nuttx/clock.h>
+#include <errno.h>
+#include <hrtimer/hrtimer.h>
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: hrtimer_insert
+ *
+ * Description:
+ *   Insert the given high-resolution timer into the active timer RB-tree.
+ *   If the timer already exists, it will be removed and re-inserted.
+ *   If the inserted timer is the earliest in the tree, start the hardware
+ *   timer to fire at its expiration.
+ *
+ * Input Parameters:
+ *   hrtimer - Pointer to the hrtimer structure to be inserted.
+ *
+ * Returned Value:
+ *   OK (0) on success, or a negated errno value on failure.
+ *
+ * Assumptions/Notes:
+ *   - This function should be called with interrupts disabled or under
+ *     spinlock protection to ensure RB-tree integrity.
+ *   - Inline function for performance in critical path.
+ ****************************************************************************/
+
+static inline_function
+int hrtimer_insert(FAR hrtimer_t *hrtimer)
+{
+  int ret = OK;
+  FAR struct hrtimer_node_s *inserted =
+    RB_INSERT(hrtimer_tree_s, &g_activetree, &hrtimer->node);
+
+  if (inserted == NULL)
+    {
+      if (&hrtimer->node == RB_MIN(hrtimer_tree_s, &g_activetree))
+        {
+          /* If new timer is the earliest, start hardware timer */
+
+          ret = hrtimer_starttimer(hrtimer->expired);

Review Comment:
   nxsched_reassess_timer is for tickless os which is supported by the hrtimer 
instance when hrtiner is enabled, and is in tick level resolution, so i don't 
think it is propriate to use it here.
   
   I updated implementation of nxsched_timer_start to use nxsched_hrtimer_start 
when hrtimer is enabled, I think this will be good, could you please have a 
check? 



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