Changeset caaa47c in rtems


Ignore:
Timestamp:
Dec 1, 1995, 9:08:03 PM (24 years ago)
Author:
Joel Sherrill <joel.sherrill@…>
Branches:
4.10, 4.11, 4.8, 4.9, master
Children:
8d0b7d96
Parents:
ed32907
Message:

Added new synchronization algorithm.

Files:
2 edited

Legend:

Unmodified
Added
Removed
  • c/src/exec/score/src/threadq.c

    red32907 rcaaa47c  
    113113       &the_thread->Timer,
    114114      timeout,
    115       WATCHDOG_NO_ACTIVATE
     115      WATCHDOG_ACTIVATE_NOW
    116116    );
    117117  }
     
    122122      break;
    123123    case THREAD_QUEUE_DISCIPLINE_PRIORITY:
    124       _Thread_queue_Enqueue_priority(
    125          the_thread_queue, the_thread, timeout );
     124      _Thread_queue_Enqueue_priority( the_thread_queue, the_thread, timeout );
    126125      break;
    127126  }
     
    151150{
    152151  Thread_Control *the_thread;
    153   ISR_Level       level;
    154152
    155153  switch ( the_thread_queue->discipline ) {
     
    165163  }
    166164
    167   if ( !_Thread_Is_null( the_thread ) )
    168     return( the_thread );
    169 
    170   _ISR_Disable( level );
    171   if ( the_thread_queue->sync == FALSE ) {
    172     _ISR_Enable( level );
    173     return( NULL );
    174   }
    175 
    176   the_thread_queue->sync = FALSE;
    177   _ISR_Enable( level );
    178   return( _Thread_Executing );
     165  return( the_thread );
    179166}
    180167
     
    332319)
    333320{
    334   Thread_Control  *the_thread;
    335   Objects_Locations       location;
     321  Thread_Control       *the_thread;
     322  Thread_queue_Control *the_thread_queue;
     323  Objects_Locations     location;
    336324
    337325  the_thread = _Thread_Get( id, &location );
     
    341329      break;
    342330    case OBJECTS_LOCAL:
    343       the_thread->Wait.return_code = the_thread->Wait.queue->timeout_status;
    344       _Thread_queue_Extract( the_thread->Wait.queue, the_thread );
     331      the_thread_queue = the_thread->Wait.queue;
     332
     333      if ( the_thread_queue->sync == TRUE && _Thread_Is_executing(the_thread)) {
     334        if ( the_thread_queue->sync_state != THREAD_QUEUE_SATISFIED )
     335          the_thread_queue->sync_state = THREAD_QUEUE_TIMEOUT;
     336      } else {
     337        the_thread->Wait.return_code = the_thread->Wait.queue->timeout_status;
     338        _Thread_queue_Extract( the_thread->Wait.queue, the_thread );
     339      }
    345340      _Thread_Unnest_dispatch();
    346341      break;
     
    375370
    376371  _ISR_Disable( level );
    377   if ( the_thread_queue->sync == TRUE ) {
    378     the_thread_queue->sync = FALSE;
    379 
    380     _Chain_Append_unprotected(
    381       &the_thread_queue->Queues.Fifo,
    382       &the_thread->Object.Node
    383     );
    384 
    385     if ( timeout != WATCHDOG_NO_TIMEOUT )
    386       _Watchdog_Activate( &the_thread->Timer );
    387 
    388     _ISR_Enable( level );
    389     return;
    390   }
    391 
    392   if ( !_Watchdog_Is_active( &the_thread->Timer ) ) {
    393     _ISR_Enable( level );
    394     _Thread_Unblock( the_thread );
    395   } else {
    396     _Watchdog_Deactivate( &the_thread->Timer );
    397     _ISR_Enable( level );
    398     (void) _Watchdog_Remove( &the_thread->Timer );
    399     _Thread_Unblock( the_thread );
    400   }
     372
     373  switch ( the_thread_queue->sync_state ) {
     374    case THREAD_QUEUE_NOTHING_HAPPENED:
     375      the_thread_queue->sync = FALSE;
     376      _Chain_Append_unprotected(
     377        &the_thread_queue->Queues.Fifo,
     378        &the_thread->Object.Node
     379      );
     380      _ISR_Enable( level );
     381      return;
     382
     383    case THREAD_QUEUE_TIMEOUT:
     384      the_thread->Wait.return_code = the_thread->Wait.queue->timeout_status;
     385      _ISR_Enable( level );
     386      break;
     387
     388    case THREAD_QUEUE_SATISFIED:
     389      if ( _Watchdog_Is_active( &the_thread->Timer ) ) {
     390        _Watchdog_Deactivate( &the_thread->Timer );
     391        _ISR_Enable( level );
     392        (void) _Watchdog_Remove( &the_thread->Timer );
     393      } else
     394        _ISR_Enable( level );
     395      break;
     396  }
     397
     398  /*
     399   *  Global objects with thread queue's should not be operated on from an
     400   *  ISR.  But the sync code still must allow short timeouts to be processed
     401   *  correctly.
     402   */
     403
     404  _Thread_Unblock( the_thread );
    401405
    402406  if ( !_Objects_Is_local_id( the_thread->Object.id ) )
     
    448452      _Thread_MP_Free_proxy( the_thread );
    449453
    450     return( the_thread );
    451   }
    452   _ISR_Enable( level );
    453   return( NULL );
     454    return the_thread;
     455  } else if ( the_thread_queue->sync ) {
     456    the_thread_queue->sync_state = THREAD_QUEUE_SATISFIED;
     457    _ISR_Enable( level );
     458    return _Thread_Executing;
     459  } else {
     460    _ISR_Enable( level );
     461    return NULL;
     462  }
    454463}
    455464
     
    598607       (Thread_Control *)search_thread->Object.Node.next;
    599608  }
    600   if ( the_thread_queue->sync == FALSE )
     609  if ( the_thread_queue->sync_state != THREAD_QUEUE_NOTHING_HAPPENED )
    601610    goto syncronize;
    602611
    603612  the_thread_queue->sync = FALSE;
    604   if ( timeout != WATCHDOG_NO_TIMEOUT )
    605     _Watchdog_Activate( &the_thread->Timer );
    606613
    607614  if ( priority == search_priority )
     
    644651                         search_thread->Object.Node.previous;
    645652  }
    646   if ( !the_thread_queue->sync )
     653  if ( the_thread_queue->sync_state != THREAD_QUEUE_NOTHING_HAPPENED )
    647654    goto syncronize;
    648655
    649656  the_thread_queue->sync = FALSE;
    650   if ( timeout != WATCHDOG_NO_TIMEOUT )
    651     _Watchdog_Activate( &the_thread->Timer );
    652657
    653658  if ( priority == search_priority )
     
    678683
    679684syncronize:
    680   if ( !_Watchdog_Is_active( &the_thread->Timer ) ) {
    681     _ISR_Enable( level );
    682     _Thread_Unblock( the_thread );
    683   } else {
    684     _Watchdog_Deactivate( &the_thread->Timer );
    685     _ISR_Enable( level );
    686     (void) _Watchdog_Remove( &the_thread->Timer );
    687     _Thread_Unblock( the_thread );
    688   }
     685
     686  switch ( the_thread_queue->sync_state ) {
     687    case THREAD_QUEUE_NOTHING_HAPPENED:
     688      /*
     689       *  All of this was dealt with above.  This should never happen.
     690       */
     691      break;
     692 
     693    case THREAD_QUEUE_TIMEOUT:
     694      the_thread->Wait.return_code = the_thread->Wait.queue->timeout_status;
     695      _ISR_Enable( level );
     696      break;
     697 
     698    case THREAD_QUEUE_SATISFIED:
     699      if ( _Watchdog_Is_active( &the_thread->Timer ) ) {
     700        _Watchdog_Deactivate( &the_thread->Timer );
     701        _ISR_Enable( level );
     702        (void) _Watchdog_Remove( &the_thread->Timer );
     703      } else
     704        _ISR_Enable( level );
     705      break;
     706  }
     707 
     708  /*
     709   *  Global objects with thread queue's should not be operated on from an
     710   *  ISR.  But the sync code still must allow short timeouts to be processed
     711   *  correctly.
     712   */
     713 
     714  _Thread_Unblock( the_thread );
     715 
    689716  if ( !_Objects_Is_local_id( the_thread->Object.id ) )
    690717    _Thread_MP_Free_proxy( the_thread );
     
    722749  Chain_Node     *previous_node;
    723750
     751  _ISR_Disable( level );
    724752  for( index=0 ;
    725753       index < TASK_QUEUE_DATA_NUMBER_OF_PRIORITY_HEADERS ;
    726754       index++ ) {
    727     _ISR_Disable( level );
    728755    if ( !_Chain_Is_empty( &the_thread_queue->Queues.Priority[ index ] ) ) {
    729756      the_thread = (Thread_Control *)
     
    731758      goto dequeue;
    732759    }
     760  }
     761
     762  if ( the_thread_queue->sync ) {
     763    the_thread_queue->sync_state = THREAD_QUEUE_SATISFIED;
    733764    _ISR_Enable( level );
    734   }
     765    return _Thread_Executing;
     766  }
     767
     768  _ISR_Enable( level );
    735769  return NULL;
    736770
  • cpukit/score/src/threadq.c

    red32907 rcaaa47c  
    113113       &the_thread->Timer,
    114114      timeout,
    115       WATCHDOG_NO_ACTIVATE
     115      WATCHDOG_ACTIVATE_NOW
    116116    );
    117117  }
     
    122122      break;
    123123    case THREAD_QUEUE_DISCIPLINE_PRIORITY:
    124       _Thread_queue_Enqueue_priority(
    125          the_thread_queue, the_thread, timeout );
     124      _Thread_queue_Enqueue_priority( the_thread_queue, the_thread, timeout );
    126125      break;
    127126  }
     
    151150{
    152151  Thread_Control *the_thread;
    153   ISR_Level       level;
    154152
    155153  switch ( the_thread_queue->discipline ) {
     
    165163  }
    166164
    167   if ( !_Thread_Is_null( the_thread ) )
    168     return( the_thread );
    169 
    170   _ISR_Disable( level );
    171   if ( the_thread_queue->sync == FALSE ) {
    172     _ISR_Enable( level );
    173     return( NULL );
    174   }
    175 
    176   the_thread_queue->sync = FALSE;
    177   _ISR_Enable( level );
    178   return( _Thread_Executing );
     165  return( the_thread );
    179166}
    180167
     
    332319)
    333320{
    334   Thread_Control  *the_thread;
    335   Objects_Locations       location;
     321  Thread_Control       *the_thread;
     322  Thread_queue_Control *the_thread_queue;
     323  Objects_Locations     location;
    336324
    337325  the_thread = _Thread_Get( id, &location );
     
    341329      break;
    342330    case OBJECTS_LOCAL:
    343       the_thread->Wait.return_code = the_thread->Wait.queue->timeout_status;
    344       _Thread_queue_Extract( the_thread->Wait.queue, the_thread );
     331      the_thread_queue = the_thread->Wait.queue;
     332
     333      if ( the_thread_queue->sync == TRUE && _Thread_Is_executing(the_thread)) {
     334        if ( the_thread_queue->sync_state != THREAD_QUEUE_SATISFIED )
     335          the_thread_queue->sync_state = THREAD_QUEUE_TIMEOUT;
     336      } else {
     337        the_thread->Wait.return_code = the_thread->Wait.queue->timeout_status;
     338        _Thread_queue_Extract( the_thread->Wait.queue, the_thread );
     339      }
    345340      _Thread_Unnest_dispatch();
    346341      break;
     
    375370
    376371  _ISR_Disable( level );
    377   if ( the_thread_queue->sync == TRUE ) {
    378     the_thread_queue->sync = FALSE;
    379 
    380     _Chain_Append_unprotected(
    381       &the_thread_queue->Queues.Fifo,
    382       &the_thread->Object.Node
    383     );
    384 
    385     if ( timeout != WATCHDOG_NO_TIMEOUT )
    386       _Watchdog_Activate( &the_thread->Timer );
    387 
    388     _ISR_Enable( level );
    389     return;
    390   }
    391 
    392   if ( !_Watchdog_Is_active( &the_thread->Timer ) ) {
    393     _ISR_Enable( level );
    394     _Thread_Unblock( the_thread );
    395   } else {
    396     _Watchdog_Deactivate( &the_thread->Timer );
    397     _ISR_Enable( level );
    398     (void) _Watchdog_Remove( &the_thread->Timer );
    399     _Thread_Unblock( the_thread );
    400   }
     372
     373  switch ( the_thread_queue->sync_state ) {
     374    case THREAD_QUEUE_NOTHING_HAPPENED:
     375      the_thread_queue->sync = FALSE;
     376      _Chain_Append_unprotected(
     377        &the_thread_queue->Queues.Fifo,
     378        &the_thread->Object.Node
     379      );
     380      _ISR_Enable( level );
     381      return;
     382
     383    case THREAD_QUEUE_TIMEOUT:
     384      the_thread->Wait.return_code = the_thread->Wait.queue->timeout_status;
     385      _ISR_Enable( level );
     386      break;
     387
     388    case THREAD_QUEUE_SATISFIED:
     389      if ( _Watchdog_Is_active( &the_thread->Timer ) ) {
     390        _Watchdog_Deactivate( &the_thread->Timer );
     391        _ISR_Enable( level );
     392        (void) _Watchdog_Remove( &the_thread->Timer );
     393      } else
     394        _ISR_Enable( level );
     395      break;
     396  }
     397
     398  /*
     399   *  Global objects with thread queue's should not be operated on from an
     400   *  ISR.  But the sync code still must allow short timeouts to be processed
     401   *  correctly.
     402   */
     403
     404  _Thread_Unblock( the_thread );
    401405
    402406  if ( !_Objects_Is_local_id( the_thread->Object.id ) )
     
    448452      _Thread_MP_Free_proxy( the_thread );
    449453
    450     return( the_thread );
    451   }
    452   _ISR_Enable( level );
    453   return( NULL );
     454    return the_thread;
     455  } else if ( the_thread_queue->sync ) {
     456    the_thread_queue->sync_state = THREAD_QUEUE_SATISFIED;
     457    _ISR_Enable( level );
     458    return _Thread_Executing;
     459  } else {
     460    _ISR_Enable( level );
     461    return NULL;
     462  }
    454463}
    455464
     
    598607       (Thread_Control *)search_thread->Object.Node.next;
    599608  }
    600   if ( the_thread_queue->sync == FALSE )
     609  if ( the_thread_queue->sync_state != THREAD_QUEUE_NOTHING_HAPPENED )
    601610    goto syncronize;
    602611
    603612  the_thread_queue->sync = FALSE;
    604   if ( timeout != WATCHDOG_NO_TIMEOUT )
    605     _Watchdog_Activate( &the_thread->Timer );
    606613
    607614  if ( priority == search_priority )
     
    644651                         search_thread->Object.Node.previous;
    645652  }
    646   if ( !the_thread_queue->sync )
     653  if ( the_thread_queue->sync_state != THREAD_QUEUE_NOTHING_HAPPENED )
    647654    goto syncronize;
    648655
    649656  the_thread_queue->sync = FALSE;
    650   if ( timeout != WATCHDOG_NO_TIMEOUT )
    651     _Watchdog_Activate( &the_thread->Timer );
    652657
    653658  if ( priority == search_priority )
     
    678683
    679684syncronize:
    680   if ( !_Watchdog_Is_active( &the_thread->Timer ) ) {
    681     _ISR_Enable( level );
    682     _Thread_Unblock( the_thread );
    683   } else {
    684     _Watchdog_Deactivate( &the_thread->Timer );
    685     _ISR_Enable( level );
    686     (void) _Watchdog_Remove( &the_thread->Timer );
    687     _Thread_Unblock( the_thread );
    688   }
     685
     686  switch ( the_thread_queue->sync_state ) {
     687    case THREAD_QUEUE_NOTHING_HAPPENED:
     688      /*
     689       *  All of this was dealt with above.  This should never happen.
     690       */
     691      break;
     692 
     693    case THREAD_QUEUE_TIMEOUT:
     694      the_thread->Wait.return_code = the_thread->Wait.queue->timeout_status;
     695      _ISR_Enable( level );
     696      break;
     697 
     698    case THREAD_QUEUE_SATISFIED:
     699      if ( _Watchdog_Is_active( &the_thread->Timer ) ) {
     700        _Watchdog_Deactivate( &the_thread->Timer );
     701        _ISR_Enable( level );
     702        (void) _Watchdog_Remove( &the_thread->Timer );
     703      } else
     704        _ISR_Enable( level );
     705      break;
     706  }
     707 
     708  /*
     709   *  Global objects with thread queue's should not be operated on from an
     710   *  ISR.  But the sync code still must allow short timeouts to be processed
     711   *  correctly.
     712   */
     713 
     714  _Thread_Unblock( the_thread );
     715 
    689716  if ( !_Objects_Is_local_id( the_thread->Object.id ) )
    690717    _Thread_MP_Free_proxy( the_thread );
     
    722749  Chain_Node     *previous_node;
    723750
     751  _ISR_Disable( level );
    724752  for( index=0 ;
    725753       index < TASK_QUEUE_DATA_NUMBER_OF_PRIORITY_HEADERS ;
    726754       index++ ) {
    727     _ISR_Disable( level );
    728755    if ( !_Chain_Is_empty( &the_thread_queue->Queues.Priority[ index ] ) ) {
    729756      the_thread = (Thread_Control *)
     
    731758      goto dequeue;
    732759    }
     760  }
     761
     762  if ( the_thread_queue->sync ) {
     763    the_thread_queue->sync_state = THREAD_QUEUE_SATISFIED;
    733764    _ISR_Enable( level );
    734   }
     765    return _Thread_Executing;
     766  }
     767
     768  _ISR_Enable( level );
    735769  return NULL;
    736770
Note: See TracChangeset for help on using the changeset viewer.