Changeset ea9d7db in rtems


Ignore:
Timestamp:
Aug 4, 1995, 10:17:48 PM (25 years ago)
Author:
Joel Sherrill <joel.sherrill@…>
Branches:
4.10, 4.11, 4.8, 4.9, 5, master
Children:
ce6e30b1
Parents:
216ed54
Message:

split out event support functions in anticipation of making a handler

Files:
2 edited

Legend:

Unmodified
Added
Removed
  • c/src/exec/rtems/src/event.c

    r216ed54 rea9d7db  
    102102  return( _Thread_Executing->Wait.return_code );
    103103}
    104 
    105 /*PAGE
    106  *
    107  *  _Event_Seize
    108  *
    109  *  This routine attempts to satisfy the requested event condition
    110  *  for the running thread.
    111  *
    112  *  Input parameters:
    113  *    event_in   - the event condition to satisfy
    114  *    option_set - acquire event options
    115  *    ticks      - interval to wait
    116  *
    117  *  Output parameters: NONE
    118  *
    119  *  INTERRUPT LATENCY:
    120  *    available
    121  *    wait
    122  *    check sync
    123  */
    124 
    125 void _Event_Seize(
    126   rtems_event_set event_in,
    127   rtems_option    option_set,
    128   rtems_interval  ticks
    129 )
    130 {
    131   Thread_Control   *executing;
    132   rtems_event_set   seized_events;
    133   rtems_event_set   pending_events;
    134   ISR_Level         level;
    135 
    136   executing = _Thread_Executing;
    137   executing->Wait.return_code = RTEMS_SUCCESSFUL;
    138 
    139   _ISR_Disable( level );
    140   pending_events = executing->pending_events;
    141   seized_events  = _Event_sets_Get( pending_events, event_in );
    142 
    143   if ( !_Event_sets_Is_empty( seized_events ) &&
    144        (seized_events == event_in || _Options_Is_any( option_set )) ) {
    145     executing->pending_events =
    146       _Event_sets_Clear( pending_events, seized_events );
    147     _ISR_Enable( level );
    148     executing->events_out = seized_events;
    149     return;
    150   }
    151 
    152   if ( _Options_Is_no_wait( option_set ) ) {
    153     _ISR_Enable( level );
    154     executing->Wait.return_code = RTEMS_UNSATISFIED;
    155     executing->events_out = seized_events;
    156     return;
    157   }
    158 
    159   _Event_Sync = TRUE;
    160   executing->Wait.option_set            = option_set;
    161   executing->Wait.Extra.event_condition = event_in;
    162 
    163   _ISR_Enable( level );
    164   _Thread_Set_state( executing, STATES_WAITING_FOR_EVENT );
    165 
    166   if ( ticks ) {
    167     _Watchdog_Initialize(
    168       &executing->Timer,
    169       _Event_Timeout,
    170       executing->Object.id,
    171       NULL
    172     );
    173     _Watchdog_Insert_ticks(
    174       &executing->Timer,
    175       ticks,
    176       WATCHDOG_NO_ACTIVATE
    177     );
    178   }
    179 
    180   _ISR_Disable( level );
    181   if ( _Event_Sync == TRUE ) {
    182     _Event_Sync = FALSE;
    183     if ( ticks )
    184       _Watchdog_Activate( &executing->Timer );
    185     _ISR_Enable( level );
    186     return;
    187   }
    188   _ISR_Enable( level );
    189   (void) _Watchdog_Remove( &executing->Timer );
    190   _Thread_Unblock( executing );
    191   return;
    192 }
    193 
    194 /*PAGE
    195  *
    196  *  _Event_Surrender
    197  *
    198  *  This routines remove a thread from the specified threadq.
    199  *
    200  *  Input parameters:
    201  *    the_thread - pointer to thread to be dequeued
    202  *
    203  *  Output parameters: NONE
    204  *
    205  *  INTERRUPT LATENCY:
    206  *    before flash
    207  *    after flash
    208  *    check sync
    209  */
    210 
    211 void _Event_Surrender(
    212   Thread_Control *the_thread
    213 )
    214 {
    215   ISR_Level          level;
    216   rtems_event_set pending_events;
    217   rtems_event_set event_condition;
    218   rtems_event_set seized_events;
    219 
    220   _ISR_Disable( level );
    221   pending_events  = the_thread->pending_events;
    222   event_condition = the_thread->Wait.Extra.event_condition;
    223 
    224   seized_events = _Event_sets_Get( pending_events, event_condition );
    225 
    226   if ( !_Event_sets_Is_empty( seized_events ) ) {
    227     if ( _States_Is_waiting_for_event( the_thread->current_state ) ) {
    228       if ( seized_events == event_condition ||
    229                     _Options_Is_any( the_thread->Wait.option_set ) ) {
    230         the_thread->pending_events =
    231            _Event_sets_Clear( pending_events, seized_events );
    232         (rtems_event_set *)the_thread->events_out = seized_events;
    233 
    234         _ISR_Flash( level );
    235 
    236         if ( !_Watchdog_Is_active( &the_thread->Timer ) ) {
    237           _ISR_Enable( level );
    238           _Thread_Unblock( the_thread );
    239         }
    240         else {
    241           _Watchdog_Deactivate( &the_thread->Timer );
    242           _ISR_Enable( level );
    243           (void) _Watchdog_Remove( &the_thread->Timer );
    244           _Thread_Unblock( the_thread );
    245         }
    246         return;
    247       }
    248     }
    249     else if ( _Thread_Is_executing( the_thread ) && _Event_Sync == TRUE ) {
    250       if ( seized_events == event_condition ||
    251                     _Options_Is_any( the_thread->Wait.option_set ) ) {
    252         the_thread->pending_events =
    253            _Event_sets_Clear( pending_events,seized_events );
    254         (rtems_event_set *)the_thread->events_out = seized_events;
    255         _Event_Sync = FALSE;
    256       }
    257     }
    258   }
    259   _ISR_Enable( level );
    260 }
    261 
    262 /*PAGE
    263  *
    264  *  _Event_Timeout
    265  *
    266  *  This routine processes a thread which timeouts while waiting to
    267  *  receive an event_set. It is called by the watchdog handler.
    268  *
    269  *  Input parameters:
    270  *    id - thread id
    271  *
    272  *  Output parameters: NONE
    273  */
    274 
    275 void _Event_Timeout(
    276   Objects_Id  id,
    277   void       *ignored
    278 )
    279 {
    280   Thread_Control *the_thread;
    281   Objects_Locations      location;
    282 
    283   the_thread = _Thread_Get( id, &location );
    284   switch ( location ) {
    285     case OBJECTS_ERROR:
    286     case OBJECTS_REMOTE:  /* impossible */
    287       break;
    288     case OBJECTS_LOCAL:
    289       the_thread->Wait.return_code = RTEMS_TIMEOUT;
    290       _Thread_Unblock( the_thread );
    291       _Thread_Unnest_dispatch();
    292       break;
    293   }
    294 }
  • cpukit/rtems/src/event.c

    r216ed54 rea9d7db  
    102102  return( _Thread_Executing->Wait.return_code );
    103103}
    104 
    105 /*PAGE
    106  *
    107  *  _Event_Seize
    108  *
    109  *  This routine attempts to satisfy the requested event condition
    110  *  for the running thread.
    111  *
    112  *  Input parameters:
    113  *    event_in   - the event condition to satisfy
    114  *    option_set - acquire event options
    115  *    ticks      - interval to wait
    116  *
    117  *  Output parameters: NONE
    118  *
    119  *  INTERRUPT LATENCY:
    120  *    available
    121  *    wait
    122  *    check sync
    123  */
    124 
    125 void _Event_Seize(
    126   rtems_event_set event_in,
    127   rtems_option    option_set,
    128   rtems_interval  ticks
    129 )
    130 {
    131   Thread_Control   *executing;
    132   rtems_event_set   seized_events;
    133   rtems_event_set   pending_events;
    134   ISR_Level         level;
    135 
    136   executing = _Thread_Executing;
    137   executing->Wait.return_code = RTEMS_SUCCESSFUL;
    138 
    139   _ISR_Disable( level );
    140   pending_events = executing->pending_events;
    141   seized_events  = _Event_sets_Get( pending_events, event_in );
    142 
    143   if ( !_Event_sets_Is_empty( seized_events ) &&
    144        (seized_events == event_in || _Options_Is_any( option_set )) ) {
    145     executing->pending_events =
    146       _Event_sets_Clear( pending_events, seized_events );
    147     _ISR_Enable( level );
    148     executing->events_out = seized_events;
    149     return;
    150   }
    151 
    152   if ( _Options_Is_no_wait( option_set ) ) {
    153     _ISR_Enable( level );
    154     executing->Wait.return_code = RTEMS_UNSATISFIED;
    155     executing->events_out = seized_events;
    156     return;
    157   }
    158 
    159   _Event_Sync = TRUE;
    160   executing->Wait.option_set            = option_set;
    161   executing->Wait.Extra.event_condition = event_in;
    162 
    163   _ISR_Enable( level );
    164   _Thread_Set_state( executing, STATES_WAITING_FOR_EVENT );
    165 
    166   if ( ticks ) {
    167     _Watchdog_Initialize(
    168       &executing->Timer,
    169       _Event_Timeout,
    170       executing->Object.id,
    171       NULL
    172     );
    173     _Watchdog_Insert_ticks(
    174       &executing->Timer,
    175       ticks,
    176       WATCHDOG_NO_ACTIVATE
    177     );
    178   }
    179 
    180   _ISR_Disable( level );
    181   if ( _Event_Sync == TRUE ) {
    182     _Event_Sync = FALSE;
    183     if ( ticks )
    184       _Watchdog_Activate( &executing->Timer );
    185     _ISR_Enable( level );
    186     return;
    187   }
    188   _ISR_Enable( level );
    189   (void) _Watchdog_Remove( &executing->Timer );
    190   _Thread_Unblock( executing );
    191   return;
    192 }
    193 
    194 /*PAGE
    195  *
    196  *  _Event_Surrender
    197  *
    198  *  This routines remove a thread from the specified threadq.
    199  *
    200  *  Input parameters:
    201  *    the_thread - pointer to thread to be dequeued
    202  *
    203  *  Output parameters: NONE
    204  *
    205  *  INTERRUPT LATENCY:
    206  *    before flash
    207  *    after flash
    208  *    check sync
    209  */
    210 
    211 void _Event_Surrender(
    212   Thread_Control *the_thread
    213 )
    214 {
    215   ISR_Level          level;
    216   rtems_event_set pending_events;
    217   rtems_event_set event_condition;
    218   rtems_event_set seized_events;
    219 
    220   _ISR_Disable( level );
    221   pending_events  = the_thread->pending_events;
    222   event_condition = the_thread->Wait.Extra.event_condition;
    223 
    224   seized_events = _Event_sets_Get( pending_events, event_condition );
    225 
    226   if ( !_Event_sets_Is_empty( seized_events ) ) {
    227     if ( _States_Is_waiting_for_event( the_thread->current_state ) ) {
    228       if ( seized_events == event_condition ||
    229                     _Options_Is_any( the_thread->Wait.option_set ) ) {
    230         the_thread->pending_events =
    231            _Event_sets_Clear( pending_events, seized_events );
    232         (rtems_event_set *)the_thread->events_out = seized_events;
    233 
    234         _ISR_Flash( level );
    235 
    236         if ( !_Watchdog_Is_active( &the_thread->Timer ) ) {
    237           _ISR_Enable( level );
    238           _Thread_Unblock( the_thread );
    239         }
    240         else {
    241           _Watchdog_Deactivate( &the_thread->Timer );
    242           _ISR_Enable( level );
    243           (void) _Watchdog_Remove( &the_thread->Timer );
    244           _Thread_Unblock( the_thread );
    245         }
    246         return;
    247       }
    248     }
    249     else if ( _Thread_Is_executing( the_thread ) && _Event_Sync == TRUE ) {
    250       if ( seized_events == event_condition ||
    251                     _Options_Is_any( the_thread->Wait.option_set ) ) {
    252         the_thread->pending_events =
    253            _Event_sets_Clear( pending_events,seized_events );
    254         (rtems_event_set *)the_thread->events_out = seized_events;
    255         _Event_Sync = FALSE;
    256       }
    257     }
    258   }
    259   _ISR_Enable( level );
    260 }
    261 
    262 /*PAGE
    263  *
    264  *  _Event_Timeout
    265  *
    266  *  This routine processes a thread which timeouts while waiting to
    267  *  receive an event_set. It is called by the watchdog handler.
    268  *
    269  *  Input parameters:
    270  *    id - thread id
    271  *
    272  *  Output parameters: NONE
    273  */
    274 
    275 void _Event_Timeout(
    276   Objects_Id  id,
    277   void       *ignored
    278 )
    279 {
    280   Thread_Control *the_thread;
    281   Objects_Locations      location;
    282 
    283   the_thread = _Thread_Get( id, &location );
    284   switch ( location ) {
    285     case OBJECTS_ERROR:
    286     case OBJECTS_REMOTE:  /* impossible */
    287       break;
    288     case OBJECTS_LOCAL:
    289       the_thread->Wait.return_code = RTEMS_TIMEOUT;
    290       _Thread_Unblock( the_thread );
    291       _Thread_Unnest_dispatch();
    292       break;
    293   }
    294 }
Note: See TracChangeset for help on using the changeset viewer.