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


##########
include/nuttx/hrtimer/hrtimer_queue.h:
##########
@@ -0,0 +1,555 @@
+/****************************************************************************
+ * include/nuttx/hrtimer_queue.h
+ *
+ * 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.
+ *
+ ****************************************************************************/
+
+#ifndef __INCLUDE_HRTIMER_QUEUE_H
+#define __INCLUDE_HRTIMER_QUEUE_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <nuttx/compiler.h>
+#include <nuttx/clock.h>
+#include <nuttx/seqlock.h>
+
+#include <nuttx/hrtimer_queue_type.h>
+
+#include <stdint.h>
+
+/* This header file should be only included for internal use,
+ * DO NOT EXPOSE IT TO USERS.
+ *
+ * Before including this file, Please provide the following inputs:
+ *
+ * Include the hrtimer_type_xxx.h header file. This header file should
+ * provide the implementation of the queue operations and definition for
+ * internal hrtimer.
+ *
+ * Function implementation: static inline_function
+ * void hrtimer_reprogram(FAR USER_HRTIMER_QUEUE_TYPE *queue,
+ *                        uint64_t next_expired);
+ *   - Reprogram the timer hardware to the next expired time.
+ */
+
+#ifdef __cplusplus
+#define EXTERN extern "C"
+extern "C"
+{
+#else
+#define EXTERN extern
+#endif
+
+/****************************************************************************
+ * Inline function
+ ****************************************************************************/
+
+/* The relied function hrtimer_reprogram must be implemented.
+ * Please note the forward declaration and reverse dependency here.
+ * We instead of the function pointers because most functional-safety
+ * compilers (E.g. GHC, Tasking and CompCert C) do not support inlining
+ * function pointers, which would introduce additional memory and
+ * performance overhead.
+ */
+
+static inline_function
+void hrtimer_reprogram(FAR hrtimer_queue_internal_t *queue,

Review Comment:
   **Why Forward‑declare the Dependent Function hrtimer_reprogram?**
   I also tried two other approaches, but each had its own issues:
   
   - Using a pre‑defined `hrtimer_ops_t` callback to inform users that they 
need to implement `hrtimer_reprogram` when instantiating an hrtimer. This works 
fine under `GCC/Clang`—the compiler can fully inline static const 
`hrtimer_ops_t` and eliminate the overhead of the structure. However, I checked 
the assembly and found that safety compilers like `CompCertC` can not perform 
such optimizations.
   - Using higher‑order macro functions, passing `hrtimer_reprogram` as a 
dependent input function. This avoids compiler optimization issues, but 
@xiaoxiang781216 and @GUIDINGLI considered it poor for readability.
   
   After trying the above approaches, I chose to forward‑declare the dependent 
function `hrtimer_reprogram`. This implementation meets readability, 
performance, and memory-overhead requirements, but requires slight caution 
during use (the inclusion order must strictly follow Figure 1; otherwise, 
compilation errors may occur).



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