Fix-Point commented on code in PR #17517:
URL: https://github.com/apache/nuttx/pull/17517#discussion_r2621646074


##########
sched/hrtimer/hrtimer_cancel.c:
##########
@@ -0,0 +1,140 @@
+/****************************************************************************
+ * sched/hrtimer/hrtimer_cancel.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>
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: hrtimer_cancel
+ *
+ * Description:
+ *   Cancel a high-resolution timer.
+ *
+ *   If the timer is currently armed, it will be removed from the active
+ *   hrtimer red-black tree and will not be executed.
+ *
+ *   If the timer callback is currently executing, the timer will be marked
+ *   as canceled. The running callback is allowed to complete, but it will
+ *   not be re-armed or executed again.
+ *
+ *   If the canceled timer was the earliest (head) timer in the tree, the
+ *   expiration of the underlying hardware timer will be updated to:
+ *
+ *     1. The expiration time of the next earliest timer, or
+ *     2. A safe default expiration if no timers remain.
+ *
+ *   This function is non-blocking and does not wait for a running callback
+ *   to finish.
+ *
+ * Input Parameters:
+ *   hrtimer - Pointer to the high-resolution timer instance to cancel.
+ *
+ * Returned Value:
+ *   OK (0) on success; a negated errno value on failure.
+ *
+ * Assumptions/Notes:
+ *   - This function acquires the global hrtimer spinlock to protect the
+ *     red-black tree and timer state.
+ *   - The caller must ensure that the timer structure is not freed until
+ *     it is guaranteed that any running callback has returned.
+ ****************************************************************************/
+
+int hrtimer_cancel(FAR hrtimer_t *hrtimer)

Review Comment:
   How can you ensure that a periodic hrtimer can be successfully canceled? 
Does hrtimer_cancel have no upper bound for WCET?



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