Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src-draft/trunk]: src/sys/net80211 Fix locking and destruction for task/time...
details: https://anonhg.NetBSD.org/src-all/rev/0864718e5908
branches: trunk
changeset: 947873:0864718e5908
user: Martin Husemann <martin%NetBSD.org@localhost>
date: Sat Dec 19 16:23:18 2020 +0100
description:
Fix locking and destruction for task/timer queues.
Add TIMEOUT_TASK_DESTROY() and TIMEOUT_TASK_DESTROY() macros to
clean up the corresponding task structures.
diffstat:
sys/net80211/ieee80211_netbsd.c | 21 +++++++++++++++------
sys/net80211/ieee80211_netbsd.h | 22 +++++++++++++++++-----
2 files changed, 32 insertions(+), 11 deletions(-)
diffs (105 lines):
diff -r 16091167b277 -r 0864718e5908 sys/net80211/ieee80211_netbsd.c
--- a/sys/net80211/ieee80211_netbsd.c Sat Dec 19 16:17:29 2020 +0100
+++ b/sys/net80211/ieee80211_netbsd.c Sat Dec 19 16:23:18 2020 +0100
@@ -131,8 +131,8 @@
void
taskqueue_drain(struct workqueue *wq, struct task *task_item)
{
+
workqueue_wait(wq, &task_item->t_work);
- mutex_destroy(&task_item->t_mutex);
}
static void
@@ -151,7 +151,12 @@
struct timeout_task *timeout_task, int nticks)
{
mutex_enter(&timeout_task->to_task.t_mutex);
- if (!timeout_task->to_scheduled) {
+ if (timeout_task->to_scheduled == -1) {
+ /* we are draining the task queue */
+ mutex_exit(&timeout_task->to_task.t_mutex);
+ return EIO;
+ }
+ if (timeout_task->to_scheduled == 0) {
callout_reset(&timeout_task->to_callout, nticks,
taskqueue_callout_enqueue, timeout_task);
timeout_task->to_scheduled = 1;
@@ -170,16 +175,20 @@
timeout_task->to_scheduled = 0;
mutex_exit(&timeout_task->to_task.t_mutex);
- // printf ("taskqueue_cancel_timeout called\n");
-
return 0;
}
void
-taskqueue_drain_timeout(struct workqueue *queue,
+taskqueue_drain_timeout(struct workqueue *wq,
struct timeout_task *timeout_task)
{
- // printf ("taskqueue_drain_timeout called\n");
+
+ mutex_enter(&timeout_task->to_task.t_mutex);
+ timeout_task->to_scheduled = -1;
+ callout_halt(&timeout_task->to_callout,
+ &timeout_task->to_task.t_mutex);
+ workqueue_wait(wq, &timeout_task->to_task.t_work);
+ mutex_exit(&timeout_task->to_task.t_mutex);
}
diff -r 16091167b277 -r 0864718e5908 sys/net80211/ieee80211_netbsd.h
--- a/sys/net80211/ieee80211_netbsd.h Sat Dec 19 16:17:29 2020 +0100
+++ b/sys/net80211/ieee80211_netbsd.h Sat Dec 19 16:23:18 2020 +0100
@@ -107,10 +107,14 @@
};
struct timeout_task {
- struct task to_task; /* Must be first so we can cast to a task. */
- struct workqueue *to_wq;
- callout_t to_callout;
- int to_scheduled;
+ /* Must be first so we can cast to a task. */
+ struct task to_task;
+ struct workqueue *to_wq;
+ callout_t to_callout;
+ int to_scheduled; /* 0 inactive,
+ * 1 pending,
+ * -1 draining
+ */
};
@@ -130,7 +134,6 @@
int ieee80211_clone_attach(void);
void ieee80211_if_attach(struct ifnet *ifp, const uint8_t *lla);
-/* NNN ---- Need to add a way to mutex_destroy at the right time. */
#define TASK_INIT(var, pri, func, arg) do { \
(var)->t_func = func; \
@@ -140,6 +143,10 @@
(var)->t_func_name = #func; \
} while(0)
+#define TASK_DESTROY(var) do { \
+ mutex_destroy(&(var)->t_mutex);\
+} while(0)
+
#define TIMEOUT_TASK_INIT(queue, task, pri, func, arg) do { \
(task)->to_task.t_func = func; \
(task)->to_task.t_arg = arg; \
@@ -151,6 +158,11 @@
(task)->to_scheduled = 0;\
} while (0)
+#define TIMEOUT_TASK_DESTROY(task) do { \
+ mutex_destroy(&(task)->to_task.t_mutex);\
+ callout_destroy(&(task)->to_callout);\
+} while (0)
+
#define taskqueue workqueue
#define taskqueue_free(queue) workqueue_destroy(queue)
Home |
Main Index |
Thread Index |
Old Index