You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by GitBox <gi...@apache.org> on 2021/10/05 14:48:46 UTC

[GitHub] [mynewt-nimble] gavin-yy commented on a change in pull request #1031: porting/npl/linux: support C library which didn't have PTHREAD_MUTEX_RECURSIVE_NP

gavin-yy commented on a change in pull request #1031:
URL: https://github.com/apache/mynewt-nimble/pull/1031#discussion_r722320357



##########
File path: porting/npl/linux/src/os_atomic.c
##########
@@ -22,10 +22,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 ) {

Review comment:
       pthread_mutexattr_settype() was just set a flag to the mutex attribute, so it should be fine i think ?   The race condition only occurs when 2 or more threads call ble_npl_hw_enter_critical() at the first time (and at the same time), if both threads write the mutex attribute to a const value, it should not cause any problem.
   
   If there is a OS/Platform init function exists (such as sysinit()), it is better to set mutex type in this function.  But i didn't find platform related init function for linux .




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@mynewt.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org