Changeset fb1d8f81 in rtems


Ignore:
Timestamp:
08/30/01 18:33:57 (22 years ago)
Author:
Joel Sherrill <joel.sherrill@…>
Branches:
4.10, 4.11, 4.8, 4.9, 5, master
Children:
7078fa2a
Parents:
760045f0
Message:

2001-08-30 Joel Sherrill <joel@…>

  • 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@…> 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.
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • c/src/exec/score/ChangeLog

    r760045f0 rfb1d8f81  
     1
     22001-08-30      Joel Sherrill <joel@OARcorp.com>
     3
     4        *  src/coremutex.c, src/coremutexseize.c, src/coremutexsurrender.c,
     5        inline/rtems/score/coremutex.inl: The per thread field resource_count
     6        should only be manipulated when a mutex is priority ceiling or
     7        priority inherit.  This was reported by Chris Johns <ccj@acm.org>
     8        who also noticed that the use of switches for all disciplines
     9        generated less efficient code than using explicit tests for the one
     10        or two cases we were really interested in.  Further review of his
     11        modifications made it apparent that the "isa" methods to test mutex
     12        discipline were not being used so this modification was swept into
     13        the code as well.
    114
    2152001-08-30      Joel Sherrill <joel@OARcorp.com>
  • c/src/exec/score/inline/rtems/score/coremutex.inl

    r760045f0 rfb1d8f81  
    135135    the_mutex->holder_id  = executing->Object.id;
    136136    the_mutex->nest_count = 1;
    137     executing->resource_count++;
    138     if ( the_mutex->Attributes.discipline !=
    139            CORE_MUTEX_DISCIPLINES_PRIORITY_CEILING ) {
     137    if ( _CORE_mutex_Is_inherit_priority( &the_mutex->Attributes ) ||
     138         _CORE_mutex_Is_priority_ceiling( &the_mutex->Attributes ) )
     139      executing->resource_count++;
     140    if ( !_CORE_mutex_Is_priority_ceiling( &the_mutex->Attributes ) ) {
    140141        _ISR_Enable( level );
    141142        return 0;
  • c/src/exec/score/src/coremutex.c

    r760045f0 rfb1d8f81  
    7474    the_mutex->holder     = _Thread_Executing;
    7575    the_mutex->holder_id  = _Thread_Executing->Object.id;
    76     _Thread_Executing->resource_count++;
     76    if ( _CORE_mutex_Is_inherit_priority( &the_mutex->Attributes ) ||
     77         _CORE_mutex_Is_priority_ceiling( &the_mutex->Attributes ) )
     78      _Thread_Executing->resource_count++;
    7779  } else {
    7880    the_mutex->nest_count = 0;
  • c/src/exec/score/src/coremutexseize.c

    r760045f0 rfb1d8f81  
    4444
    4545  executing = _Thread_Executing;
    46   switch ( the_mutex->Attributes.discipline ) {
    47     case CORE_MUTEX_DISCIPLINES_FIFO:
    48     case CORE_MUTEX_DISCIPLINES_PRIORITY:
    49     case CORE_MUTEX_DISCIPLINES_PRIORITY_CEILING:
    50       break;
    51     case CORE_MUTEX_DISCIPLINES_PRIORITY_INHERIT:
    52       if ( the_mutex->holder->current_priority > executing->current_priority ) {
    53         _Thread_Change_priority(
    54           the_mutex->holder,
    55           executing->current_priority,
    56           FALSE
    57         );
    58       }
    59       break;
     46  if ( _CORE_mutex_Is_inherit_priority( &the_mutex->Attributes ) ) {
     47    if ( the_mutex->holder->current_priority > executing->current_priority ) {
     48      _Thread_Change_priority(
     49        the_mutex->holder,
     50        executing->current_priority,
     51        FALSE
     52      );
     53    }
    6054  }
    6155
     
    6458
    6559  if ( _Thread_Executing->Wait.return_code == CORE_MUTEX_STATUS_SUCCESSFUL ) {
    66     switch ( the_mutex->Attributes.discipline ) {
    67       case CORE_MUTEX_DISCIPLINES_FIFO:
    68       case CORE_MUTEX_DISCIPLINES_PRIORITY:
    69       case CORE_MUTEX_DISCIPLINES_PRIORITY_INHERIT:
    70         break;
    71       case CORE_MUTEX_DISCIPLINES_PRIORITY_CEILING:
    72         if ( the_mutex->Attributes.priority_ceiling <
    73                                            executing->current_priority ) {
    74           _Thread_Change_priority(
    75             executing,
    76             the_mutex->Attributes.priority_ceiling,
    77             FALSE
    78           );
    79         };
    80         break;
     60    /*
     61     *  if CORE_MUTEX_DISCIPLINES_PRIORITY_INHERIT then nothing to do
     62     *  because this task is already the highest priority.
     63     */
     64
     65    if ( _CORE_mutex_Is_priority_ceiling( &the_mutex->Attributes ) ) {
     66      if (the_mutex->Attributes.priority_ceiling < executing->current_priority){
     67        _Thread_Change_priority(
     68          executing,
     69          the_mutex->Attributes.priority_ceiling,
     70          FALSE
     71        );
     72      }
    8173    }
    8274  }
     
    10294    the_mutex->holder_id  = executing->Object.id;
    10395    the_mutex->nest_count = 1;
    104     executing->resource_count++;
    105     if ( the_mutex->Attributes.discipline !=
    106            CORE_MUTEX_DISCIPLINES_PRIORITY_CEILING ) {
    107         _ISR_Enable( level );
    108         return 0;
     96    if ( _CORE_mutex_Is_inherit_priority( &the_mutex->Attributes ) ||
     97         _CORE_mutex_Is_priority_ceiling( &the_mutex->Attributes ) )
     98      executing->resource_count++;
     99
     100    if ( !_CORE_mutex_Is_priority_ceiling( &the_mutex->Attributes ) ) {
     101      _ISR_Enable( level );
     102      return 0;
    109103    }
    110104    /* else must be CORE_MUTEX_DISCIPLINES_PRIORITY_CEILING */
     
    140134    return 0;
    141135  }
     136
     137  if ( _Thread_Is_executing( the_mutex->holder ) ) {
     138    switch ( the_mutex->Attributes.lock_nesting_behavior ) {
     139      case CORE_MUTEX_NESTING_ACQUIRES:
     140        the_mutex->nest_count++;
     141        _ISR_Enable( level );
     142        return 0;
     143      case CORE_MUTEX_NESTING_IS_ERROR:
     144        executing->Wait.return_code = CORE_MUTEX_STATUS_NESTING_NOT_ALLOWED;
     145        _ISR_Enable( level );
     146        return 0;
     147      case CORE_MUTEX_NESTING_BLOCKS:
     148        break;
     149    }
     150  }
     151
    142152  return 1;
    143153}
  • c/src/exec/score/src/coremutexsurrender.c

    r760045f0 rfb1d8f81  
    8787  }
    8888
    89   holder->resource_count--;
     89  if ( _CORE_mutex_Is_inherit_priority( &the_mutex->Attributes ) ||
     90       _CORE_mutex_Is_priority_ceiling( &the_mutex->Attributes ) )
     91    holder->resource_count--;
    9092  the_mutex->holder    = NULL;
    9193  the_mutex->holder_id = 0;
     
    9799   */
    98100
    99   switch ( the_mutex->Attributes.discipline ) {
    100     case CORE_MUTEX_DISCIPLINES_FIFO:
    101     case CORE_MUTEX_DISCIPLINES_PRIORITY:
    102       break;
    103     case CORE_MUTEX_DISCIPLINES_PRIORITY_CEILING:
    104     case CORE_MUTEX_DISCIPLINES_PRIORITY_INHERIT:
    105       if ( holder->resource_count == 0 &&
    106            holder->real_priority != holder->current_priority ) {
    107          _Thread_Change_priority( holder, holder->real_priority, TRUE );
    108       }
    109       break;
     101  if ( _CORE_mutex_Is_inherit_priority( &the_mutex->Attributes ) ||
     102       _CORE_mutex_Is_priority_ceiling( &the_mutex->Attributes ) ) {
     103    if ( holder->resource_count == 0 &&
     104         holder->real_priority != holder->current_priority ) {
     105      _Thread_Change_priority( holder, holder->real_priority, TRUE );
     106    }
    110107  }
    111 
    112108
    113109  if ( ( the_thread = _Thread_queue_Dequeue( &the_mutex->Wait_queue ) ) ) {
     
    128124      the_mutex->holder     = the_thread;
    129125      the_mutex->holder_id  = the_thread->Object.id;
    130       the_thread->resource_count++;
     126      if ( _CORE_mutex_Is_inherit_priority( &the_mutex->Attributes ) ||
     127           _CORE_mutex_Is_priority_ceiling( &the_mutex->Attributes ) )
     128        the_thread->resource_count++;
    131129      the_mutex->nest_count = 1;
    132130
  • cpukit/score/ChangeLog

    r760045f0 rfb1d8f81  
     1
     22001-08-30      Joel Sherrill <joel@OARcorp.com>
     3
     4        *  src/coremutex.c, src/coremutexseize.c, src/coremutexsurrender.c,
     5        inline/rtems/score/coremutex.inl: The per thread field resource_count
     6        should only be manipulated when a mutex is priority ceiling or
     7        priority inherit.  This was reported by Chris Johns <ccj@acm.org>
     8        who also noticed that the use of switches for all disciplines
     9        generated less efficient code than using explicit tests for the one
     10        or two cases we were really interested in.  Further review of his
     11        modifications made it apparent that the "isa" methods to test mutex
     12        discipline were not being used so this modification was swept into
     13        the code as well.
    114
    2152001-08-30      Joel Sherrill <joel@OARcorp.com>
  • cpukit/score/inline/rtems/score/coremutex.inl

    r760045f0 rfb1d8f81  
    135135    the_mutex->holder_id  = executing->Object.id;
    136136    the_mutex->nest_count = 1;
    137     executing->resource_count++;
    138     if ( the_mutex->Attributes.discipline !=
    139            CORE_MUTEX_DISCIPLINES_PRIORITY_CEILING ) {
     137    if ( _CORE_mutex_Is_inherit_priority( &the_mutex->Attributes ) ||
     138         _CORE_mutex_Is_priority_ceiling( &the_mutex->Attributes ) )
     139      executing->resource_count++;
     140    if ( !_CORE_mutex_Is_priority_ceiling( &the_mutex->Attributes ) ) {
    140141        _ISR_Enable( level );
    141142        return 0;
  • cpukit/score/src/coremutex.c

    r760045f0 rfb1d8f81  
    7474    the_mutex->holder     = _Thread_Executing;
    7575    the_mutex->holder_id  = _Thread_Executing->Object.id;
    76     _Thread_Executing->resource_count++;
     76    if ( _CORE_mutex_Is_inherit_priority( &the_mutex->Attributes ) ||
     77         _CORE_mutex_Is_priority_ceiling( &the_mutex->Attributes ) )
     78      _Thread_Executing->resource_count++;
    7779  } else {
    7880    the_mutex->nest_count = 0;
  • cpukit/score/src/coremutexseize.c

    r760045f0 rfb1d8f81  
    4444
    4545  executing = _Thread_Executing;
    46   switch ( the_mutex->Attributes.discipline ) {
    47     case CORE_MUTEX_DISCIPLINES_FIFO:
    48     case CORE_MUTEX_DISCIPLINES_PRIORITY:
    49     case CORE_MUTEX_DISCIPLINES_PRIORITY_CEILING:
    50       break;
    51     case CORE_MUTEX_DISCIPLINES_PRIORITY_INHERIT:
    52       if ( the_mutex->holder->current_priority > executing->current_priority ) {
    53         _Thread_Change_priority(
    54           the_mutex->holder,
    55           executing->current_priority,
    56           FALSE
    57         );
    58       }
    59       break;
     46  if ( _CORE_mutex_Is_inherit_priority( &the_mutex->Attributes ) ) {
     47    if ( the_mutex->holder->current_priority > executing->current_priority ) {
     48      _Thread_Change_priority(
     49        the_mutex->holder,
     50        executing->current_priority,
     51        FALSE
     52      );
     53    }
    6054  }
    6155
     
    6458
    6559  if ( _Thread_Executing->Wait.return_code == CORE_MUTEX_STATUS_SUCCESSFUL ) {
    66     switch ( the_mutex->Attributes.discipline ) {
    67       case CORE_MUTEX_DISCIPLINES_FIFO:
    68       case CORE_MUTEX_DISCIPLINES_PRIORITY:
    69       case CORE_MUTEX_DISCIPLINES_PRIORITY_INHERIT:
    70         break;
    71       case CORE_MUTEX_DISCIPLINES_PRIORITY_CEILING:
    72         if ( the_mutex->Attributes.priority_ceiling <
    73                                            executing->current_priority ) {
    74           _Thread_Change_priority(
    75             executing,
    76             the_mutex->Attributes.priority_ceiling,
    77             FALSE
    78           );
    79         };
    80         break;
     60    /*
     61     *  if CORE_MUTEX_DISCIPLINES_PRIORITY_INHERIT then nothing to do
     62     *  because this task is already the highest priority.
     63     */
     64
     65    if ( _CORE_mutex_Is_priority_ceiling( &the_mutex->Attributes ) ) {
     66      if (the_mutex->Attributes.priority_ceiling < executing->current_priority){
     67        _Thread_Change_priority(
     68          executing,
     69          the_mutex->Attributes.priority_ceiling,
     70          FALSE
     71        );
     72      }
    8173    }
    8274  }
     
    10294    the_mutex->holder_id  = executing->Object.id;
    10395    the_mutex->nest_count = 1;
    104     executing->resource_count++;
    105     if ( the_mutex->Attributes.discipline !=
    106            CORE_MUTEX_DISCIPLINES_PRIORITY_CEILING ) {
    107         _ISR_Enable( level );
    108         return 0;
     96    if ( _CORE_mutex_Is_inherit_priority( &the_mutex->Attributes ) ||
     97         _CORE_mutex_Is_priority_ceiling( &the_mutex->Attributes ) )
     98      executing->resource_count++;
     99
     100    if ( !_CORE_mutex_Is_priority_ceiling( &the_mutex->Attributes ) ) {
     101      _ISR_Enable( level );
     102      return 0;
    109103    }
    110104    /* else must be CORE_MUTEX_DISCIPLINES_PRIORITY_CEILING */
     
    140134    return 0;
    141135  }
     136
     137  if ( _Thread_Is_executing( the_mutex->holder ) ) {
     138    switch ( the_mutex->Attributes.lock_nesting_behavior ) {
     139      case CORE_MUTEX_NESTING_ACQUIRES:
     140        the_mutex->nest_count++;
     141        _ISR_Enable( level );
     142        return 0;
     143      case CORE_MUTEX_NESTING_IS_ERROR:
     144        executing->Wait.return_code = CORE_MUTEX_STATUS_NESTING_NOT_ALLOWED;
     145        _ISR_Enable( level );
     146        return 0;
     147      case CORE_MUTEX_NESTING_BLOCKS:
     148        break;
     149    }
     150  }
     151
    142152  return 1;
    143153}
  • cpukit/score/src/coremutexsurrender.c

    r760045f0 rfb1d8f81  
    8787  }
    8888
    89   holder->resource_count--;
     89  if ( _CORE_mutex_Is_inherit_priority( &the_mutex->Attributes ) ||
     90       _CORE_mutex_Is_priority_ceiling( &the_mutex->Attributes ) )
     91    holder->resource_count--;
    9092  the_mutex->holder    = NULL;
    9193  the_mutex->holder_id = 0;
     
    9799   */
    98100
    99   switch ( the_mutex->Attributes.discipline ) {
    100     case CORE_MUTEX_DISCIPLINES_FIFO:
    101     case CORE_MUTEX_DISCIPLINES_PRIORITY:
    102       break;
    103     case CORE_MUTEX_DISCIPLINES_PRIORITY_CEILING:
    104     case CORE_MUTEX_DISCIPLINES_PRIORITY_INHERIT:
    105       if ( holder->resource_count == 0 &&
    106            holder->real_priority != holder->current_priority ) {
    107          _Thread_Change_priority( holder, holder->real_priority, TRUE );
    108       }
    109       break;
     101  if ( _CORE_mutex_Is_inherit_priority( &the_mutex->Attributes ) ||
     102       _CORE_mutex_Is_priority_ceiling( &the_mutex->Attributes ) ) {
     103    if ( holder->resource_count == 0 &&
     104         holder->real_priority != holder->current_priority ) {
     105      _Thread_Change_priority( holder, holder->real_priority, TRUE );
     106    }
    110107  }
    111 
    112108
    113109  if ( ( the_thread = _Thread_queue_Dequeue( &the_mutex->Wait_queue ) ) ) {
     
    128124      the_mutex->holder     = the_thread;
    129125      the_mutex->holder_id  = the_thread->Object.id;
    130       the_thread->resource_count++;
     126      if ( _CORE_mutex_Is_inherit_priority( &the_mutex->Attributes ) ||
     127           _CORE_mutex_Is_priority_ceiling( &the_mutex->Attributes ) )
     128        the_thread->resource_count++;
    131129      the_mutex->nest_count = 1;
    132130
Note: See TracChangeset for help on using the changeset viewer.