diff options
author | Daniel Verkamp <dverkamp@chromium.org> | 2019-09-12 13:34:50 -0700 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2019-09-17 22:32:22 +0000 |
commit | 9dd75d0d3e1a7fa8226bef55a40a608beff5baf7 (patch) | |
tree | f5b368968319b8563f237f78b1a0f707bc976714 /devices/src/virtio/wl.rs | |
parent | 94c352752e1109fc6cf7c0cf9c6ce121ad1d46b9 (diff) | |
download | crosvm-9dd75d0d3e1a7fa8226bef55a40a608beff5baf7.tar crosvm-9dd75d0d3e1a7fa8226bef55a40a608beff5baf7.tar.gz crosvm-9dd75d0d3e1a7fa8226bef55a40a608beff5baf7.tar.bz2 crosvm-9dd75d0d3e1a7fa8226bef55a40a608beff5baf7.tar.lz crosvm-9dd75d0d3e1a7fa8226bef55a40a608beff5baf7.tar.xz crosvm-9dd75d0d3e1a7fa8226bef55a40a608beff5baf7.tar.zst crosvm-9dd75d0d3e1a7fa8226bef55a40a608beff5baf7.zip |
devices: join worker threads in drop()
Make sure all devices join any threads they spawn before returning from the drop() handler after signaling the exit event. BUG=chromium:992494 TEST=crosvm exits without errors Change-Id: I6bc91c32a08f568b041765044caa9aff6f7cf4a9 Signed-off-by: Daniel Verkamp <dverkamp@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1802156 Reviewed-by: Stephen Barber <smbarber@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com>
Diffstat (limited to 'devices/src/virtio/wl.rs')
-rw-r--r-- | devices/src/virtio/wl.rs | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/devices/src/virtio/wl.rs b/devices/src/virtio/wl.rs index e6d4f40..a4988cb 100644 --- a/devices/src/virtio/wl.rs +++ b/devices/src/virtio/wl.rs @@ -1669,6 +1669,7 @@ impl Worker { pub struct Wl { kill_evt: Option<EventFd>, + worker_thread: Option<thread::JoinHandle<()>>, wayland_path: PathBuf, vm_socket: Option<VmMemoryControlRequestSocket>, resource_bridge: Option<ResourceRequestSocket>, @@ -1683,6 +1684,7 @@ impl Wl { ) -> Result<Wl> { Ok(Wl { kill_evt: None, + worker_thread: None, wayland_path: wayland_path.as_ref().to_owned(), vm_socket: Some(vm_socket), resource_bridge, @@ -1697,6 +1699,10 @@ impl Drop for Wl { // Ignore the result because there is nothing we can do about it. let _ = kill_evt.write(1); } + + if let Some(worker_thread) = self.worker_thread.take() { + let _ = worker_thread.join(); + } } } @@ -1777,9 +1783,14 @@ impl VirtioDevice for Wl { .run(queue_evts, kill_evt); }); - if let Err(e) = worker_result { - error!("failed to spawn virtio_wl worker: {}", e); - return; + match worker_result { + Err(e) => { + error!("failed to spawn virtio_wl worker: {}", e); + return; + } + Ok(join_handle) => { + self.worker_thread = Some(join_handle); + } } } } |