Repository navigation
[drivers][workqueue] 延迟改立即提交时停掉旧定时器 - #12059
cms19859230182-lang wants to merge 1 commit into
Conversation
|
在重新提交工作项时先清理异构队列在途任务与 delayed/submitting 状态,并将节点链表安全重置,避免提前以 tick=0 触发后残留状态干扰。 |
|
👋 感谢您对 RT-Thread 的贡献!Thank you for your contribution to RT-Thread! 为确保代码符合 RT-Thread 的编码规范,请在你的仓库中执行以下步骤运行代码格式化工作流(如果格式化CI运行失败)。 🛠 操作步骤 | Steps
完成后,提交将自动更新至 如有问题欢迎联系我们,再次感谢您的贡献!💐 |
📌 Code Review Assignment🏷️ Tag: componentsReviewers: @Maihuanyi Changed Files (Click to expand)
📊 Current Review Status (Last Updated: 2026-12-01 12:58 CST)
📝 Review Instructions
|
|
|
#11285 跟这个pr是否是一样的工作? |
|
|
||
| if (work->workqueue != RT_NULL && work->workqueue != queue) | ||
| { | ||
| _workqueue_cancel_work(work->workqueue, work); |
There was a problem hiding this comment.
这里读了两次 work->workqueue,原队列的 worker 可以在中间取走 work 并清空指针。迁移节点前请在原队列锁下复核归属。
The old worker can dequeue the item and clear work->workqueue between these two reads. Recheck ownership under the old queue's lock before moving the item.
82e2605 to
0c34ed7
Compare
| level = rt_spin_lock_irqsave(&(queue->spinlock)); | ||
| /* remove list */ | ||
| /* remove list and reset delayed state */ | ||
| rt_list_remove(&(work->list)); |
There was a problem hiding this comment.
两个线程同时把空闲的 work 提交到不同队列时,都可能读到空的 owner。后提交者会只持本队列锁摘除另一队列的节点。请串行化同一工作项的归属变更,再操作所属队列的链表。
|
没问题,等我改改,我的线程好像会串行 |
0c34ed7 to
fca1539
Compare
| { | ||
| /* The work belongs to another queue: its list node must not be | ||
| * unlinked without that queue's lock. */ | ||
| err = -RT_EBUSY; |
There was a problem hiding this comment.
工作项移到另一队列后,这里会返回 -RT_EBUSY,但 rt_workqueue_cancel_work_sync() 丢掉了这个结果并返回 RT_EOK。调用方会以为取消成功,实际回调仍可能执行。请把取消失败的结果返回给调用方。
698e475 to
1c1f1ba
Compare
| } | ||
|
|
||
| /* not in this queue any more: the work item has been moved away */ | ||
| if (work->workqueue != RT_NULL && work->workqueue != queue) |
There was a problem hiding this comment.
取消时已在锁内判定工作项属于另一队列。这里重读 workqueue 时,另一队列的 worker 可能已取走工作并清空该字段,下一轮就会按空闲返回 RT_EOK,即使回调还在运行。请直接返回锁内判定的结果,区分已迁移和本队列正在执行。
There was a problem hiding this comment.
让我审查一下我的代码,我想想这是咋回事
Fix RT-Thread#8477 When a delayed work item (submitted with ticks > 0) is resubmitted with ticks == 0 before its delay expires, the delayed state must be cleared and the item detached from the previous delayed list before it is inserted into the immediate work list. Serialize the ownership hand-off of a work item with a module spinlock that is always taken before any queue->spinlock: _workqueue_submit_work(), rt_workqueue_urgent_work() and _workqueue_cancel_work(). Two threads may both see an idle (or stale) owner and then each take only their own queue lock, so one of them would unlink the node from the other queue's list. The owner is now snapshot once, re-checked under that queue's lock before the node is detached, and only one queue lock is held at a time, so two queues cannot deadlock on each other. rt_workqueue_urgent_work() also records work->workqueue = queue. A work item owned by another queue can no longer be unlinked from here: rt_workqueue_cancel_work() reports -RT_EBUSY for it, and rt_workqueue_cancel_work_sync() passes that result on instead of returning RT_EOK. Reporting success made callers (aio_cancel(), rt_work_cancel() users) believe the callback could no longer run while it still could. The synchronous variant still waits for the callback when the item is executed by its own queue.
1c1f1ba to
79d1e58
Compare
修#8477
以前延迟任务没到点并且 submit(0)时,定时器和状态没有收干净会导致 recall
现在直接改成停掉再执行,多加一次终端