From f6bc1d4631b630c4dfffe857ea6ca24bcc47d08c Mon Sep 17 00:00:00 2001 From: coffee Date: Sun, 19 Apr 2026 23:50:35 +0800 Subject: [PATCH] =?UTF-8?q?1.=20=E4=BF=AE=E5=A4=8D=E5=AE=9A=E6=97=B6?= =?UTF-8?q?=E5=99=A8=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/HTimer.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/HTimer.c b/src/HTimer.c index 96cac79..0bc8d23 100644 --- a/src/HTimer.c +++ b/src/HTimer.c @@ -239,7 +239,8 @@ static HTimer_t AddTimerData(uint8_t id, uint32_t duration, HTimerCallType call, t->call = call; t->flags = flags; t->heapIndex = HEAP_INVALID_INDEX; - HTIMER_RELEASE_FENCE(); // 确保上述写入在状态变更前完成 + // 确保上述写入在状态变更前完成 + HTIMER_RELEASE_FENCE(); // 第二步:kTimerAdding -> kTimerActive,标记初始化完成 HTIMER_STORE(&t->state, kTimerActive); @@ -307,7 +308,7 @@ uint8_t HTimerRegisterTimerInfo(uint8_t id, HTimerInfo *info, uint16_t infoLen) return 0; } - if (infoLen > 255) { + if (infoLen > HTIMER_LEN_MAX) { LogD("infoLen too large, max 255"); return 0; } @@ -338,8 +339,10 @@ void HTimerRun(uint8_t id) // schedu 阶段:只有 HTimerRun 修改堆,单线程安全 // 使用 acquire-release 语义确保看到其他线程的写入 while (HTIMER_ATOMIC_XCHG(®->schedu, 0)) { - HTIMER_ACQUIRE_FENCE(); // 确保看到 AddTimerData 中的写入 - // 1. 清理堆中已删除的定时器 + // 确保看到 AddTimerData 中的写入 + HTIMER_ACQUIRE_FENCE(); + + // 1. 清理堆中已删除的定时器 for (HTimerLen_t i = reg->heapSize; i > 0;) { i--; HTimerLen_t tIdx = HEAP_AT(reg, i); @@ -350,6 +353,7 @@ void HTimerRun(uint8_t id) t->state = kTimerUnused; HTIMER_BARRIER(); if (i < reg->heapSize) { + heapUp(reg, i); heapDown(reg, i); } }