From 83e09bfa79d0ef588a38c04c997ee8091ea52617 Mon Sep 17 00:00:00 2001 From: zxystd <1051244836@qq.com> Date: Wed, 13 Mar 2024 01:07:31 +0800 Subject: [PATCH] task: check if task is already in queue before trying lock, potentially fixing thread race crash issue. --- itl80211/openbsd/sys/_task.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/itl80211/openbsd/sys/_task.cpp b/itl80211/openbsd/sys/_task.cpp index df69a1a6f..8188b5426 100644 --- a/itl80211/openbsd/sys/_task.cpp +++ b/itl80211/openbsd/sys/_task.cpp @@ -276,16 +276,19 @@ int task_add(struct taskq *tq, struct task *w) { int rv = 0; -// IOLog("itlwm: taskq task_add %s\n", w->name); +// IOLog("itlwm: taskq task_add %s thread: %lld\n", w->name, thread_tid(current_thread())); + + if (ISSET(w->t_flags, TASK_ONQUEUE)) + return (0); IORecursiveLockLock(tq->tq_mtx); if (ISSET(w->t_flags, TASK_ONQUEUE)) { - IOLog("itlwm: taskq task_add %s is already on queue\n", w->name); +// IOLog("itlwm: taskq task_add %s is already on queue thread: %lld\n", w->name, thread_tid(current_thread())); IORecursiveLockUnlock(tq->tq_mtx); return (0); } if (!ISSET(w->t_flags, TASK_ONQUEUE)) { - IOLog("itlwm: taskq task_add %s add to queue\n", w->name); +// IOLog("itlwm: taskq task_add %s add to queue thread: %lld\n", w->name, thread_tid(current_thread())); rv = 1; SET(w->t_flags, TASK_ONQUEUE); TAILQ_INSERT_TAIL(&tq->tq_worklist, w, t_entry); @@ -302,7 +305,10 @@ int task_del(struct taskq *tq, struct task *w) { int rv = 0; -// IOLog("itlwm: taskq task_del %s\n", w->name); +// IOLog("itlwm: taskq task_del %s thread: %lld\n", w->name, thread_tid(current_thread())); + + if (!ISSET(w->t_flags, TASK_ONQUEUE)) + return (0); IORecursiveLockLock(tq->tq_mtx); if (ISSET(w->t_flags, TASK_ONQUEUE)) {