- Index: Base/PosixSystem.cpp
- ===================================================================
- --- Base/PosixSystem.cpp (revision 9635)
- +++ Base/PosixSystem.cpp (working copy)
- @@ -1222,6 +1222,7 @@
- (void)pthread_mutex_destroy(&event->crit);
- delete event;
- }
- +
- return 0 == errorVal ? event : NULL;
- }
- Index: Boost/boost_1_33_1/boost/detail/atomic_count_pthreads.hpp
- ===================================================================
- --- Boost/boost_1_33_1/boost/detail/atomic_count_pthreads.hpp (revision 9635)
- +++ Boost/boost_1_33_1/boost/detail/atomic_count_pthreads.hpp (working copy)
- @@ -54,7 +54,15 @@
- explicit atomic_count(long v): value_(v)
- {
- - pthread_mutex_init(&mutex_, 0);
- + pthread_mutexattr_t muattr;
- + /*
- + * fixme: replace (void)-casts with real error checks
- + * throwing real C++ exceptions
- + */
- + (void)pthread_mutexattr_init(&muattr);
- + (void)pthread_mutexattr_setprotocol(&muattr, PTHREAD_PRIO_INHERIT);
- + (void)pthread_mutex_init(&mutex_, &muattr);
- + (void)pthread_mutexattr_destroy(&muattr);
- }
- ~atomic_count()
- Index: Communication/CifXTCPServer/OS_Specific.c
- ===================================================================
- --- Communication/CifXTCPServer/OS_Specific.c (revision 9635)
- +++ Communication/CifXTCPServer/OS_Specific.c (working copy)
- @@ -116,6 +116,13 @@
- perror("set mutex recursive");
- return NULL;
- }
- +
- + if( pthread_mutexattr_setprotocol(&mta, PTHREAD_PRIO_INHERIT) != 0 )
- + {
- + perror("set mutex protocol PTHREAD_PRIO_INHERIT");
- + return NULL;
- + }
- +
- g_ptMutex =(pthread_mutex_t*)malloc( sizeof(pthread_mutex_t) );
- if( g_ptMutex == NULL )
- {
- Index: Communication/ESDK_src/Platform/Linux/platform.c
- ===================================================================
- --- Communication/ESDK_src/Platform/Linux/platform.c (revision 9635)
- +++ Communication/ESDK_src/Platform/Linux/platform.c (working copy)
- @@ -646,8 +646,15 @@
- if(pMutex != NULL)
- {
- - pthread_mutex_init(pMutex, NULL);
- - }
- + pthread_mutexattr_t attr;
- + /*
- + * fixme: replace (void)-casts with real error checks
- + */
- + (void)pthread_mutexattr_init(&attr);
- + (void)pthread_mutexattr_setprotocol(&attr, PTHREAD_PRIO_INHERIT);
- + (void)pthread_mutex_init(pMutex, &attr);
- + (void)pthread_mutexattr_destroy(&attr);
- + }
- return(pMutex);
- }
- Index: Communication/Encryption/mbedtls/crypto/library/threading.c
- ===================================================================
- --- Communication/Encryption/mbedtls/crypto/library/threading.c (revision 9635)
- +++ Communication/Encryption/mbedtls/crypto/library/threading.c (working copy)
- @@ -70,10 +70,23 @@
- #if defined(MBEDTLS_THREADING_PTHREAD)
- static void threading_mutex_init_pthread( mbedtls_threading_mutex_t *mutex )
- {
- - if( mutex == NULL )
- - return;
- + pthread_mutexattr_t attr;
- - mutex->is_valid = pthread_mutex_init( &mutex->mutex, NULL ) == 0;
- + if (mutex == NULL)
- + return;
- + if (pthread_mutexattr_init(&attr) != 0)
- + return;
- + if (pthread_mutexattr_setprotocol(&attr, PTHREAD_PRIO_INHERIT) != 0)
- + goto err;
- + if (pthread_mutex_init(&mutex->mutex, &attr) != 0)
- + goto err;
- + (void)pthread_mutexattr_destroy(&attr);
- +
- + mutex->is_valid = true;
- + return;
- +err:
- + (void)pthread_mutexattr_destroy(&attr);
- + mutex->is_valid = false;
- }
- static void threading_mutex_free_pthread( mbedtls_threading_mutex_t *mutex )
- Index: Communication/Sercos3Base/src/Driver/SERC_driver.cpp
- ===================================================================
- --- Communication/Sercos3Base/src/Driver/SERC_driver.cpp (revision 9635)
- +++ Communication/Sercos3Base/src/Driver/SERC_driver.cpp (working copy)
- @@ -197,7 +197,14 @@
- pCard->pDmaRegister = 0;
- }
- - pthread_mutex_init(&cards->card[card].mutex, 0);
- + pthread_mutexattr_t muattr;
- + /*
- + * fixme: replace (void)-casts with real error checks
- + */
- + (void)pthread_mutexattr_init(&muattr);
- + (void)pthread_mutexattr_setprotocol(&muattr, PTHREAD_PRIO_INHERIT);
- + (void)pthread_mutex_init(&cards->card[card].mutex, &muattr);
- + (void)pthread_mutexattr_destroy(&muattr);
- cards->card[card].param.sched_priority = DEFAULT_CYCLE_PRIO;
- cards->card[card].nrt_param.sched_priority = DEFAULT_NRT_PRIO;
- Index: Communication/Sercos3Base/src/Driver/SERC_nrt.cpp
- ===================================================================
- --- Communication/Sercos3Base/src/Driver/SERC_nrt.cpp (revision 9635)
- +++ Communication/Sercos3Base/src/Driver/SERC_nrt.cpp (working copy)
- @@ -673,7 +673,13 @@
- *pNrt_fd = fd;
- #if 0
- pthread_attr_t attr;
- - pthread_mutex_init(&mutex, 0);
- + pthread_mutexattr_t muattr;
- +
- + pthread_mutexattr_init(&muattr);
- + pthread_mutexattr_setprotocol(&muattr, PTHREAD_PRIO_INHERIT);
- + pthread_mutex_init(&mutex, &muattr);
- + pthread_mutexattr_destroy(&muattr);
- +
- pthread_cond_init(&nrt_cond, 0);
- pthread_attr_init(&attr);
- Index: Communication/Sercos3Base/src/Driver/igb.c
- ===================================================================
- --- Communication/Sercos3Base/src/Driver/igb.c (revision 9635)
- +++ Communication/Sercos3Base/src/Driver/igb.c (working copy)
- @@ -2545,6 +2545,10 @@
- if (pthread_mutexattr_setrobust(&attr, PTHREAD_MUTEX_ROBUST) != 0)
- goto err;
- + // to avoid priority inversion problems, for example in realtime code
- + if (pthread_mutexattr_setprotocol(&attr, PTHREAD_PRIO_INHERIT) != 0)
- + goto err;
- +
- if (pthread_mutex_init(adapter->memlock, &attr) != 0)
- goto err;
- }
- Index: Communication/libcifx/src/OS_Linux.c
- ===================================================================
- --- Communication/libcifx/src/OS_Linux.c (revision 9635)
- +++ Communication/libcifx/src/OS_Linux.c (working copy)
- @@ -529,16 +529,26 @@
- if( pthread_mutexattr_init(&attr) != 0 )
- {
- perror("mutex_attr_init failed");
- - goto err_out;
- + goto err_out1;
- }
- +
- + if( pthread_mutexattr_setprotocol(&attr, PTHREAD_PRIO_INHERIT) )
- + {
- + perror("Mutex setprotocol PTHREAD_PRIO_INHERIT failed");
- + goto err_out2;
- + }
- +
- if( pthread_mutex_init(mut, &attr) != 0 )
- {
- perror("CreateMutex failed");
- - goto err_out;
- + goto err_out2;
- }
- + (void)pthread_mutexattr_destroy(&attr);
- return (void*) mut;
- -err_out:
- +err_out2:
- + (void)pthread_mutexattr_destroy(&attr);
- +err_out1:
- free(mut);
- return NULL;
- }
rds: Add PTHREAD_PRIO_INHERIT to all pthread mutex usage
Posted by Anonymous on Tue 2nd Aug 2022 17:13
raw | new post
modification of post by Anonymous (view diff)
Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.