Changeset bbe6a5fe in rtems


Ignore:
Timestamp:
Jul 15, 2010, 3:44:40 PM (9 years ago)
Author:
Joel Sherrill <joel.sherrill@…>
Branches:
4.11, master
Children:
e77a1934
Parents:
947015f
Message:

2010-07-15 Sebastian Huber <Sebastian.Huber@…>

PR 1607/cpukit

  • score/src/coremutexsurrender.c: Clean up and split out helper routines.
Location:
cpukit
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • cpukit/ChangeLog

    r947015f rbbe6a5fe  
     12010-07-15      Sebastian Huber <Sebastian.Huber@embedded-brains.de>
     2
     3        PR 1607/cpukit
     4        * score/src/coremutexsurrender.c: Clean up and split out helper
     5        routines.
     6
    172010-07-16      Sebastian Huber <sebastian.huber@embedded-brains.de>
    28
  • cpukit/score/src/coremutexsurrender.c

    r947015f rbbe6a5fe  
    2727#include <rtems/score/thread.h>
    2828#include <rtems/score/threadq.h>
     29
     30#ifdef __RTEMS_STRICT_ORDER_MUTEX__
     31  static inline void _CORE_mutex_Push_priority(
     32    CORE_mutex_Control *mutex,
     33    Thread_Control *thread
     34  )
     35  {
     36    _Chain_Prepend_unprotected(
     37      &thread->lock_mutex,
     38      &mutex->queue.lock_queue
     39    );
     40    mutex->queue.priority_before = thread->current_priority;
     41  }
     42
     43  static inline CORE_mutex_Status _CORE_mutex_Pop_priority(
     44    CORE_mutex_Control *mutex,
     45    Thread_Control *holder
     46  )
     47  {
     48    /*
     49     *  Check whether the holder release the mutex in LIFO order if not return
     50     *  error code.
     51     */
     52    if ( _Chain_First( holder->lock_mutex ) != &mutex->queue.lock_queue ) {
     53      mutex->nest_count++;
     54
     55      return CORE_MUTEX_RELEASE_NOT_ORDER;
     56    }
     57
     58    /*
     59     *  This pops the first node from the list.
     60     */
     61    _Chain_Get_first_unprotected( &holder->lock_mutex );
     62
     63    if ( mutex->queue.priority_before != holder->current_priority )
     64      _Thread_Change_priority( holder, mutex->queue.priority_before, true );
     65
     66    return CORE_MUTEX_STATUS_SUCCESSFUL;
     67  }
     68#else
     69  #define _CORE_mutex_Push_priority( mutex, thread ) ((void) 0)
     70
     71  #define _CORE_mutex_Pop_priority( mutex, thread ) \
     72    CORE_MUTEX_STATUS_SUCCESSFUL
     73#endif
    2974
    3075/*
     
    60105  Thread_Control *the_thread;
    61106  Thread_Control *holder;
    62 #ifdef __RTEMS_STRICT_ORDER_MUTEX__
    63   Chain_Node *first_node;
    64 #endif
    65   holder    = the_mutex->holder;
     107
     108  holder = the_mutex->holder;
    66109
    67110  /*
     
    113156   */
    114157  if ( _CORE_mutex_Is_inherit_priority( &the_mutex->Attributes ) ||
    115        _CORE_mutex_Is_priority_ceiling( &the_mutex->Attributes ) ){
    116 #ifdef __RTEMS_STRICT_ORDER_MUTEX__
    117     /*Check whether the holder release the mutex in LIFO order
    118       if not return error code*/
    119     if(holder->lock_mutex.first != &the_mutex->queue.lock_queue){
    120       the_mutex->nest_count++;
    121       return CORE_MUTEX_RELEASE_NOT_ORDER;
    122     }
    123     first_node = _Chain_Get_first_unprotected(&holder->lock_mutex);
    124 #endif
     158       _CORE_mutex_Is_priority_ceiling( &the_mutex->Attributes ) ) {
     159    CORE_mutex_Status pop_status =
     160      _CORE_mutex_Pop_priority( the_mutex, holder );
     161
     162    if ( pop_status != CORE_MUTEX_STATUS_SUCCESSFUL )
     163      return pop_status;
     164
    125165    holder->resource_count--;
    126   }
    127   the_mutex->holder    = NULL;
    128   the_mutex->holder_id = 0;
    129 
    130   /*
    131    *  Whether or not someone is waiting for the mutex, an
    132    *  inherited priority must be lowered if this is the last
    133    *  mutex (i.e. resource) this task has.
    134    */
    135   if ( _CORE_mutex_Is_inherit_priority( &the_mutex->Attributes ) ||
    136        _CORE_mutex_Is_priority_ceiling( &the_mutex->Attributes ) ) {
    137 #ifdef __RTEMS_STRICT_ORDER_MUTEX__
    138     if(the_mutex->queue.priority_before != holder->current_priority)
    139       _Thread_Change_priority(holder,the_mutex->queue.priority_before,true);
    140 #endif
     166
     167    /*
     168     *  Whether or not someone is waiting for the mutex, an
     169     *  inherited priority must be lowered if this is the last
     170     *  mutex (i.e. resource) this task has.
     171     */
    141172    if ( holder->resource_count == 0 &&
    142173         holder->real_priority != holder->current_priority ) {
     
    144175    }
    145176  }
     177  the_mutex->holder    = NULL;
     178  the_mutex->holder_id = 0;
    146179
    147180  /*
     
    173206          break;
    174207        case CORE_MUTEX_DISCIPLINES_PRIORITY_INHERIT:
    175 #ifdef __RTEMS_STRICT_ORDER_MUTEX__
    176           _Chain_Prepend_unprotected(&the_thread->lock_mutex,&the_mutex->queue.lock_queue);
    177           the_mutex->queue.priority_before = the_thread->current_priority;
    178 #endif
     208          _CORE_mutex_Push_priority( the_mutex, the_thread );
    179209          the_thread->resource_count++;
    180210          break;
    181211        case CORE_MUTEX_DISCIPLINES_PRIORITY_CEILING:
    182 #ifdef __RTEMS_STRICT_ORDER_MUTEX__
    183           _Chain_Prepend_unprotected(&the_thread->lock_mutex,&the_mutex->queue.lock_queue);
    184           the_mutex->queue.priority_before = the_thread->current_priority;
    185 #endif
     212          _CORE_mutex_Push_priority( the_mutex, the_thread );
    186213          the_thread->resource_count++;
    187214          if (the_mutex->Attributes.priority_ceiling <
Note: See TracChangeset for help on using the changeset viewer.