mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2024-08-22 07:51:16 +00:00
This patch modifies `event_monitor` to ensure that concurrent access to `event_log` from multiple threads is safe. Previously, the `event_log` function would acquire a reference to the event log file and write to it without doing any synchronization, which made it prone to data races. This issue likely went under the radar because the relevant `SAFETY` comment on the unsafe block was incomplete. The new implementation spawns a dedicated thread named `event-monitor` solely for writing to the file. It uses the MPMC channel exposed by `flume` to pass messages to the `event-monitor` thread. Since `flume::Sender<T>` implements `Sync`, it is safe for multiple threads to share it and send messages to the `event-monitor` thread. This is not possible with `std::sync::mpsc::Sender<T>` since it's `!Sync`, meaning it is not safe for it to be shared between different threads. The `event_monitor::set_monitor` function now only initializes the required global state and returns an instance of the `Monitor` struct. This decouples the actual logging logic from the `event_monitor` crate. The `event-monitor` thread is then spawned by the `vmm` crate. Signed-off-by: Omer Faruk Bayram <omer.faruk@sartura.hr> |
||
---|---|---|
.. | ||
src | ||
Cargo.toml |