source: rtems/cpukit/rtems/src/eventsurrender.c @ 3168deaa

4.104.114.9
Last change on this file since 3168deaa was 3168deaa, checked in by Joel Sherrill <joel.sherrill@…>, on Jan 22, 2008 at 6:28:53 PM

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

  • rtems/include/rtems/rtems/event.h, rtems/inline/rtems/rtems/eventset.inl, rtems/src/event.c, rtems/src/eventseize.c, rtems/src/eventsurrender.c, rtems/src/eventtimeout.c, score/Makefile.am, score/preinstall.am, score/include/rtems/score/interr.h, score/include/rtems/score/thread.h, score/include/rtems/score/threadq.h, score/include/rtems/score/tqdata.h, score/inline/rtems/score/threadq.inl, score/inline/rtems/score/tqdata.inl, score/src/threadq.c, score/src/threadqdequeue.c, score/src/threadqdequeuefifo.c, score/src/threadqdequeuepriority.c, score/src/threadqenqueue.c, score/src/threadqenqueuefifo.c, score/src/threadqenqueuepriority.c, score/src/threadqextract.c, score/src/threadqextractfifo.c, score/src/threadqextractpriority.c, score/src/threadqextractwithproxy.c, score/src/threadqfirst.c, score/src/threadqfirstfifo.c, score/src/threadqfirstpriority.c, score/src/threadqflush.c, score/src/threadqrequeue.c, score/src/threadqtimeout.c: Refactor thread queue enqueue and event blocking synchronization critical sections. This resulted in three copies of essentially the same hard to test critical section code becoming the one shared routine _Thread_blocking_operation_Cancel. In addition, the thread queue and event code now share a common synchronization enumerated type. Along the way, switches were reworked to eliminate dead code generated by gcc and comments and copyrights were updated.
  • score/include/rtems/score/threadsync.h, score/src/threadblockingoperationcancel.c: New files.
  • 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    return;
71
72  /*
73   *  If we are in an ISR and sending to the current thread, then
74   *  we have a critical section issue to deal with.
75   */
76  if ( _ISR_Is_in_progress() && 
77       _Thread_Is_executing( the_thread ) &&
78       ((_Event_Sync_state == THREAD_BLOCKING_OPERATION_NOTHING_HAPPENED) ||
79        (_Event_Sync_state == THREAD_BLOCKING_OPERATION_TIMEOUT)) ) {
80    if ( seized_events == event_condition || _Options_Is_any(option_set) ) {
81      api->pending_events = _Event_sets_Clear( pending_events,seized_events );
82      the_thread->Wait.count = 0; 
83      *(rtems_event_set *)the_thread->Wait.return_argument = seized_events;
84      _Event_Sync_state = THREAD_BLOCKING_OPERATION_SATISFIED;
85    }
86    _ISR_Enable( level );
87    return;
88  }
89
90  /*
91   *  Otherwise, this is a normal send to another thread
92   */
93  if ( _States_Is_waiting_for_event( the_thread->current_state ) ) {
94    if ( seized_events == event_condition || _Options_Is_any( option_set ) ) {
95      api->pending_events = _Event_sets_Clear( pending_events, seized_events );
96      the_thread->Wait.count = 0;
97      *(rtems_event_set *)the_thread->Wait.return_argument = seized_events;
98
99      _ISR_Flash( level );
100
101      if ( !_Watchdog_Is_active( &the_thread->Timer ) ) {
102        _ISR_Enable( level );
103        _Thread_Unblock( the_thread );
104      } else {
105        _Watchdog_Deactivate( &the_thread->Timer );
106        _ISR_Enable( level );
107        (void) _Watchdog_Remove( &the_thread->Timer );
108        _Thread_Unblock( the_thread );
109      }
110      return;
111    }
112  }
113  _ISR_Enable( level );
114}
Note: See TracBrowser for help on using the repository browser.