Module Name:    src
Committed By:   ozaki-r
Date:           Sat Nov 22 15:09:30 UTC 2014

Modified Files:
        src/sys/dev/sysmon: sysmon_envsys_events.c

Log Message:
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/[email protected].

Reviewed by riastradh@.


To generate a diff of this commit:
cvs rdiff -u -r1.111 -r1.112 src/sys/dev/sysmon/sysmon_envsys_events.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/sysmon/sysmon_envsys_events.c
diff -u src/sys/dev/sysmon/sysmon_envsys_events.c:1.111 src/sys/dev/sysmon/sysmon_envsys_events.c:1.112
--- src/sys/dev/sysmon/sysmon_envsys_events.c:1.111	Sat Nov 22 15:00:05 2014
+++ src/sys/dev/sysmon/sysmon_envsys_events.c	Sat Nov 22 15:09:30 2014
@@ -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 @@ sme_events_destroy(struct sysmon_envsys 
 {
 	KASSERT(mutex_owned(&sme->sme_mtx));
 
-	callout_stop(&sme->sme_callout);
-	workqueue_destroy(sme->sme_wq);
-	callout_destroy(&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);
 	DPRINTF(("%s: events framework destroyed for '%s'\n",
 	    __func__, sme->sme_name));
 }

Reply via email to