source: rtems/cpukit/rtems/src/eventseize.c @ f26145b

4.104.114.84.95
Last change on this file since f26145b was 1095ec1, checked in by Ralf Corsepius <ralf.corsepius@…>, on 01/18/05 at 09:03:45

Include config.h.

  • Property mode set to 100644
File size: 3.5 KB
Line 
1/*
2 *  Event Manager
3 *
4 *  COPYRIGHT (c) 1989-1999.
5 *  On-Line Applications Research Corporation (OAR).
6 *
7 *  The license and distribution terms for this file may be
8 *  found in the file LICENSE in this distribution or at
9 *  http://www.rtems.com/license/LICENSE.
10 *
11 *  $Id$
12 */
13
14#if HAVE_CONFIG_H
15#include "config.h"
16#endif
17
18#include <rtems/system.h>
19#include <rtems/rtems/status.h>
20#include <rtems/rtems/event.h>
21#include <rtems/score/isr.h>
22#include <rtems/score/object.h>
23#include <rtems/rtems/options.h>
24#include <rtems/score/states.h>
25#include <rtems/score/thread.h>
26#include <rtems/rtems/tasks.h>
27
28/*PAGE
29 *
30 *  _Event_Seize
31 *
32 *  This routine attempts to satisfy the requested event condition
33 *  for the running thread.
34 *
35 *  Input parameters:
36 *    event_in   - the event condition to satisfy
37 *    option_set - acquire event options
38 *    ticks      - interval to wait
39 *    event_out  - pointer to event set output area
40 *
41 *  Output parameters: NONE
42 *    *event_out - event set output area filled in
43 *
44 *  INTERRUPT LATENCY:
45 *    available
46 *    wait
47 *    check sync
48 */
49
50void _Event_Seize(
51  rtems_event_set  event_in,
52  rtems_option     option_set,
53  rtems_interval   ticks,
54  rtems_event_set *event_out
55)
56{
57  Thread_Control    *executing;
58  rtems_event_set    seized_events;
59  rtems_event_set    pending_events;
60  ISR_Level          level;
61  RTEMS_API_Control  *api;
62  Event_Sync_states   sync_state;
63
64  executing = _Thread_Executing;
65  executing->Wait.return_code = RTEMS_SUCCESSFUL;
66
67  api = executing->API_Extensions[ THREAD_API_RTEMS ];
68
69  _ISR_Disable( level );
70  pending_events = api->pending_events;
71  seized_events  = _Event_sets_Get( pending_events, event_in );
72
73  if ( !_Event_sets_Is_empty( seized_events ) &&
74       (seized_events == event_in || _Options_Is_any( option_set )) ) {
75    api->pending_events =
76      _Event_sets_Clear( pending_events, seized_events );
77    _ISR_Enable( level );
78    *event_out = seized_events;
79    return;
80  }
81
82  if ( _Options_Is_no_wait( option_set ) ) {
83    _ISR_Enable( level );
84    executing->Wait.return_code = RTEMS_UNSATISFIED;
85    *event_out = seized_events;
86    return;
87  }
88
89  _Event_Sync_state = EVENT_SYNC_NOTHING_HAPPENED;
90
91  executing->Wait.option            = (uint32_t  ) option_set;
92  executing->Wait.count             = (uint32_t  ) event_in;
93  executing->Wait.return_argument   = event_out;
94
95  _ISR_Enable( level );
96
97  if ( ticks ) {
98    _Watchdog_Initialize(
99      &executing->Timer,
100      _Event_Timeout,
101      executing->Object.id,
102      NULL
103    );
104    _Watchdog_Insert_ticks( &executing->Timer, ticks );
105  }
106
107  _Thread_Set_state( executing, STATES_WAITING_FOR_EVENT );
108
109  _ISR_Disable( level );
110
111  sync_state = _Event_Sync_state;
112  _Event_Sync_state = EVENT_SYNC_SYNCHRONIZED;
113
114  switch ( sync_state ) {
115    case EVENT_SYNC_SYNCHRONIZED:
116      /*
117       *  This cannot happen.  It indicates that this routine did not
118       *  enter the synchronization states above.
119       */
120      return;
121
122    case EVENT_SYNC_NOTHING_HAPPENED:
123      _ISR_Enable( level );
124      return;
125
126    case EVENT_SYNC_TIMEOUT:
127      executing->Wait.return_code = RTEMS_TIMEOUT;
128      _ISR_Enable( level );
129      _Thread_Unblock( executing );
130      return;
131
132    case EVENT_SYNC_SATISFIED:
133      if ( _Watchdog_Is_active( &executing->Timer ) ) {
134        _Watchdog_Deactivate( &executing->Timer );
135        _ISR_Enable( level );
136        (void) _Watchdog_Remove( &executing->Timer );
137      } else
138        _ISR_Enable( level );
139      _Thread_Unblock( executing );
140      return;
141  }
142}
Note: See TracBrowser for help on using the repository browser.