From 0e3afe7ced595cd095da341775dc5eb535757614 Mon Sep 17 00:00:00 2001 From: taks <857tn859@gmail.com> Date: Fri, 22 Nov 2024 17:50:17 +0900 Subject: [PATCH 1/3] Added Mutex.try_lock --- src/utilities/mutex.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/utilities/mutex.rs b/src/utilities/mutex.rs index 181d000..2d36ab3 100644 --- a/src/utilities/mutex.rs +++ b/src/utilities/mutex.rs @@ -22,6 +22,12 @@ impl RawMutex { debug_assert_eq!(r, 0); } + #[inline(always)] + #[allow(clippy::missing_safety_doc)] + pub unsafe fn try_lock(&self) -> bool { + pthread_mutex_trylock(self.0.get()) == 0 + } + #[inline(always)] #[allow(clippy::missing_safety_doc)] pub unsafe fn unlock(&self) { @@ -54,6 +60,11 @@ impl Mutex { MutexGuard::new(self) } + #[inline(always)] + pub fn try_lock(&self) -> Option> { + MutexGuard::try_new(self) + } + #[inline(always)] pub(crate) fn into_innter(self) -> T { self.1.into_inner() @@ -79,6 +90,15 @@ impl<'a, T> MutexGuard<'a, T> { Self(mutex) } + + #[inline(always)] + fn try_new(mutex: &'a Mutex) -> Option { + if unsafe { mutex.0.try_lock() } { + Some(Self(mutex)) + } else { + None + } + } } impl<'a, T> Drop for MutexGuard<'a, T> { From 829c0f89ddf37c2e027b88ef36507d569d070ec2 Mon Sep 17 00:00:00 2001 From: taks <857tn859@gmail.com> Date: Fri, 22 Nov 2024 17:58:50 +0900 Subject: [PATCH 2/3] Changed to use try_lock() in BLECharacteristic.handle_gap_event --- src/server/ble_characteristic.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/server/ble_characteristic.rs b/src/server/ble_characteristic.rs index 55d9d3b..1b4b588 100644 --- a/src/server/ble_characteristic.rs +++ b/src/server/ble_characteristic.rs @@ -323,7 +323,9 @@ impl BLECharacteristic { let ctxt = unsafe { &*ctxt }; let mutex = unsafe { voidp_to_ref::>(arg) }; - let mut characteristic = mutex.lock(); + let Some(mut characteristic) = mutex.try_lock() else { + return sys::BLE_ATT_ERR_UNLIKELY as _; + }; if unsafe { sys::ble_uuid_cmp((*ctxt.__bindgen_anon_1.chr).uuid, &characteristic.uuid.u) != 0 } { From 6a0a32eb3cf0b0782e52da391e4ba4272e57da84 Mon Sep 17 00:00:00 2001 From: taks <857tn859@gmail.com> Date: Fri, 22 Nov 2024 18:13:15 +0900 Subject: [PATCH 3/3] CI: Changed fail-fast to false --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 809f96d..2020759 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -16,7 +16,7 @@ jobs: build: runs-on: ubuntu-latest strategy: - fail-fast: true + fail-fast: false matrix: include: - target: riscv32imc-esp-espidf