Change Mutex by RwLock
Some checks failed
Build legacy Nix package on Ubuntu / build (push) Failing after 10m35s

This commit is contained in:
Florian RICHER 2025-05-30 22:04:54 +02:00
parent bc42892d39
commit b1458785e5
Signed by: florian.richer
GPG key ID: C73D37CBED7BFC77
2 changed files with 44 additions and 38 deletions

View file

@ -1,4 +1,4 @@
use std::sync::{Arc, Mutex};
use std::sync::{Arc, RwLock};
use egui_winit_vulkano::Gui;
use vulkano::{
@ -35,19 +35,19 @@ pub struct ApplicationContext {
pub window_id: WindowId,
// Données mutables partagées avec Arc<Mutex<>>
pub vulkano_windows: Arc<Mutex<VulkanoWindows>>,
pub input_manager: Arc<Mutex<InputManager>>,
pub timer: Arc<Mutex<Timer>>,
pub gui: Arc<Mutex<Gui>>,
pub vulkano_windows: Arc<RwLock<VulkanoWindows>>,
pub input_manager: Arc<RwLock<InputManager>>,
pub timer: Arc<RwLock<Timer>>,
pub gui: Arc<RwLock<Gui>>,
}
impl ApplicationContext {
pub fn new(
vulkan_context: Arc<VulkanContext>,
vulkano_windows: Arc<Mutex<VulkanoWindows>>,
input_manager: Arc<Mutex<InputManager>>,
timer: Arc<Mutex<Timer>>,
gui: Arc<Mutex<Gui>>,
vulkano_windows: Arc<RwLock<VulkanoWindows>>,
input_manager: Arc<RwLock<InputManager>>,
timer: Arc<RwLock<Timer>>,
gui: Arc<RwLock<Gui>>,
event_loop_proxy: EventLoopProxy<UserEvent>,
window_id: WindowId,
) -> Self {
@ -172,7 +172,7 @@ impl ApplicationContext {
{
let vulkano_windows = self
.vulkano_windows
.lock()
.read()
.expect("Failed to lock vulkano_windows");
let renderer = vulkano_windows
.get_renderer(self.window_id)
@ -187,7 +187,7 @@ impl ApplicationContext {
{
let mut vulkano_windows = self
.vulkano_windows
.lock()
.write()
.expect("Failed to lock vulkano_windows");
let renderer = vulkano_windows
.get_renderer_mut(self.window_id)
@ -200,7 +200,7 @@ impl ApplicationContext {
where
F: FnOnce(&Gui) -> T,
{
let gui = self.gui.lock().unwrap();
let gui = self.gui.read().expect("Failed to lock gui");
f(&gui)
}
@ -209,7 +209,7 @@ impl ApplicationContext {
where
F: FnOnce(&mut Gui) -> T,
{
let mut gui = self.gui.lock().unwrap();
let mut gui = self.gui.write().expect("Failed to lock gui");
f(&mut gui)
}
@ -218,7 +218,10 @@ impl ApplicationContext {
where
F: FnOnce(&InputManager) -> T,
{
let input_manager = self.input_manager.lock().unwrap();
let input_manager = self
.input_manager
.read()
.expect("Failed to lock input_manager");
f(&input_manager)
}
@ -227,7 +230,7 @@ impl ApplicationContext {
where
F: FnOnce(&Timer) -> T,
{
let timer = self.timer.lock().unwrap();
let timer = self.timer.read().expect("Failed to lock timer");
f(&timer)
}
}