summaryrefslogtreecommitdiffstats
path: root/c/src/exec/score/src/coremutexseize.c
diff options
context:
space:
mode:
authorJoel Sherrill <joel.sherrill@OARcorp.com>2001-08-30 18:33:57 +0000
committerJoel Sherrill <joel.sherrill@OARcorp.com>2001-08-30 18:33:57 +0000
commitfb1d8f81a0e38540fb470da89d044dd28b0134ad (patch)
treecaa751896d100e3e7eaf54fa4edfe18bb8454daf /c/src/exec/score/src/coremutexseize.c
parent2001-08-30 Joel Sherrill <joel@OARcorp.com> (diff)
downloadrtems-fb1d8f81a0e38540fb470da89d044dd28b0134ad.tar.bz2
2001-08-30 Joel Sherrill <joel@OARcorp.com>
* src/coremutex.c, src/coremutexseize.c, src/coremutexsurrender.c, inline/rtems/score/coremutex.inl: 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.
Diffstat (limited to 'c/src/exec/score/src/coremutexseize.c')
-rw-r--r--c/src/exec/score/src/coremutexseize.c78
1 files changed, 44 insertions, 34 deletions
diff --git a/c/src/exec/score/src/coremutexseize.c b/c/src/exec/score/src/coremutexseize.c
index a4aadb7410..2fb2fc27e9 100644
--- a/c/src/exec/score/src/coremutexseize.c
+++ b/c/src/exec/score/src/coremutexseize.c
@@ -43,41 +43,33 @@ void _CORE_mutex_Seize_interrupt_blocking(
Thread_Control *executing;
executing = _Thread_Executing;
- switch ( the_mutex->Attributes.discipline ) {
- case CORE_MUTEX_DISCIPLINES_FIFO:
- case CORE_MUTEX_DISCIPLINES_PRIORITY:
- case CORE_MUTEX_DISCIPLINES_PRIORITY_CEILING:
- break;
- case CORE_MUTEX_DISCIPLINES_PRIORITY_INHERIT:
- if ( the_mutex->holder->current_priority > executing->current_priority ) {
- _Thread_Change_priority(
- the_mutex->holder,
- executing->current_priority,
- FALSE
- );
- }
- break;
+ if ( _CORE_mutex_Is_inherit_priority( &the_mutex->Attributes ) ) {
+ if ( the_mutex->holder->current_priority > executing->current_priority ) {
+ _Thread_Change_priority(
+ the_mutex->holder,
+ executing->current_priority,
+ FALSE
+ );
+ }
}
the_mutex->blocked_count++;
_Thread_queue_Enqueue( &the_mutex->Wait_queue, timeout );
if ( _Thread_Executing->Wait.return_code == CORE_MUTEX_STATUS_SUCCESSFUL ) {
- switch ( the_mutex->Attributes.discipline ) {
- case CORE_MUTEX_DISCIPLINES_FIFO:
- case CORE_MUTEX_DISCIPLINES_PRIORITY:
- case CORE_MUTEX_DISCIPLINES_PRIORITY_INHERIT:
- break;
- case CORE_MUTEX_DISCIPLINES_PRIORITY_CEILING:
- if ( the_mutex->Attributes.priority_ceiling <
- executing->current_priority ) {
- _Thread_Change_priority(
- executing,
- the_mutex->Attributes.priority_ceiling,
- FALSE
- );
- };
- break;
+ /*
+ * if CORE_MUTEX_DISCIPLINES_PRIORITY_INHERIT then nothing to do
+ * because this task is already the highest priority.
+ */
+
+ if ( _CORE_mutex_Is_priority_ceiling( &the_mutex->Attributes ) ) {
+ if (the_mutex->Attributes.priority_ceiling < executing->current_priority){
+ _Thread_Change_priority(
+ executing,
+ the_mutex->Attributes.priority_ceiling,
+ FALSE
+ );
+ }
}
}
_Thread_Enable_dispatch();
@@ -101,11 +93,13 @@ int _CORE_mutex_Seize_interrupt_trylock(
the_mutex->holder = executing;
the_mutex->holder_id = executing->Object.id;
the_mutex->nest_count = 1;
- executing->resource_count++;
- if ( the_mutex->Attributes.discipline !=
- CORE_MUTEX_DISCIPLINES_PRIORITY_CEILING ) {
- _ISR_Enable( level );
- return 0;
+ if ( _CORE_mutex_Is_inherit_priority( &the_mutex->Attributes ) ||
+ _CORE_mutex_Is_priority_ceiling( &the_mutex->Attributes ) )
+ executing->resource_count++;
+
+ if ( !_CORE_mutex_Is_priority_ceiling( &the_mutex->Attributes ) ) {
+ _ISR_Enable( level );
+ return 0;
}
/* else must be CORE_MUTEX_DISCIPLINES_PRIORITY_CEILING */
{
@@ -139,6 +133,22 @@ int _CORE_mutex_Seize_interrupt_trylock(
}
return 0;
}
+
+ if ( _Thread_Is_executing( the_mutex->holder ) ) {
+ switch ( the_mutex->Attributes.lock_nesting_behavior ) {
+ case CORE_MUTEX_NESTING_ACQUIRES:
+ the_mutex->nest_count++;
+ _ISR_Enable( level );
+ return 0;
+ case CORE_MUTEX_NESTING_IS_ERROR:
+ executing->Wait.return_code = CORE_MUTEX_STATUS_NESTING_NOT_ALLOWED;
+ _ISR_Enable( level );
+ return 0;
+ case CORE_MUTEX_NESTING_BLOCKS:
+ break;
+ }
+ }
+
return 1;
}
#endif