mirror of
https://gitlab.rtems.org/rtems/rtos/rtems.git
synced 2025-12-26 06:08:20 +00:00
score: PR2179: Fix initially locked PI mutex
This commit is contained in:
@@ -59,14 +59,19 @@ CORE_mutex_Status _CORE_mutex_Initialize(
|
||||
the_mutex->blocked_count = 0;
|
||||
|
||||
if ( initial_lock == CORE_MUTEX_LOCKED ) {
|
||||
bool is_priority_ceiling =
|
||||
_CORE_mutex_Is_priority_ceiling( &the_mutex->Attributes );
|
||||
|
||||
the_mutex->nest_count = 1;
|
||||
the_mutex->holder = _Thread_Executing;
|
||||
the_mutex->holder_id = _Thread_Executing->Object.id;
|
||||
if ( _CORE_mutex_Is_inherit_priority( &the_mutex->Attributes ) ||
|
||||
_CORE_mutex_Is_priority_ceiling( &the_mutex->Attributes ) ) {
|
||||
|
||||
if ( is_priority_ceiling ||
|
||||
_CORE_mutex_Is_inherit_priority( &the_mutex->Attributes ) ) {
|
||||
Priority_Control ceiling = the_mutex->Attributes.priority_ceiling;
|
||||
|
||||
if ( _Thread_Executing->current_priority < ceiling )
|
||||
if ( is_priority_ceiling &&
|
||||
_Thread_Executing->current_priority < ceiling )
|
||||
return CORE_MUTEX_STATUS_CEILING_VIOLATED;
|
||||
#ifdef __RTEMS_STRICT_ORDER_MUTEX__
|
||||
_Chain_Prepend_unprotected( &_Thread_Executing->lock_mutex,
|
||||
@@ -75,7 +80,8 @@ CORE_mutex_Status _CORE_mutex_Initialize(
|
||||
#endif
|
||||
|
||||
_Thread_Executing->resource_count++;
|
||||
_Thread_Change_priority( _Thread_Executing, ceiling, false );
|
||||
if ( is_priority_ceiling )
|
||||
_Thread_Change_priority( _Thread_Executing, ceiling, false );
|
||||
}
|
||||
} else {
|
||||
the_mutex->nest_count = 0;
|
||||
|
||||
@@ -11,6 +11,40 @@
|
||||
|
||||
#include <tmacros.h>
|
||||
|
||||
static void test_create_initially_locked_prio_inherit_sema(void)
|
||||
{
|
||||
rtems_status_code sc;
|
||||
rtems_id id;
|
||||
rtems_task_priority prio_a;
|
||||
rtems_task_priority prio_b;
|
||||
rtems_task_priority prio_ceiling = 0;
|
||||
|
||||
sc = rtems_task_set_priority(RTEMS_SELF, RTEMS_CURRENT_PRIORITY, &prio_a);
|
||||
rtems_test_assert(sc == RTEMS_SUCCESSFUL);
|
||||
|
||||
rtems_test_assert(prio_a != prio_ceiling);
|
||||
|
||||
sc = rtems_semaphore_create(
|
||||
rtems_build_name( 'S', 'E', 'M', 'A' ),
|
||||
0,
|
||||
RTEMS_BINARY_SEMAPHORE | RTEMS_PRIORITY | RTEMS_INHERIT_PRIORITY,
|
||||
prio_ceiling,
|
||||
&id
|
||||
);
|
||||
rtems_test_assert(sc == RTEMS_SUCCESSFUL);
|
||||
|
||||
sc = rtems_task_set_priority(RTEMS_SELF, RTEMS_CURRENT_PRIORITY, &prio_b);
|
||||
rtems_test_assert(sc == RTEMS_SUCCESSFUL);
|
||||
|
||||
rtems_test_assert(prio_a == prio_b);
|
||||
|
||||
sc = rtems_semaphore_release(id);
|
||||
rtems_test_assert(sc == RTEMS_SUCCESSFUL);
|
||||
|
||||
sc = rtems_semaphore_delete(id);
|
||||
rtems_test_assert(sc == RTEMS_SUCCESSFUL);
|
||||
}
|
||||
|
||||
rtems_task Init(
|
||||
rtems_task_argument argument
|
||||
)
|
||||
@@ -50,6 +84,8 @@ rtems_task Init(
|
||||
sc = rtems_semaphore_release( mutex );
|
||||
directive_failed( sc, "rtems_semaphore_release" );
|
||||
|
||||
test_create_initially_locked_prio_inherit_sema();
|
||||
|
||||
puts( "*** END OF TEST 51 ***" );
|
||||
rtems_test_exit( 0 );
|
||||
}
|
||||
|
||||
@@ -26,3 +26,6 @@ concepts:
|
||||
|
||||
+ Ensure the when the binary semaphore lock fails to acquire the mutex,
|
||||
it is an error to release it since the lock failed.
|
||||
|
||||
+ Verify that creation of an initially locked priority inheritance mutex does
|
||||
not change the priority of the executing thread.
|
||||
|
||||
Reference in New Issue
Block a user