1Remove use of DIRECT_RECURSIVE_MUTEX_INITIALIZER its not portable 2use portable way to initialize recursive mutex using pthread_once() and direct_recursive_mutex_init() 3 4Upstream-Status: Pending 5Signed-off-by: Khem Raj <raj.khem@gmail.com> 6Index: DirectFB-1.7.7/lib/direct/os/linux/glibc/mutex.h 7=================================================================== 8--- DirectFB-1.7.7.orig/lib/direct/os/linux/glibc/mutex.h 9+++ DirectFB-1.7.7/lib/direct/os/linux/glibc/mutex.h 10@@ -46,7 +46,6 @@ struct __D_DirectMutex { 11 /**********************************************************************************************************************/ 12 13 #define DIRECT_MUTEX_INITIALIZER(name) { PTHREAD_MUTEX_INITIALIZER } 14-#define DIRECT_RECURSIVE_MUTEX_INITIALIZER(name) { PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP } 15 16 #endif 17 18Index: DirectFB-1.7.7/lib/direct/trace.c 19=================================================================== 20--- DirectFB-1.7.7.orig/lib/direct/trace.c 21+++ DirectFB-1.7.7/lib/direct/trace.c 22@@ -89,8 +89,15 @@ struct __D_DirectTraceBuffer { 23 /**************************************************************************************************/ 24 25 static DirectLink *buffers; 26-static DirectMutex buffers_lock = DIRECT_RECURSIVE_MUTEX_INITIALIZER(buffers_lock); 27 28+static pthread_once_t buffers_lock_init_once = PTHREAD_ONCE_INIT; 29+static DirectMutex buffers_lock; 30+ 31+static void 32+buffers_lock_init( void ) 33+{ 34+ direct_recursive_mutex_init(&buffers_lock); 35+} 36 /**************************************************************************************************/ 37 38 __dfb_no_instrument_function__ 39@@ -113,6 +120,7 @@ get_trace_buffer( void ) 40 41 D_MAGIC_SET( buffer, DirectTraceBuffer ); 42 43+ pthread_once(&buffers_lock_init_once, buffers_lock_init); 44 direct_mutex_lock( &buffers_lock ); 45 direct_list_append( &buffers, &buffer->link ); 46 direct_mutex_unlock( &buffers_lock ); 47@@ -138,8 +146,14 @@ typedef struct { 48 } SymbolTable; 49 50 static DirectLink *tables = NULL; 51-static DirectMutex tables_lock = DIRECT_RECURSIVE_MUTEX_INITIALIZER(tables_lock); 52+static pthread_once_t tables_lock_init_once = PTHREAD_ONCE_INIT; 53+static DirectMutex tables_lock; 54 55+static void 56+tables_lock_init( void ) 57+{ 58+ direct_recursive_mutex_init(&tabless_lock); 59+} 60 61 __dfb_no_instrument_function__ 62 static void 63@@ -370,6 +384,7 @@ direct_trace_lookup_symbol( const char * 64 Symbol *symbol; 65 SymbolTable *table; 66 67+ pthread_once(&tables_lock_init_once, tables_lock_init); 68 direct_mutex_lock( &tables_lock ); 69 70 table = find_table( filename ); 71@@ -514,6 +529,7 @@ direct_trace_print_stacks() 72 DirectTraceBuffer *b; 73 DirectTraceBuffer *buffer = get_trace_buffer(); 74 75+ pthread_once(&buffers_lock_init_once, buffers_lock_init); 76 direct_mutex_lock( &buffers_lock ); 77 78 if (buffer && buffer->level) 79@@ -611,6 +627,7 @@ direct_trace_free_buffer( DirectTraceBuf 80 D_MAGIC_ASSERT( buffer, DirectTraceBuffer ); 81 82 if (buffer->thread) { 83+ pthread_once(&buffers_lock_init_once, buffers_lock_init); 84 direct_mutex_lock( &buffers_lock ); 85 direct_list_remove( &buffers, &buffer->link ); 86 direct_mutex_unlock( &buffers_lock ); 87Index: DirectFB-1.7.7/src/directfb.c 88=================================================================== 89--- DirectFB-1.7.7.orig/src/directfb.c 90+++ DirectFB-1.7.7/src/directfb.c 91@@ -99,6 +99,15 @@ const unsigned int directfb_micro_versio 92 const unsigned int directfb_binary_age = DIRECTFB_BINARY_AGE; 93 const unsigned int directfb_interface_age = DIRECTFB_INTERFACE_AGE; 94 95+static pthread_once_t lock_init_once = PTHREAD_ONCE_INIT; 96+static DirectMutex lock; 97+ 98+static void 99+lock_init( void ) 100+{ 101+ direct_recursive_mutex_init(&lock); 102+} 103+ 104 const char * 105 DirectFBCheckVersion( unsigned int required_major, 106 unsigned int required_minor, 107@@ -215,8 +224,7 @@ DirectFBCreate( IDirectFB **interface_pt 108 if (dfb_config->remote.host) 109 return CreateRemote( dfb_config->remote.host, dfb_config->remote.port, interface_ptr ); 110 111- static DirectMutex lock = DIRECT_RECURSIVE_MUTEX_INITIALIZER(lock); 112- 113+ pthread_once(&lock_init_once, lock_init); 114 direct_mutex_lock( &lock ); 115 116 if (!dfb_config->no_singleton && idirectfb_singleton) { 117