From 3168deaa10fae157b38a94c5204a66d28a43ad7a Mon Sep 17 00:00:00 2001 From: Joel Sherrill Date: Tue, 22 Jan 2008 18:28:53 +0000 Subject: 2008-01-22 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. --- cpukit/rtems/src/eventsurrender.c | 79 ++++++++++++++++++++------------------- 1 file changed, 41 insertions(+), 38 deletions(-) (limited to 'cpukit/rtems/src/eventsurrender.c') diff --git a/cpukit/rtems/src/eventsurrender.c b/cpukit/rtems/src/eventsurrender.c index 4c2d3b12ce..5fb53922f3 100644 --- a/cpukit/rtems/src/eventsurrender.c +++ b/cpukit/rtems/src/eventsurrender.c @@ -1,7 +1,7 @@ /* * Event Manager * - * COPYRIGHT (c) 1989-1999. + * COPYRIGHT (c) 1989-2008. * On-Line Applications Research Corporation (OAR). * * The license and distribution terms for this file may be @@ -63,48 +63,51 @@ void _Event_Surrender( seized_events = _Event_sets_Get( pending_events, event_condition ); - if ( !_Event_sets_Is_empty( seized_events ) ) { - if ( _States_Is_waiting_for_event( the_thread->current_state ) ) { - if ( seized_events == event_condition || _Options_Is_any( option_set ) ) { - api->pending_events = - _Event_sets_Clear( pending_events, seized_events ); - the_thread->Wait.count = 0; - *(rtems_event_set *)the_thread->Wait.return_argument = seized_events; + /* + * No events were seized in this operation + */ + if ( _Event_sets_Is_empty( seized_events ) ) + return; - _ISR_Flash( level ); - - if ( !_Watchdog_Is_active( &the_thread->Timer ) ) { - _ISR_Enable( level ); - _Thread_Unblock( the_thread ); - } - else { - _Watchdog_Deactivate( &the_thread->Timer ); - _ISR_Enable( level ); - (void) _Watchdog_Remove( &the_thread->Timer ); - _Thread_Unblock( the_thread ); - } - return; - } + /* + * If we are in an ISR and sending to the current thread, then + * we have a critical section issue to deal with. + */ + if ( _ISR_Is_in_progress() && + _Thread_Is_executing( the_thread ) && + ((_Event_Sync_state == THREAD_BLOCKING_OPERATION_NOTHING_HAPPENED) || + (_Event_Sync_state == THREAD_BLOCKING_OPERATION_TIMEOUT)) ) { + if ( seized_events == event_condition || _Options_Is_any(option_set) ) { + api->pending_events = _Event_sets_Clear( pending_events,seized_events ); + the_thread->Wait.count = 0; + *(rtems_event_set *)the_thread->Wait.return_argument = seized_events; + _Event_Sync_state = THREAD_BLOCKING_OPERATION_SATISFIED; } + _ISR_Enable( level ); + return; + } - switch ( _Event_Sync_state ) { - case EVENT_SYNC_SYNCHRONIZED: - case EVENT_SYNC_SATISFIED: - break; + /* + * Otherwise, this is a normal send to another thread + */ + if ( _States_Is_waiting_for_event( the_thread->current_state ) ) { + if ( seized_events == event_condition || _Options_Is_any( option_set ) ) { + api->pending_events = _Event_sets_Clear( pending_events, seized_events ); + the_thread->Wait.count = 0; + *(rtems_event_set *)the_thread->Wait.return_argument = seized_events; - case EVENT_SYNC_NOTHING_HAPPENED: - case EVENT_SYNC_TIMEOUT: - if ( !_Thread_Is_executing( the_thread ) ) - break; + _ISR_Flash( level ); - if ( seized_events == event_condition || _Options_Is_any(option_set) ) { - api->pending_events = - _Event_sets_Clear( pending_events,seized_events ); - the_thread->Wait.count = 0; - *(rtems_event_set *)the_thread->Wait.return_argument = seized_events; - _Event_Sync_state = EVENT_SYNC_SATISFIED; - } - break; + if ( !_Watchdog_Is_active( &the_thread->Timer ) ) { + _ISR_Enable( level ); + _Thread_Unblock( the_thread ); + } else { + _Watchdog_Deactivate( &the_thread->Timer ); + _ISR_Enable( level ); + (void) _Watchdog_Remove( &the_thread->Timer ); + _Thread_Unblock( the_thread ); + } + return; } } _ISR_Enable( level ); -- cgit v1.2.3