Changeset 990575c in rtems


Ignore:
Timestamp:
Oct 30, 2012, 3:18:36 PM (9 years ago)
Author:
Sebastian Huber <sebastian.huber@…>
Branches:
4.11, 5, master
Children:
0edf263
Parents:
f8657bbd
git-author:
Sebastian Huber <sebastian.huber@…> (10/30/12 15:18:36)
git-committer:
Sebastian Huber <sebastian.huber@…> (10/30/12 17:00:33)
Message:

rtems: Reusable event implementation

Change event implementation to enable reuse for system events.

Location:
cpukit
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • cpukit/libmisc/monitor/mon-task.c

    rf8657bbd r990575c  
    3131    canonical_task->state = rtems_thread->current_state;
    3232    canonical_task->wait_id = rtems_thread->Wait.id;
    33     canonical_task->events = api->pending_events;
     33    canonical_task->events = api->Event.pending_events;
    3434    /*
    3535     * FIXME: make this optionally cpu_time_executed
  • cpukit/rtems/include/rtems/rtems/event.h

    rf8657bbd r990575c  
    215215 */
    216216
     217typedef struct {
     218  rtems_event_set pending_events;
     219} Event_Control;
     220
    217221/**
    218222 *  This constant is passed as the event_in to the
     
    221225#define EVENT_CURRENT  0
    222226
    223 /**
    224  *  @brief Event_Manager_initialization
    225  *
    226  *  This routine performs the initialization necessary for this manager.
    227  */
    228227void _Event_Manager_initialization( void );
    229228
    230 /**
    231  *  @brief Event_Seize
    232  *
    233  *  This routine determines if the event condition event_in is
    234  *  satisfied.  If so or if the no_wait option is enabled in option_set,
    235  *  then the procedure returns immediately.  If neither of these
    236  *  conditions is true, then the calling task is blocked with an
    237  *  optional timeout of ticks clock ticks.
    238  */
    239 void _Event_Seize (
    240   rtems_event_set  event_in,
    241   rtems_option     option_set,
    242   rtems_interval   ticks,
    243   rtems_event_set *event_out
    244 );
    245 
    246 /**
    247  *  @brief Event_Surrender
    248  *
    249  *  This routine determines if the event condition of the_thread
    250  *  has been satisfied.  If so, it unblocks the_thread.
    251  */
    252 void _Event_Surrender (
    253   Thread_Control *the_thread
    254 );
    255 
    256 /**
    257  *  @brief Event_Timeout
    258  *
    259  *  This routine is invoked when a task's event receive request
    260  *  has not been satisfied after the specified timeout interval.
    261  *  The task represented by ID will be unblocked and its status
    262  *  code will be set in it's control block to indicate that a timeout
    263  *  has occurred.
    264  */
    265 void _Event_Timeout (
     229void _Event_Seize(
     230  rtems_event_set                   event_in,
     231  rtems_option                      option_set,
     232  rtems_interval                    ticks,
     233  rtems_event_set                  *event_out,
     234  Thread_Control                   *executing,
     235  Event_Control                    *event,
     236  Thread_blocking_operation_States *sync_state,
     237  States_Control                    wait_state
     238);
     239
     240void _Event_Surrender(
     241  Thread_Control                   *the_thread,
     242  rtems_event_set                   event_in,
     243  Event_Control                    *event,
     244  Thread_blocking_operation_States *sync_state,
     245  States_Control                    wait_state
     246);
     247
     248void _Event_Timeout(
    266249  Objects_Id  id,
    267250  void       *ignored
    268251);
    269252
    270 /**
    271  *  @brief he following defines the synchronization flag used by the
    272  */
    273 RTEMS_EVENT_EXTERN volatile Thread_blocking_operation_States _Event_Sync_state;
     253RTEMS_EVENT_EXTERN Thread_blocking_operation_States _Event_Sync_state;
    274254
    275255/** @} */
  • cpukit/rtems/include/rtems/rtems/tasks.h

    rf8657bbd r990575c  
    3939#include <rtems/score/thread.h>
    4040#include <rtems/rtems/types.h>
    41 #include <rtems/rtems/eventset.h>
     41#include <rtems/rtems/event.h>
    4242#include <rtems/rtems/asr.h>
    4343#include <rtems/rtems/attr.h>
     
    211211 */
    212212typedef struct {
    213   /** This field contains the pending events for this task. */
    214   rtems_event_set          pending_events;
     213  /** This field contains the event control for this task. */
     214  Event_Control            Event;
    215215  /** This field contains the Classic API Signal information for this task. */
    216216  ASR_Information          Signal;
  • cpukit/rtems/inline/rtems/rtems/event.inl

    rf8657bbd r990575c  
    2626 */
    2727
     28RTEMS_INLINE_ROUTINE void _Event_Initialize( Event_Control *event )
     29{
     30  event->pending_events = EVENT_SETS_NONE_PENDING;
     31}
     32
    2833/**@}*/
    2934
  • cpukit/rtems/inline/rtems/rtems/eventset.inl

    rf8657bbd r990575c  
    2121
    2222#include <rtems/score/basedefs.h> /* RTEMS_INLINE_ROUTINE */
    23 #include <rtems/score/isr.h> /* ISR_Level */
    2423
    2524/**
     
    5251)
    5352{
    54   ISR_Level level;
    55 
    56   _ISR_Disable( level );
    57     *the_event_set |= the_new_events;
    58   _ISR_Enable( level );
     53  *the_event_set |= the_new_events;
    5954}
    6055
  • cpukit/rtems/src/eventreceive.c

    rf8657bbd r990575c  
    1111
    1212#if HAVE_CONFIG_H
    13 #include "config.h"
     13  #include "config.h"
    1414#endif
    1515
    16 #include <rtems/system.h>
    17 #include <rtems/rtems/status.h>
    1816#include <rtems/rtems/event.h>
    19 #include <rtems/score/isr.h>
    20 #include <rtems/score/object.h>
    21 #include <rtems/rtems/options.h>
    22 #include <rtems/score/states.h>
    23 #include <rtems/score/thread.h>
    2417#include <rtems/rtems/tasks.h>
    25 
    26 /*
    27  *  rtems_event_receive
    28  *
    29  *  This directive allows a thread to receive a set of events.
    30  *
    31  *  Input parameters:
    32  *    event_in   - input event condition
    33  *    option_set - options
    34  *    ticks      - number of ticks to wait (0 means wait forever)
    35  *    event_out  - pointer to output event set
    36  *
    37  *  Output parameters:
    38  *    event out         - event set
    39  *    RTEMS_SUCCESSFUL - if successful
    40  *    error code        - if unsuccessful
    41  */
    4218
    4319rtems_status_code rtems_event_receive(
     
    4824)
    4925{
    50   RTEMS_API_Control       *api;
     26  rtems_status_code sc;
    5127
    52   if ( !event_out )
    53     return RTEMS_INVALID_ADDRESS;
     28  if ( event_out != NULL ) {
     29    Thread_Control    *executing = _Thread_Executing;
     30    RTEMS_API_Control *api = executing->API_Extensions[ THREAD_API_RTEMS ];
     31    Event_Control     *event = &api->Event;
    5432
    55   api = _Thread_Executing->API_Extensions[ THREAD_API_RTEMS ];
     33    if ( !_Event_sets_Is_empty( event_in ) ) {
     34      _Thread_Disable_dispatch();
     35      _Event_Seize(
     36        event_in,
     37        option_set,
     38        ticks,
     39        event_out,
     40        executing,
     41        event,
     42        &_Event_Sync_state,
     43        STATES_WAITING_FOR_EVENT
     44      );
     45      _Thread_Enable_dispatch();
    5646
    57   if ( _Event_sets_Is_empty( event_in ) ) {
    58     *event_out = api->pending_events;
    59     return RTEMS_SUCCESSFUL;
     47      sc = executing->Wait.return_code;
     48    } else {
     49      *event_out = event->pending_events;
     50      sc = RTEMS_SUCCESSFUL;
     51    }
     52  } else {
     53    sc = RTEMS_INVALID_ADDRESS;
    6054  }
    6155
    62   _Thread_Disable_dispatch();
    63   _Event_Seize( event_in, option_set, ticks, event_out );
    64   _Thread_Enable_dispatch();
    65   return( _Thread_Executing->Wait.return_code );
     56  return sc;
    6657}
  • cpukit/rtems/src/eventseize.c

    rf8657bbd r990575c  
    1111
    1212#if HAVE_CONFIG_H
    13 #include "config.h"
     13  #include "config.h"
    1414#endif
    1515
    16 #include <rtems/system.h>
    17 #include <rtems/rtems/status.h>
    1816#include <rtems/rtems/event.h>
    19 #include <rtems/score/isr.h>
    20 #include <rtems/score/object.h>
    21 #include <rtems/rtems/options.h>
    22 #include <rtems/score/states.h>
    23 #include <rtems/score/thread.h>
    24 #include <rtems/rtems/tasks.h>
    2517
    2618/*
    27  *  _Event_Seize
    28  *
    29  *  This routine attempts to satisfy the requested event condition
    30  *  for the running thread.
    31  *
    32  *  Input parameters:
    33  *    event_in   - the event condition to satisfy
    34  *    option_set - acquire event options
    35  *    ticks      - interval to wait
    36  *    event_out  - pointer to event set output area
    37  *
    38  *  Output parameters: NONE
    39  *    *event_out - event set output area filled in
    40  *
    4119 *  INTERRUPT LATENCY:
    4220 *    available
     
    4624
    4725void _Event_Seize(
    48   rtems_event_set  event_in,
    49   rtems_option     option_set,
    50   rtems_interval   ticks,
    51   rtems_event_set *event_out
     26  rtems_event_set                   event_in,
     27  rtems_option                      option_set,
     28  rtems_interval                    ticks,
     29  rtems_event_set                  *event_out,
     30  Thread_Control                   *executing,
     31  Event_Control                    *event,
     32  Thread_blocking_operation_States *sync_state,
     33  States_Control                    wait_state
    5234)
    5335{
    54   Thread_Control                   *executing;
    55   rtems_event_set                   seized_events;
    56   rtems_event_set                   pending_events;
    57   ISR_Level                         level;
    58   RTEMS_API_Control                *api;
    59   Thread_blocking_operation_States  sync_state;
     36  rtems_event_set                  seized_events;
     37  rtems_event_set                  pending_events;
     38  ISR_Level                        level;
     39  Thread_blocking_operation_States current_sync_state;
    6040
    61   executing = _Thread_Executing;
    6241  executing->Wait.return_code = RTEMS_SUCCESSFUL;
    6342
    64   api = executing->API_Extensions[ THREAD_API_RTEMS ];
    65 
    6643  _ISR_Disable( level );
    67   pending_events = api->pending_events;
     44  pending_events = event->pending_events;
    6845  seized_events  = _Event_sets_Get( pending_events, event_in );
    6946
    7047  if ( !_Event_sets_Is_empty( seized_events ) &&
    7148       (seized_events == event_in || _Options_Is_any( option_set )) ) {
    72     api->pending_events =
     49    event->pending_events =
    7350      _Event_sets_Clear( pending_events, seized_events );
    7451    _ISR_Enable( level );
     
    9269   *        issue but better safe than sorry.
    9370   */
    94   executing->Wait.option            = (uint32_t) option_set;
    95   executing->Wait.count             = (uint32_t) event_in;
     71  executing->Wait.option            = option_set;
     72  executing->Wait.count             = event_in;
    9673  executing->Wait.return_argument   = event_out;
    9774
    98   _Event_Sync_state = THREAD_BLOCKING_OPERATION_NOTHING_HAPPENED;
     75  *sync_state = THREAD_BLOCKING_OPERATION_NOTHING_HAPPENED;
    9976
    10077  _ISR_Enable( level );
     
    11087  }
    11188
    112   _Thread_Set_state( executing, STATES_WAITING_FOR_EVENT );
     89  _Thread_Set_state( executing, wait_state );
    11390
    11491  _ISR_Disable( level );
    11592
    116   sync_state = _Event_Sync_state;
    117   _Event_Sync_state = THREAD_BLOCKING_OPERATION_SYNCHRONIZED;
    118   if ( sync_state == THREAD_BLOCKING_OPERATION_NOTHING_HAPPENED ) {
     93  current_sync_state = *sync_state;
     94  *sync_state = THREAD_BLOCKING_OPERATION_SYNCHRONIZED;
     95  if ( current_sync_state == THREAD_BLOCKING_OPERATION_NOTHING_HAPPENED ) {
    11996    _ISR_Enable( level );
    12097    return;
     
    128105   *  enabled!
    129106   */
    130   _Thread_blocking_operation_Cancel( sync_state, executing, level );
     107  _Thread_blocking_operation_Cancel( current_sync_state, executing, level );
    131108}
  • cpukit/rtems/src/eventsend.c

    rf8657bbd r990575c  
    1111
    1212#if HAVE_CONFIG_H
    13 #include "config.h"
     13  #include "config.h"
    1414#endif
    1515
    16 #include <rtems/system.h>
    17 #include <rtems/rtems/status.h>
    1816#include <rtems/rtems/event.h>
    19 #include <rtems/score/isr.h>
    20 #include <rtems/score/object.h>
    21 #include <rtems/rtems/options.h>
    22 #include <rtems/score/states.h>
    23 #include <rtems/score/thread.h>
    2417#include <rtems/rtems/tasks.h>
    2518
    26 /*
    27  *  rtems_event_send
    28  *
    29  *  This directive allows a thread send an event set to another thread.
    30  *
    31  *  Input parameters:
    32  *    id    - thread id
    33  *    event - event set
    34  *
    35  *  Output parameters:
    36  *    RTEMS_SUCCESSFUL - if successful
    37  *    error code - if unsuccessful
    38  */
    39 
    4019rtems_status_code rtems_event_send(
    41   rtems_id          id,
    42   rtems_event_set   event_in
     20  rtems_id        id,
     21  rtems_event_set event_in
    4322)
    4423{
    45   register Thread_Control *the_thread;
    46   Objects_Locations        location;
    47   RTEMS_API_Control       *api;
     24  rtems_status_code  sc;
     25  Thread_Control    *thread;
     26  Objects_Locations  location;
     27  RTEMS_API_Control *api;
    4828
    49   the_thread = _Thread_Get( id, &location );
     29  thread = _Thread_Get( id, &location );
    5030  switch ( location ) {
    51 
    5231    case OBJECTS_LOCAL:
    53       api = the_thread->API_Extensions[ THREAD_API_RTEMS ];
    54       _Event_sets_Post( event_in, &api->pending_events );
    55       _Event_Surrender( the_thread );
     32      api = thread->API_Extensions[ THREAD_API_RTEMS ];
     33      _Event_Surrender(
     34        thread,
     35        event_in,
     36        &api->Event,
     37        &_Event_Sync_state,
     38        STATES_WAITING_FOR_EVENT
     39      );
    5640      _Thread_Enable_dispatch();
    57       return RTEMS_SUCCESSFUL;
    58 
    59 #if defined(RTEMS_MULTIPROCESSING)
     41      sc = RTEMS_SUCCESSFUL;
     42      break;
     43#ifdef RTEMS_MULTIPROCESSING
    6044    case OBJECTS_REMOTE:
    61       return(
    62         _Event_MP_Send_request_packet(
    63           EVENT_MP_SEND_REQUEST,
    64           id,
    65           event_in
    66         )
     45      sc = _Event_MP_Send_request_packet(
     46        EVENT_MP_SEND_REQUEST,
     47        id,
     48        event_in
    6749      );
     50      break;
    6851#endif
    69 
    70     case OBJECTS_ERROR:
     52    default:
     53      sc = RTEMS_INVALID_ID;
    7154      break;
    7255  }
    7356
    74   return RTEMS_INVALID_ID;
     57  return sc;
    7558}
  • cpukit/rtems/src/eventsurrender.c

    rf8657bbd r990575c  
    1111
    1212#if HAVE_CONFIG_H
    13 #include "config.h"
     13  #include "config.h"
    1414#endif
    1515
    16 #include <rtems/system.h>
    17 #include <rtems/rtems/status.h>
    1816#include <rtems/rtems/event.h>
    19 #include <rtems/score/isr.h>
    20 #include <rtems/score/object.h>
    21 #include <rtems/rtems/options.h>
    22 #include <rtems/score/states.h>
    23 #include <rtems/score/thread.h>
    24 #include <rtems/rtems/tasks.h>
    2517
    2618/*
    27  *  _Event_Surrender
    28  *
    29  *  This routines remove a thread from the specified threadq.
    30  *
    31  *  Input parameters:
    32  *    the_thread - pointer to thread to be dequeued
    33  *
    34  *  Output parameters: NONE
    35  *
    3619 *  INTERRUPT LATENCY:
    3720 *    before flash
     
    4124
    4225void _Event_Surrender(
    43   Thread_Control *the_thread
     26  Thread_Control                   *the_thread,
     27  rtems_event_set                   event_in,
     28  Event_Control                    *event,
     29  Thread_blocking_operation_States *sync_state,
     30  States_Control                    wait_state
    4431)
    4532{
    46   ISR_Level           level;
    47   rtems_event_set     pending_events;
    48   rtems_event_set     event_condition;
    49   rtems_event_set     seized_events;
    50   rtems_option        option_set;
    51   RTEMS_API_Control  *api;
     33  ISR_Level       level;
     34  rtems_event_set pending_events;
     35  rtems_event_set event_condition;
     36  rtems_event_set seized_events;
     37  rtems_option    option_set;
    5238
    53   api = the_thread->API_Extensions[ THREAD_API_RTEMS ];
    54 
    55   option_set = (rtems_option) the_thread->Wait.option;
     39  option_set = the_thread->Wait.option;
    5640
    5741  _ISR_Disable( level );
    58   pending_events  = api->pending_events;
    59   event_condition = (rtems_event_set) the_thread->Wait.count;
     42  _Event_sets_Post( event_in, &event->pending_events );
     43  pending_events  = event->pending_events;
     44  event_condition = the_thread->Wait.count;
    6045
    6146  seized_events = _Event_sets_Get( pending_events, event_condition );
     
    7560  if ( _ISR_Is_in_progress() &&
    7661       _Thread_Is_executing( the_thread ) &&
    77        ((_Event_Sync_state == THREAD_BLOCKING_OPERATION_TIMEOUT) ||
    78         (_Event_Sync_state == THREAD_BLOCKING_OPERATION_NOTHING_HAPPENED)) ) {
     62       ((*sync_state == THREAD_BLOCKING_OPERATION_TIMEOUT) ||
     63        (*sync_state == THREAD_BLOCKING_OPERATION_NOTHING_HAPPENED)) ) {
    7964    if ( seized_events == event_condition || _Options_Is_any(option_set) ) {
    80       api->pending_events = _Event_sets_Clear( pending_events,seized_events );
     65      event->pending_events = _Event_sets_Clear(
     66        pending_events,
     67        seized_events
     68      );
    8169      the_thread->Wait.count = 0;
    8270      *(rtems_event_set *)the_thread->Wait.return_argument = seized_events;
    83       _Event_Sync_state = THREAD_BLOCKING_OPERATION_SATISFIED;
     71      *sync_state = THREAD_BLOCKING_OPERATION_SATISFIED;
    8472    }
    8573    _ISR_Enable( level );
     
    9078   *  Otherwise, this is a normal send to another thread
    9179   */
    92   if ( _States_Is_waiting_for_event( the_thread->current_state ) ) {
     80  if ( _States_Are_set( the_thread->current_state, wait_state ) ) {
    9381    if ( seized_events == event_condition || _Options_Is_any( option_set ) ) {
    94       api->pending_events = _Event_sets_Clear( pending_events, seized_events );
     82      event->pending_events = _Event_sets_Clear(
     83        pending_events,
     84        seized_events
     85      );
    9586      the_thread->Wait.count = 0;
    9687      *(rtems_event_set *)the_thread->Wait.return_argument = seized_events;
  • cpukit/rtems/src/tasks.c

    rf8657bbd r990575c  
    6565  created->API_Extensions[ THREAD_API_RTEMS ] = api;
    6666
    67   api->pending_events = EVENT_SETS_NONE_PENDING;
     67  _Event_Initialize( &api->Event );
    6868  _ASR_Initialize( &api->Signal );
    6969  created->task_variables = NULL;
     
    9393  api = started->API_Extensions[ THREAD_API_RTEMS ];
    9494
    95   api->pending_events = EVENT_SETS_NONE_PENDING;
     95  _Event_Initialize( &api->Event );
    9696}
    9797
Note: See TracChangeset for help on using the changeset viewer.