Source-Changes-HG archive

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

[src/trunk]: src/sys/dev/sysmon Replace callout_stop with callout_halt



details:   https://anonhg.NetBSD.org/src/rev/8e1714b8a9f3
branches:  trunk
changeset: 333931:8e1714b8a9f3
user:      ozaki-r <ozaki-r%NetBSD.org@localhost>
date:      Sat Nov 22 15:09:30 2014 +0000

description:
Replace callout_stop with callout_halt

In order to call callout_destroy for a callout safely, we have to ensure
the function of the callout is not running and pending. To do so, we should
use callout_halt, not callout_stop.

In this case, we need to pass an interlock to callout_halt to wait for
the callout complete. And also we make sure that SME_CALLOUT_INITIALIZED
is unset before calling callout_halt to prevent the callout from calling
callout_schedule. This is the same as what we did in sys/netinet6/mld6.c@1.61.

Reviewed by riastradh@.

diffstat:

 sys/dev/sysmon/sysmon_envsys_events.c |  16 +++++++++++-----
 1 files changed, 11 insertions(+), 5 deletions(-)

diffs (38 lines):

diff -r dd12c1c31e28 -r 8e1714b8a9f3 sys/dev/sysmon/sysmon_envsys_events.c
--- a/sys/dev/sysmon/sysmon_envsys_events.c     Sat Nov 22 15:02:39 2014 +0000
+++ b/sys/dev/sysmon/sysmon_envsys_events.c     Sat Nov 22 15:09:30 2014 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: sysmon_envsys_events.c,v 1.111 2014/11/22 15:00:05 ozaki-r Exp $ */
+/* $NetBSD: sysmon_envsys_events.c,v 1.112 2014/11/22 15:09:30 ozaki-r Exp $ */
 
 /*-
  * Copyright (c) 2007, 2008 Juan Romero Pardines.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys_events.c,v 1.111 2014/11/22 15:00:05 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys_events.c,v 1.112 2014/11/22 15:09:30 ozaki-r Exp $");
 
 #include <sys/param.h>
 #include <sys/types.h>
@@ -611,10 +611,16 @@
 {
        KASSERT(mutex_owned(&sme->sme_mtx));
 
-       callout_stop(&sme->sme_callout);
+       /*
+        * Unset before callout_halt to ensure callout is not scheduled again
+        * during callout_halt.
+        */
+       sme->sme_flags &= ~SME_CALLOUT_INITIALIZED;
+
+       callout_halt(&sme->sme_callout, &sme->sme_mtx);
+       callout_destroy(&sme->sme_callout);
+
        workqueue_destroy(sme->sme_wq);
-       callout_destroy(&sme->sme_callout);
-       sme->sme_flags &= ~SME_CALLOUT_INITIALIZED;
        DPRINTF(("%s: events framework destroyed for '%s'\n",
            __func__, sme->sme_name));
 }



Home | Main Index | Thread Index | Old Index