wangchdo commented on code in PR #17675: URL: https://github.com/apache/nuttx/pull/17675#discussion_r2647640631
########## include/nuttx/hrtimer_type_rb.h: ########## @@ -0,0 +1,216 @@ +/**************************************************************************** + * include/nuttx/hrtimer_type_rb.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_TYPE_RB_H +#define __INCLUDE_HRTIMER_TYPE_RB_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <nuttx/config.h> + +#include <nuttx/hrtimer_queue_type.h> + +/* This header file should be only included for internal use, + * DO NOT EXPOSE IT TO USERS. + */ + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +typedef struct hrtimer_rb_s hrtimer_internal_t; +typedef struct hrtimer_rb_queue_s hrtimer_queue_internal_t; + +#define hrtimer_queue_peek(queue) hrtimer_rb_queue_peek(queue) +#define hrtimer_queue_add(queue, timer) hrtimer_rb_queue_add(queue, timer) +#define hrtimer_queue_del(queue, timer) hrtimer_rb_queue_del(queue, timer) +#define hrtimer_queue_clear(queue) hrtimer_rb_queue_clear(queue) + +#ifdef __cplusplus +#define EXTERN extern "C" +extern "C" +{ +#else +#define EXTERN extern +#endif + +/**************************************************************************** + * Inline function + ****************************************************************************/ + +/* Compare function for the rb-tree. */ + +static inline_function +int hrtimer_compare(FAR const hrtimer_rb_t *a, FAR const hrtimer_rb_t *b) +{ + /* This branchless compare is equivalent to: + * (int64_t)(a->expired - b->expired) > 0 ? 1 : -1; Review Comment: It should be equivalent to ` (int64_t)(a->expired - b->expired) >= 0 ? 1 : -1;` This ensures that when a new timer has the same expiration time as an existing one, it will be placed after the older timer. -- 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]
