From 4d492cb2c6bf83f904625a9c87de99115b23f905 Mon Sep 17 00:00:00 2001 From: 21pages Date: Sat, 12 Nov 2022 17:18:26 +0800 Subject: [PATCH] portable-service: fix set capture para dead lock Signed-off-by: 21pages --- src/server/portable_service.rs | 45 ++++++++++++++++++++-------------- 1 file changed, 27 insertions(+), 18 deletions(-) diff --git a/src/server/portable_service.rs b/src/server/portable_service.rs index a666b56d5..d78038ecd 100644 --- a/src/server/portable_service.rs +++ b/src/server/portable_service.rs @@ -469,17 +469,20 @@ pub mod client { where Self: Sized, { - Self::set_para(CapturerPara { - current_display, - use_yuv, - timeout_ms: 33, - }); + let mut option = SHMEM.lock().unwrap(); + let shmem = option.as_mut().unwrap(); + Self::set_para( + shmem, + CapturerPara { + current_display, + use_yuv, + timeout_ms: 33, + }, + ); CapturerPortable {} } - fn set_para(para: CapturerPara) { - let mut option = SHMEM.lock().unwrap(); - let shmem = option.as_mut().unwrap(); + fn set_para(shmem: &mut SharedMemory, para: CapturerPara) { let para_ptr = ¶ as *const CapturerPara as *const u8; let para_data; unsafe { @@ -497,11 +500,14 @@ pub mod client { let para_ptr = shmem.as_ptr().add(ADDR_CAPTURER_PARA); let para = para_ptr as *const CapturerPara; if use_yuv != (*para).use_yuv { - Self::set_para(CapturerPara { - current_display: (*para).current_display, - use_yuv, - timeout_ms: (*para).timeout_ms, - }); + Self::set_para( + shmem, + CapturerPara { + current_display: (*para).current_display, + use_yuv, + timeout_ms: (*para).timeout_ms, + }, + ); } } } @@ -514,11 +520,14 @@ pub mod client { let para_ptr = base.add(ADDR_CAPTURER_PARA); let para = para_ptr as *const CapturerPara; if timeout.as_millis() != (*para).timeout_ms as _ { - Self::set_para(CapturerPara { - current_display: (*para).current_display, - use_yuv: (*para).use_yuv, - timeout_ms: timeout.as_millis() as _, - }); + Self::set_para( + shmem, + CapturerPara { + current_display: (*para).current_display, + use_yuv: (*para).use_yuv, + timeout_ms: timeout.as_millis() as _, + }, + ); } if utils::counter_ready(base.add(ADDR_CAPTURE_FRAME_COUNTER)) { let frame_len_ptr = base.add(ADDR_CAPTURE_FRAME_SIZE);