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 e718a2fb porting/npl/linux: support C library (for example:musl) which 
didn't have PTHREAD_MUTEX_RECURSIVE_NP
e718a2fb is described below

commit e718a2fb22a56141ddb6a63cab875489a6a08f25
Author: [email protected] <[email protected]>
AuthorDate: Mon Sep 27 07:41:45 2021 -0400

    porting/npl/linux: support C library (for example:musl) which didn't have 
PTHREAD_MUTEX_RECURSIVE_NP
---
 porting/npl/linux/src/os_atomic.c | 8 +++++++-
 porting/npl/linux/src/os_mutex.c  | 2 +-
 2 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/porting/npl/linux/src/os_atomic.c 
b/porting/npl/linux/src/os_atomic.c
index 51260149..b01e234b 100644
--- a/porting/npl/linux/src/os_atomic.c
+++ b/porting/npl/linux/src/os_atomic.c
@@ -23,10 +23,16 @@
 
 #include "nimble/nimble_npl.h"
 
-static pthread_mutex_t s_mutex = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP;
+static pthread_mutex_t s_mutex = PTHREAD_MUTEX_INITIALIZER;
+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);
+        s_mutex_inited = 1;
+    }
+
     pthread_mutex_lock(&s_mutex);
     return 0;
 }
diff --git a/porting/npl/linux/src/os_mutex.c b/porting/npl/linux/src/os_mutex.c
index c7d6190e..86cad965 100644
--- a/porting/npl/linux/src/os_mutex.c
+++ b/porting/npl/linux/src/os_mutex.c
@@ -31,7 +31,7 @@ ble_npl_mutex_init(struct ble_npl_mutex *mu)
     }
 
     pthread_mutexattr_init(&mu->attr);
-    pthread_mutexattr_settype(&mu->attr, PTHREAD_MUTEX_RECURSIVE_NP);
+    pthread_mutexattr_settype(&mu->attr, PTHREAD_MUTEX_RECURSIVE);
     pthread_mutex_init(&mu->lock, &mu->attr);
 
     return BLE_NPL_OK;

Reply via email to