Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/external/bsd/common/linux Deduplicate callout destruction.



details:   https://anonhg.NetBSD.org/src/rev/7f031f38dffe
branches:  trunk
changeset: 835442:7f031f38dffe
user:      riastradh <riastradh%NetBSD.org@localhost>
date:      Mon Aug 27 15:03:59 2018 +0000

description:
Deduplicate callout destruction.

diffstat:

 sys/external/bsd/common/linux/linux_work.c |  40 +++++++++++++++++++++---------
 1 files changed, 28 insertions(+), 12 deletions(-)

diffs (89 lines):

diff -r 6e41b3507dd9 -r 7f031f38dffe sys/external/bsd/common/linux/linux_work.c
--- a/sys/external/bsd/common/linux/linux_work.c        Mon Aug 27 15:03:45 2018 +0000
+++ b/sys/external/bsd/common/linux/linux_work.c        Mon Aug 27 15:03:59 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: linux_work.c,v 1.30 2018/08/27 15:03:45 riastradh Exp $        */
+/*     $NetBSD: linux_work.c,v 1.31 2018/08/27 15:03:59 riastradh Exp $        */
 
 /*-
  * Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: linux_work.c,v 1.30 2018/08/27 15:03:45 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: linux_work.c,v 1.31 2018/08/27 15:03:59 riastradh Exp $");
 
 #include <sys/types.h>
 #include <sys/atomic.h>
@@ -67,6 +67,8 @@
                            struct workqueue_struct *);
 static void            dw_callout_init(struct workqueue_struct *,
                            struct delayed_work *);
+static void            dw_callout_destroy(struct workqueue_struct *,
+                           struct delayed_work *);
 static void            cancel_delayed_work_done(struct workqueue_struct *,
                            struct delayed_work *);
 
@@ -305,9 +307,7 @@
        case DELAYED_WORK_IDLE:
                panic("delayed work callout uninitialized: %p", dw);
        case DELAYED_WORK_SCHEDULED:
-               dw->dw_state = DELAYED_WORK_IDLE;
-               callout_destroy(&dw->dw_callout);
-               TAILQ_REMOVE(&wq->wq_delayed, dw, dw_entry);
+               dw_callout_destroy(wq, dw);
                TAILQ_INSERT_TAIL(&wq->wq_queue, &dw->work, work_entry);
                cv_broadcast(&wq->wq_cv);
                break;
@@ -564,6 +564,26 @@
 }
 
 /*
+ * dw_callout_destroy(wq, dw)
+ *
+ *     Destroy the callout of dw and transition to DELAYED_WORK_IDLE.
+ */
+static void
+dw_callout_destroy(struct workqueue_struct *wq, struct delayed_work *dw)
+{
+
+       KASSERT(mutex_owned(&wq->wq_lock));
+       KASSERT(dw->work.work_queue == wq);
+       KASSERT(dw->dw_state == DELAYED_WORK_SCHEDULED ||
+           dw->dw_state == DELAYED_WORK_RESCHEDULED ||
+           dw->dw_state == DELAYED_WORK_CANCELLED);
+
+       TAILQ_REMOVE(&wq->wq_delayed, dw, dw_entry);
+       callout_destroy(&dw->dw_callout);
+       dw->dw_state = DELAYED_WORK_IDLE;
+}
+
+/*
  * cancel_delayed_work_done(wq, dw)
  *
  *     Complete cancellation of a delayed work: transition from
@@ -577,9 +597,8 @@
        KASSERT(mutex_owned(&wq->wq_lock));
        KASSERT(dw->work.work_queue == wq);
        KASSERT(dw->dw_state == DELAYED_WORK_CANCELLED);
-       dw->dw_state = DELAYED_WORK_IDLE;
-       callout_destroy(&dw->dw_callout);
-       TAILQ_REMOVE(&wq->wq_delayed, dw, dw_entry);
+
+       dw_callout_destroy(wq, dw);
        release_work(&dw->work, wq);
        /* Can't touch dw after this point.  */
 }
@@ -862,10 +881,7 @@
                                         * queue, and signal the worker
                                         * thread.
                                         */
-                                       dw->dw_state = DELAYED_WORK_IDLE;
-                                       callout_destroy(&dw->dw_callout);
-                                       TAILQ_REMOVE(&wq->wq_delayed, dw,
-                                           dw_entry);
+                                       dw_callout_destroy(wq, dw);
                                        TAILQ_INSERT_TAIL(&wq->wq_queue,
                                            &dw->work, work_entry);
                                        cv_broadcast(&wq->wq_cv);



Home | Main Index | Thread Index | Old Index