summaryrefslogtreecommitdiffstats
path: root/sys/dev
diff options
context:
space:
mode:
authorhselasky <hselasky@FreeBSD.org>2015-01-11 12:25:10 +0000
committerhselasky <hselasky@FreeBSD.org>2015-01-11 12:25:10 +0000
commitdd1bd8c59187bdd5b23cd4deaff30bd37228bdf9 (patch)
tree0e8ba4569e787712c0a96c16f219360cd5733a97 /sys/dev
parentf17550e390afea114ef25ae736f4483da1ac5ec1 (diff)
downloadFreeBSD-src-dd1bd8c59187bdd5b23cd4deaff30bd37228bdf9.zip
FreeBSD-src-dd1bd8c59187bdd5b23cd4deaff30bd37228bdf9.tar.gz
MFC r276534:
The "vt_suspend_flush_timer()" function is sometimes called locked which prevents us from doing a "callout_drain()" call. The callout in question has a lock associated with it and we are not freeing the callout. That means we can use the "callout_stop()" function to atomically stop the callback iff the "callout_stop()" function is called locked. This patch applies proper locking to "callout_stop()" and replaces a "callout_drain()" with a "callout_stop()".
Diffstat (limited to 'sys/dev')
-rw-r--r--sys/dev/vt/vt_core.c11
1 files changed, 10 insertions, 1 deletions
diff --git a/sys/dev/vt/vt_core.c b/sys/dev/vt/vt_core.c
index f7e3244..3af8b9e 100644
--- a/sys/dev/vt/vt_core.c
+++ b/sys/dev/vt/vt_core.c
@@ -114,6 +114,7 @@ const struct terminal_class vt_termclass = {
#define VT_LOCK(vd) mtx_lock(&(vd)->vd_lock)
#define VT_UNLOCK(vd) mtx_unlock(&(vd)->vd_lock)
+#define VT_LOCK_ASSERT(vd, what) mtx_assert(&(vd)->vd_lock, what)
#define VT_UNIT(vw) ((vw)->vw_device->vd_unit * VT_MAXWINDOWS + \
(vw)->vw_number)
@@ -282,12 +283,18 @@ vt_resume_flush_timer(struct vt_device *vd, int ms)
static void
vt_suspend_flush_timer(struct vt_device *vd)
{
+ /*
+ * As long as this function is called locked, callout_stop()
+ * has the same effect like callout_drain() with regard to
+ * preventing the callback function from executing.
+ */
+ VT_LOCK_ASSERT(vd, MA_OWNED);
if (!(vd->vd_flags & VDF_ASYNC) ||
!atomic_cmpset_int(&vd->vd_timer_armed, 1, 0))
return;
- callout_drain(&vd->vd_timer);
+ callout_stop(&vd->vd_timer);
}
static void
@@ -2595,7 +2602,9 @@ vt_allocate(struct vt_driver *drv, void *softc)
if (vd->vd_flags & VDF_ASYNC) {
/* Stop vt_flush periodic task. */
+ VT_LOCK(vd);
vt_suspend_flush_timer(vd);
+ VT_UNLOCK(vd);
/*
* Mute current terminal until we done. vt_change_font (called
* from vt_resize) will unmute it.
OpenPOWER on IntegriCloud