source: rtems/cpukit/rtems/src/eventsurrender.c @ 11c16a64

4.104.114.9
Last change on this file since 11c16a64 was 11c16a64, checked in by Joel Sherrill <joel.sherrill@…>, on Jan 22, 2008 at 9:19:18 PM

2008-01-22 Joel Sherrill <joel.sherrill@…>

  • rtems/src/eventsurrender.c, rtems/src/ratemonperiod.c, score/src/threadqdequeue.c, score/src/threadqdequeuefifo.c, score/src/threadqdequeuepriority.c: Fix bugs encountered while testing and clean up more code.
  • Property mode set to 100644
File size: 3.1 KB
Line 
1/*
2 *  Event Manager
3 *
4 *  COPYRIGHT (c) 1989-2008.
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_Surrender
31 *
32 *  This routines remove a thread from the specified threadq.
33 *
34 *  Input parameters:
35 *    the_thread - pointer to thread to be dequeued
36 *
37 *  Output parameters: NONE
38 *
39 *  INTERRUPT LATENCY:
40 *    before flash
41 *    after flash
42 *    check sync
43 */
44
45void _Event_Surrender(
46  Thread_Control *the_thread
47)
48{
49  ISR_Level           level;
50  rtems_event_set     pending_events;
51  rtems_event_set     event_condition;
52  rtems_event_set     seized_events;
53  rtems_option        option_set;
54  RTEMS_API_Control  *api;
55
56  api = the_thread->API_Extensions[ THREAD_API_RTEMS ];
57
58  option_set = (rtems_option) the_thread->Wait.option;
59
60  _ISR_Disable( level );
61  pending_events  = api->pending_events;
62  event_condition = (rtems_event_set) the_thread->Wait.count;
63
64  seized_events = _Event_sets_Get( pending_events, event_condition );
65
66  /*
67   *  No events were seized in this operation
68   */
69  if ( _Event_sets_Is_empty( seized_events ) ) {
70    _ISR_Enable( level );
71    return;
72  }
73
74  /*
75   *  If we are in an ISR and sending to the current thread, then
76   *  we have a critical section issue to deal with.
77   */
78  if ( _ISR_Is_in_progress() && 
79       _Thread_Is_executing( the_thread ) &&
80       ((_Event_Sync_state == THREAD_BLOCKING_OPERATION_NOTHING_HAPPENED) ||
81        (_Event_Sync_state == THREAD_BLOCKING_OPERATION_TIMEOUT)) ) {
82    if ( seized_events == event_condition || _Options_Is_any(option_set) ) {
83      api->pending_events = _Event_sets_Clear( pending_events,seized_events );
84      the_thread->Wait.count = 0; 
85      *(rtems_event_set *)the_thread->Wait.return_argument = seized_events;
86      _Event_Sync_state = THREAD_BLOCKING_OPERATION_SATISFIED;
87    }
88    _ISR_Enable( level );
89    return;
90  }
91
92  /*
93   *  Otherwise, this is a normal send to another thread
94   */
95  if ( _States_Is_waiting_for_event( the_thread->current_state ) ) {
96    if ( seized_events == event_condition || _Options_Is_any( option_set ) ) {
97      api->pending_events = _Event_sets_Clear( pending_events, seized_events );
98      the_thread->Wait.count = 0;
99      *(rtems_event_set *)the_thread->Wait.return_argument = seized_events;
100
101      _ISR_Flash( level );
102
103      if ( !_Watchdog_Is_active( &the_thread->Timer ) ) {
104        _ISR_Enable( level );
105        _Thread_Unblock( the_thread );
106      } else {
107        _Watchdog_Deactivate( &the_thread->Timer );
108        _ISR_Enable( level );
109        (void) _Watchdog_Remove( &the_thread->Timer );
110        _Thread_Unblock( the_thread );
111      }
112      return;
113    }
114  }
115  _ISR_Enable( level );
116}
Note: See TracBrowser for help on using the repository browser.