This is an automated email from the ASF dual-hosted git repository.

janc pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-nimble.git


The following commit(s) were added to refs/heads/master by this push:
     new 9d4f474b porting/linux: fix deadlock in ble_npl_hw_enter_critical
9d4f474b is described below

commit 9d4f474bf8c867a289e8111aa1cc43fedf7b0b62
Author: Hang Fan <fanha...@gmail.com>
AuthorDate: Sun Sep 10 14:33:07 2023 +0800

    porting/linux: fix deadlock in ble_npl_hw_enter_critical
    
    Fix wrong mutex attributes in pthread_mutexattr_settype.
    It can cause deadlock after locked.
    
    Signed-off-by: Hang Fan <fanha...@gmail.com>
---
 porting/npl/linux/src/os_atomic.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/porting/npl/linux/src/os_atomic.c 
b/porting/npl/linux/src/os_atomic.c
index b01e234b..743a8470 100644
--- a/porting/npl/linux/src/os_atomic.c
+++ b/porting/npl/linux/src/os_atomic.c
@@ -23,21 +23,21 @@
 
 #include "nimble/nimble_npl.h"
 
-static pthread_mutex_t s_mutex = PTHREAD_MUTEX_INITIALIZER;
+static struct ble_npl_mutex s_mutex;
 static uint8_t s_mutex_inited = 0;
 
 uint32_t ble_npl_hw_enter_critical(void)
 {
     if( !s_mutex_inited ) {
-        pthread_mutexattr_settype(&s_mutex, PTHREAD_MUTEX_RECURSIVE);
+        ble_npl_mutex_init(&s_mutex);
         s_mutex_inited = 1;
     }
 
-    pthread_mutex_lock(&s_mutex);
+    pthread_mutex_lock(&s_mutex.lock);
     return 0;
 }
 
 void ble_npl_hw_exit_critical(uint32_t ctx)
 {
-    pthread_mutex_unlock(&s_mutex);
+    pthread_mutex_unlock(&s_mutex.lock);
 }

Reply via email to