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-11-25 19:09 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。后提交者会只持本队列锁摘除另一队列的节点。请串行化同一工作项的归属变更,再操作所属队列的链表。
|
没问题,等我改改,我的线程好像会串行 |
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 work safely detached from the previous delayed list before inserting into the immediate work list. Cancel any pending work on a foreign workqueue before submitting, reset RT_WORK_STATE_SUBMITTING when removing from lists, and re-initialize work->list to prevent dangling list node corruption upon subsequent removal. For a cross-queue submit, snapshot the previous owner once and re-check work->workqueue under that queue's spinlock before detaching the item: the owner's worker thread may dequeue the work and clear work->workqueue in between, in which case there is nothing left to cancel. Only one queue lock is held at a time, so two workqueues cannot deadlock on each other. - Serialize work ownership changes across queues. Two threads submitting the same work item may both observe work->workqueue == NULL (or a stale owner) and then each take only its own queue lock, so one of them would unlink the node from the other queue's list. _workqueue_submit_work(), _workqueue_cancel_work() and rt_workqueue_urgent_work() now take one owner lock around the ownership hand-off (lock order: owner lock, then a single queue lock), re-check work->workqueue under the queue lock, and cancel on the old owner before moving the node; cancelling a work owned by another queue returns -RT_EBUSY instead of touching that queue's list, and urgent also records work->workqueue = queue. Co-Authored-By: DeepSeek Flash 1017 Co-Authored-By: Gemini 3.8 Flash
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。调用方会以为取消成功,实际回调仍可能执行。请把取消失败的结果返回给调用方。
修#8477
以前延迟任务没到点并且 submit(0)时,定时器和状态没有收干净会导致 recall
现在直接改成停掉再执行,多加一次终端