forked from Imagelibrary/rtems
2001-08-30 Joel Sherrill <joel@OARcorp.com>
* src/coremutex.c, src/coremutexseize.c, src/coremutexsurrender.c: The per thread field resource_count should only be manipulated when a mutex is priority ceiling or priority inherit. This was reported by Chris Johns <ccj@acm.org> who also noticed that the use of switches for all disciplines generated less efficient code than using explicit tests for the one or two cases we were really interested in. Further review of his modifications made it apparent that the "isa" methods to test mutex discipline were not being used so this modification was swept into the code as well.
This commit is contained in:
@@ -72,7 +72,9 @@ void _CORE_mutex_Initialize(
|
|||||||
the_mutex->nest_count = 1;
|
the_mutex->nest_count = 1;
|
||||||
the_mutex->holder = _Thread_Executing;
|
the_mutex->holder = _Thread_Executing;
|
||||||
the_mutex->holder_id = _Thread_Executing->Object.id;
|
the_mutex->holder_id = _Thread_Executing->Object.id;
|
||||||
_Thread_Executing->resource_count++;
|
if ( _CORE_mutex_Is_inherit_priority( &the_mutex->Attributes ) ||
|
||||||
|
_CORE_mutex_Is_priority_ceiling( &the_mutex->Attributes ) )
|
||||||
|
_Thread_Executing->resource_count++;
|
||||||
} else {
|
} else {
|
||||||
the_mutex->nest_count = 0;
|
the_mutex->nest_count = 0;
|
||||||
the_mutex->holder = NULL;
|
the_mutex->holder = NULL;
|
||||||
|
|||||||
@@ -53,17 +53,11 @@ void _CORE_mutex_Seize(
|
|||||||
ISR_Level level;
|
ISR_Level level;
|
||||||
|
|
||||||
executing = _Thread_Executing;
|
executing = _Thread_Executing;
|
||||||
switch ( the_mutex->Attributes.discipline ) {
|
if ( _CORE_mutex_Is_priority_ceiling( &the_mutex->Attributes ) ) {
|
||||||
case CORE_MUTEX_DISCIPLINES_FIFO:
|
if ( executing->current_priority < the_mutex->Attributes.priority_ceiling) {
|
||||||
case CORE_MUTEX_DISCIPLINES_PRIORITY:
|
executing->Wait.return_code = CORE_MUTEX_STATUS_CEILING_VIOLATED;
|
||||||
case CORE_MUTEX_DISCIPLINES_PRIORITY_INHERIT:
|
return;
|
||||||
break;
|
}
|
||||||
case CORE_MUTEX_DISCIPLINES_PRIORITY_CEILING:
|
|
||||||
if ( executing->current_priority <
|
|
||||||
the_mutex->Attributes.priority_ceiling) {
|
|
||||||
executing->Wait.return_code = CORE_MUTEX_STATUS_CEILING_VIOLATED;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
executing->Wait.return_code = CORE_MUTEX_STATUS_SUCCESSFUL;
|
executing->Wait.return_code = CORE_MUTEX_STATUS_SUCCESSFUL;
|
||||||
_ISR_Disable( level );
|
_ISR_Disable( level );
|
||||||
@@ -72,17 +66,17 @@ void _CORE_mutex_Seize(
|
|||||||
the_mutex->holder = executing;
|
the_mutex->holder = executing;
|
||||||
the_mutex->holder_id = executing->Object.id;
|
the_mutex->holder_id = executing->Object.id;
|
||||||
the_mutex->nest_count = 1;
|
the_mutex->nest_count = 1;
|
||||||
executing->resource_count++;
|
if ( _CORE_mutex_Is_priority_ceiling( &the_mutex->Attributes ) ||
|
||||||
|
_CORE_mutex_Is_inherit_priority( &the_mutex->Attributes ) )
|
||||||
|
executing->resource_count++;
|
||||||
_ISR_Enable( level );
|
_ISR_Enable( level );
|
||||||
switch ( the_mutex->Attributes.discipline ) {
|
/*
|
||||||
case CORE_MUTEX_DISCIPLINES_FIFO:
|
* if CORE_MUTEX_DISCIPLINES_PRIORITY_INHERIT then nothing to do
|
||||||
case CORE_MUTEX_DISCIPLINES_PRIORITY:
|
* because this task is already the highest priority.
|
||||||
case CORE_MUTEX_DISCIPLINES_PRIORITY_INHERIT:
|
*/
|
||||||
/* already the highest priority */
|
|
||||||
break;
|
if ( _CORE_mutex_Is_priority_ceiling( &the_mutex->Attributes ) ) {
|
||||||
case CORE_MUTEX_DISCIPLINES_PRIORITY_CEILING:
|
if (the_mutex->Attributes.priority_ceiling < executing->current_priority){
|
||||||
if ( the_mutex->Attributes.priority_ceiling <
|
|
||||||
executing->current_priority ) {
|
|
||||||
_Thread_Change_priority(
|
_Thread_Change_priority(
|
||||||
the_mutex->holder,
|
the_mutex->holder,
|
||||||
the_mutex->Attributes.priority_ceiling,
|
the_mutex->Attributes.priority_ceiling,
|
||||||
@@ -120,40 +114,27 @@ void _CORE_mutex_Seize(
|
|||||||
executing->Wait.id = id;
|
executing->Wait.id = id;
|
||||||
_ISR_Enable( level );
|
_ISR_Enable( level );
|
||||||
|
|
||||||
switch ( the_mutex->Attributes.discipline ) {
|
if ( _CORE_mutex_Is_inherit_priority( &the_mutex->Attributes ) ) {
|
||||||
case CORE_MUTEX_DISCIPLINES_FIFO:
|
if ( the_mutex->holder->current_priority > executing->current_priority ) {
|
||||||
case CORE_MUTEX_DISCIPLINES_PRIORITY:
|
_Thread_Change_priority(
|
||||||
case CORE_MUTEX_DISCIPLINES_PRIORITY_CEILING:
|
the_mutex->holder,
|
||||||
break;
|
executing->current_priority,
|
||||||
case CORE_MUTEX_DISCIPLINES_PRIORITY_INHERIT:
|
FALSE
|
||||||
if ( the_mutex->holder->current_priority > executing->current_priority ) {
|
);
|
||||||
_Thread_Change_priority(
|
}
|
||||||
the_mutex->holder,
|
|
||||||
executing->current_priority,
|
|
||||||
FALSE
|
|
||||||
);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_Thread_queue_Enqueue( &the_mutex->Wait_queue, timeout );
|
_Thread_queue_Enqueue( &the_mutex->Wait_queue, timeout );
|
||||||
|
|
||||||
if ( _Thread_Executing->Wait.return_code == CORE_MUTEX_STATUS_SUCCESSFUL ) {
|
if ( _Thread_Executing->Wait.return_code == CORE_MUTEX_STATUS_SUCCESSFUL ) {
|
||||||
switch ( the_mutex->Attributes.discipline ) {
|
if ( _CORE_mutex_Is_priority_ceiling( &the_mutex->Attributes ) ) {
|
||||||
case CORE_MUTEX_DISCIPLINES_FIFO:
|
if (the_mutex->Attributes.priority_ceiling < executing->current_priority){
|
||||||
case CORE_MUTEX_DISCIPLINES_PRIORITY:
|
_Thread_Change_priority(
|
||||||
case CORE_MUTEX_DISCIPLINES_PRIORITY_INHERIT:
|
executing,
|
||||||
break;
|
the_mutex->Attributes.priority_ceiling,
|
||||||
case CORE_MUTEX_DISCIPLINES_PRIORITY_CEILING:
|
FALSE
|
||||||
if ( the_mutex->Attributes.priority_ceiling <
|
);
|
||||||
executing->current_priority ) {
|
}
|
||||||
_Thread_Change_priority(
|
|
||||||
executing,
|
|
||||||
the_mutex->Attributes.priority_ceiling,
|
|
||||||
FALSE
|
|
||||||
);
|
|
||||||
};
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -86,7 +86,9 @@ CORE_mutex_Status _CORE_mutex_Surrender(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
holder->resource_count--;
|
if ( _CORE_mutex_Is_inherit_priority( &the_mutex->Attributes ) ||
|
||||||
|
_CORE_mutex_Is_priority_ceiling( &the_mutex->Attributes ) )
|
||||||
|
holder->resource_count--;
|
||||||
the_mutex->holder = NULL;
|
the_mutex->holder = NULL;
|
||||||
the_mutex->holder_id = 0;
|
the_mutex->holder_id = 0;
|
||||||
|
|
||||||
@@ -96,20 +98,14 @@ CORE_mutex_Status _CORE_mutex_Surrender(
|
|||||||
* mutex (i.e. resource) this task has.
|
* mutex (i.e. resource) this task has.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
switch ( the_mutex->Attributes.discipline ) {
|
if ( _CORE_mutex_Is_inherit_priority( &the_mutex->Attributes ) ||
|
||||||
case CORE_MUTEX_DISCIPLINES_FIFO:
|
_CORE_mutex_Is_priority_ceiling( &the_mutex->Attributes ) ) {
|
||||||
case CORE_MUTEX_DISCIPLINES_PRIORITY:
|
if ( holder->resource_count == 0 &&
|
||||||
break;
|
holder->real_priority != holder->current_priority ) {
|
||||||
case CORE_MUTEX_DISCIPLINES_PRIORITY_CEILING:
|
_Thread_Change_priority( holder, holder->real_priority, TRUE );
|
||||||
case CORE_MUTEX_DISCIPLINES_PRIORITY_INHERIT:
|
}
|
||||||
if ( holder->resource_count == 0 &&
|
|
||||||
holder->real_priority != holder->current_priority ) {
|
|
||||||
_Thread_Change_priority( holder, holder->real_priority, TRUE );
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if ( ( the_thread = _Thread_queue_Dequeue( &the_mutex->Wait_queue ) ) ) {
|
if ( ( the_thread = _Thread_queue_Dequeue( &the_mutex->Wait_queue ) ) ) {
|
||||||
|
|
||||||
#if defined(RTEMS_MULTIPROCESSING)
|
#if defined(RTEMS_MULTIPROCESSING)
|
||||||
|
|||||||
Reference in New Issue
Block a user