wangchdo commented on code in PR #17642:
URL: https://github.com/apache/nuttx/pull/17642#discussion_r2661124536
##########
sched/hrtimer/hrtimer_process.c:
##########
@@ -94,32 +106,36 @@ void hrtimer_process(uint64_t now)
RB_REMOVE(hrtimer_tree_s, &g_hrtimer_tree, &hrtimer->node);
- /* Ensure the timer callback is valid */
+ /* Increment running reference counter */
+
+ hrtimer->cpus++;
- DEBUGASSERT(hrtimer->func != NULL);
+ /* cpus is a running reference counter and must never wrap */
- hrtimer->state = HRTIMER_STATE_RUNNING;
+ DEBUGASSERT(hrtimer->cpus != 0);
- spin_unlock_irqrestore(&g_hrtimer_spinlock, flags);
+ /* Leave critical section before invoking the callback */
+
+ write_sequnlock_irqrestore(&g_hrtimer_spinlock, flags);
/* Invoke the timer callback */
- period = hrtimer->func(hrtimer);
+ period = func(arg);
- flags = spin_lock_irqsave(&g_hrtimer_spinlock);
+ /* Re-enter critical section to update timer state */
- if ((hrtimer->state == HRTIMER_STATE_CANCELED) || (period == 0))
- {
- /* Timer is canceled or one-shot; mark it inactive */
+ flags = write_seqlock_irqsave(&g_hrtimer_spinlock);
- hrtimer->state = HRTIMER_STATE_INACTIVE;
- }
- else
+ hrtimer->cpus--;
+
+ /* Re-arm periodic timer if not canceled or re-armed concurrently */
+
+ if (period > 0 && hrtimer->expired == expired)
Review Comment:
Agree, Updated.
##########
include/nuttx/hrtimer.h:
##########
@@ -97,11 +84,11 @@ struct hrtimer_node_s
struct hrtimer_s
{
- hrtimer_node_t node; /* RB-tree node for sorted insertion */
- enum hrtimer_state_e state; /* Current timer state */
- hrtimer_cb func; /* Expiration callback function */
- FAR void *arg; /* Argument passed to callback */
- uint64_t expired; /* Absolute expiration time (ns) */
+ hrtimer_node_t node; /* RB-tree node for sorted insertion */
+ hrtimer_cb func; /* Expiration callback function */
+ FAR void *arg; /* Argument passed to callback */
+ uint64_t expired; /* Absolute expiration time (ns) */
+ uint8_t cpus; /* Number of cpus that are running the timer */
Review Comment:
OK, updated
--
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]