From 7d4003b184bf3b809fb0e23f949a1aa30ae6a802 Mon Sep 17 00:00:00 2001 From: njl Date: Mon, 9 Apr 2007 21:10:04 +0000 Subject: Restore the locking for the sleep/wakeup to avoid waiting an extra 1 sec if a race was lost. We're still single-threaded at this point, but just be safe for the future. --- sys/kern/vfs_mount.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'sys/kern') diff --git a/sys/kern/vfs_mount.c b/sys/kern/vfs_mount.c index c6ddedb..5182249 100644 --- a/sys/kern/vfs_mount.c +++ b/sys/kern/vfs_mount.c @@ -1378,12 +1378,13 @@ root_mount_done(void) { /* - * No mutex is acquired here because int stores are atomic. If a - * thread is polling root_mount_complete, it may get a spurious - * wakeup() but that is fine in the tsleep()/wakeup() model. + * Use a mutex to prevent the wakeup being missed and waiting for + * an extra 1 second sleep. */ + mtx_lock(&mountlist_mtx); root_mount_complete = 1; wakeup(&root_mount_complete); + mtx_unlock(&mountlist_mtx); } /* @@ -1393,6 +1394,7 @@ int root_mounted(void) { + /* No mutex is acquired here because int stores are atomic. */ return (root_mount_complete); } @@ -1409,8 +1411,12 @@ root_mount_wait(void) */ KASSERT(curthread->td_proc->p_pid != 0, ("root_mount_wait: cannot be called from the swapper thread")); - while (!root_mount_complete) - tsleep(&root_mount_complete, PZERO, "rootwait", hz); + mtx_lock(&mountlist_mtx); + while (!root_mount_complete) { + msleep(&root_mount_complete, &mountlist_mtx, PZERO, "rootwait", + hz); + } + mtx_unlock(&mountlist_mtx); } static void -- cgit v1.1