Changeset ba5ef37 in rtems


Ignore:
Timestamp:
Apr 20, 2016, 9:12:53 AM (4 years ago)
Author:
Sebastian Huber <sebastian.huber@…>
Branches:
master
Children:
5c9fa6f
Parents:
0b590858
git-author:
Sebastian Huber <sebastian.huber@…> (04/20/16 09:12:53)
git-committer:
Sebastian Huber <sebastian.huber@…> (04/22/16 07:25:09)
Message:

score: Use _Thread_queue_Flush_critical() for cond

File:
1 edited

Legend:

Unmodified
Added
Removed
  • cpukit/score/src/condition.c

    r0b590858 rba5ef37  
    11/*
    2  * Copyright (c) 2015 embedded brains GmbH.  All rights reserved.
     2 * Copyright (c) 2015, 2016 embedded brains GmbH.  All rights reserved.
    33 *
    44 *  embedded brains GmbH
     
    220220}
    221221
    222 static int _Condition_Wake( struct _Condition_Control *_condition, int count )
    223 {
    224   Condition_Control  *condition;
    225   ISR_lock_Context    lock_context;
    226   Thread_queue_Heads *heads;
    227   Chain_Control       unblock;
    228   Chain_Node         *node;
    229   Chain_Node         *tail;
    230   int                 woken;
     222typedef struct {
     223  ISR_lock_Context Base;
     224  int              count;
     225} Condition_Lock_context;
     226
     227static Thread_Control *_Condition_Flush_filter(
     228  Thread_Control     *the_thread,
     229  Thread_queue_Queue *queue,
     230  ISR_lock_Context   *lock_context
     231)
     232{
     233  Condition_Lock_context *condition_lock_context;
     234
     235  condition_lock_context = (Condition_Lock_context *) lock_context;
     236
     237  if ( condition_lock_context->count <= 0 ) {
     238    return NULL;
     239  }
     240
     241  --condition_lock_context->count;
     242
     243  return the_thread;
     244}
     245
     246static void _Condition_Wake( struct _Condition_Control *_condition, int count )
     247{
     248  Condition_Control      *condition;
     249  Condition_Lock_context  lock_context;
    231250
    232251  condition = _Condition_Get( _condition );
    233   _ISR_lock_ISR_disable( &lock_context );
    234   _Condition_Queue_acquire_critical( condition, &lock_context );
     252  _ISR_lock_ISR_disable( &lock_context.Base );
     253  _Condition_Queue_acquire_critical( condition, &lock_context.Base );
    235254
    236255  /*
     
    238257   * on the queue, so check this condition early.
    239258   */
    240   heads = condition->Queue.Queue.heads;
    241   if ( __predict_true( heads == NULL ) ) {
    242     _Condition_Queue_release( condition, &lock_context );
    243 
    244     return 0;
    245   }
    246 
    247   woken = 0;
    248   _Chain_Initialize_empty( &unblock );
    249   while ( count > 0 && heads != NULL ) {
    250     const Thread_queue_Operations *operations;
    251     Thread_Control                *first;
    252     bool                           do_unblock;
    253 
    254     operations = CONDITION_TQ_OPERATIONS;
    255     first = ( *operations->first )( heads );
    256 
    257     do_unblock = _Thread_queue_Extract_locked(
    258       &condition->Queue.Queue,
    259       operations,
    260       first,
    261       NULL,
    262       0
    263     );
    264     if (do_unblock) {
    265       _Chain_Append_unprotected( &unblock, &first->Wait.Node.Chain );
    266     }
    267 
    268     ++woken;
    269     --count;
    270     heads = condition->Queue.Queue.heads;
    271   }
    272 
    273   node = _Chain_First( &unblock );
    274   tail = _Chain_Tail( &unblock );
    275   if ( node != tail ) {
    276     Per_CPU_Control *cpu_self;
    277 
    278     cpu_self = _Thread_Dispatch_disable_critical( &lock_context );
    279     _Condition_Queue_release( condition, &lock_context );
    280 
    281     do {
    282       Thread_Control *thread;
    283       Chain_Node     *next;
    284 
    285       next = _Chain_Next( node );
    286       thread = THREAD_CHAIN_NODE_TO_THREAD( node );
    287       _Thread_Timer_remove( thread );
    288       _Thread_Unblock( thread );
    289 
    290       node = next;
    291     } while ( node != tail );
    292 
    293     _Thread_Dispatch_enable( cpu_self );
    294   } else {
    295     _Condition_Queue_release( condition, &lock_context );
    296   }
    297 
    298   return woken;
     259  if ( __predict_true( _Thread_queue_Is_empty( &condition->Queue.Queue ) ) ) {
     260    _Condition_Queue_release( condition, &lock_context.Base );
     261    return;
     262  }
     263
     264  lock_context.count = count;
     265  _Thread_queue_Flush_critical(
     266    &condition->Queue.Queue,
     267    CONDITION_TQ_OPERATIONS,
     268    _Condition_Flush_filter,
     269    NULL,
     270    0,
     271    &lock_context.Base
     272  );
    299273}
    300274
Note: See TracChangeset for help on using the changeset viewer.