summaryrefslogtreecommitdiffstats
path: root/cpukit/rtems
diff options
context:
space:
mode:
authorJoel Sherrill <joel.sherrill@OARcorp.com>2008-01-22 18:28:53 +0000
committerJoel Sherrill <joel.sherrill@OARcorp.com>2008-01-22 18:28:53 +0000
commit3168deaa10fae157b38a94c5204a66d28a43ad7a (patch)
tree0bda84e785960fa6641c2b167d626cf3271b3352 /cpukit/rtems
parent2008-01-22 Joel Sherrill <joel.sherrill@OARcorp.com> (diff)
downloadrtems-3168deaa10fae157b38a94c5204a66d28a43ad7a.tar.bz2
2008-01-22 Joel Sherrill <joel.sherrill@oarcorp.com>
* 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.
Diffstat (limited to 'cpukit/rtems')
-rw-r--r--cpukit/rtems/include/rtems/rtems/event.h17
-rw-r--r--cpukit/rtems/inline/rtems/rtems/eventset.inl2
-rw-r--r--cpukit/rtems/src/event.c4
-rw-r--r--cpukit/rtems/src/eventseize.c57
-rw-r--r--cpukit/rtems/src/eventsurrender.c79
-rw-r--r--cpukit/rtems/src/eventtimeout.c31
6 files changed, 83 insertions, 107 deletions
diff --git a/cpukit/rtems/include/rtems/rtems/event.h b/cpukit/rtems/include/rtems/rtems/event.h
index 4d2b4513fe..68687af31e 100644
--- a/cpukit/rtems/include/rtems/rtems/event.h
+++ b/cpukit/rtems/include/rtems/rtems/event.h
@@ -13,7 +13,7 @@
* + receive event condition
*
*
- * COPYRIGHT (c) 1989-2007.
+ * COPYRIGHT (c) 1989-2008.
* On-Line Applications Research Corporation (OAR).
*
* The license and distribution terms for this file may be
@@ -39,6 +39,7 @@ extern "C" {
#include <rtems/rtems/types.h>
#include <rtems/rtems/options.h>
#include <rtems/score/thread.h>
+#include <rtems/score/threadsync.h>
#include <rtems/score/watchdog.h>
#include <rtems/rtems/eventset.h>
@@ -50,18 +51,6 @@ extern "C" {
#define EVENT_CURRENT 0
/*
- * The following enumerated types indicate what happened while the event
- * manager was in the synchronization window.
- */
-
-typedef enum {
- EVENT_SYNC_SYNCHRONIZED,
- EVENT_SYNC_NOTHING_HAPPENED,
- EVENT_SYNC_TIMEOUT,
- EVENT_SYNC_SATISFIED
-} Event_Sync_states;
-
-/*
* Event_Manager_initialization
*
* DESCRIPTION:
@@ -166,7 +155,7 @@ void _Event_Timeout (
* executing thread are received properly.
*/
-RTEMS_EVENT_EXTERN volatile Event_Sync_states _Event_Sync_state;
+RTEMS_EVENT_EXTERN volatile Thread_blocking_operation_States _Event_Sync_state;
#if defined(RTEMS_MULTIPROCESSING)
#include <rtems/rtems/eventmp.h>
diff --git a/cpukit/rtems/inline/rtems/rtems/eventset.inl b/cpukit/rtems/inline/rtems/rtems/eventset.inl
index 05f0e805d4..dff78bdce0 100644
--- a/cpukit/rtems/inline/rtems/rtems/eventset.inl
+++ b/cpukit/rtems/inline/rtems/rtems/eventset.inl
@@ -5,7 +5,7 @@
/*
* This include file contains the information pertaining to event sets.
*
- * COPYRIGHT (c) 1989-1999.
+ * COPYRIGHT (c) 1989-2008.
* On-Line Applications Research Corporation (OAR).
*
* The license and distribution terms for this file may be
diff --git a/cpukit/rtems/src/event.c b/cpukit/rtems/src/event.c
index ebc5682cde..85d35829c2 100644
--- a/cpukit/rtems/src/event.c
+++ b/cpukit/rtems/src/event.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
@@ -36,7 +36,7 @@
void _Event_Manager_initialization( void )
{
- _Event_Sync_state = EVENT_SYNC_SYNCHRONIZED;
+ _Event_Sync_state = THREAD_BLOCKING_OPERATION_SYNCHRONIZED;
/*
* Register the MP Process Packet routine.
diff --git a/cpukit/rtems/src/eventseize.c b/cpukit/rtems/src/eventseize.c
index d9e0797747..9abb54fa6a 100644
--- a/cpukit/rtems/src/eventseize.c
+++ b/cpukit/rtems/src/eventseize.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
@@ -54,12 +54,12 @@ void _Event_Seize(
rtems_event_set *event_out
)
{
- Thread_Control *executing;
- rtems_event_set seized_events;
- rtems_event_set pending_events;
- ISR_Level level;
- RTEMS_API_Control *api;
- Event_Sync_states sync_state;
+ Thread_Control *executing;
+ rtems_event_set seized_events;
+ rtems_event_set pending_events;
+ ISR_Level level;
+ RTEMS_API_Control *api;
+ Thread_blocking_operation_States sync_state;
executing = _Thread_Executing;
executing->Wait.return_code = RTEMS_SUCCESSFUL;
@@ -86,7 +86,7 @@ void _Event_Seize(
return;
}
- _Event_Sync_state = EVENT_SYNC_NOTHING_HAPPENED;
+ _Event_Sync_state = THREAD_BLOCKING_OPERATION_NOTHING_HAPPENED;
executing->Wait.option = (uint32_t) option_set;
executing->Wait.count = (uint32_t) event_in;
@@ -109,34 +109,17 @@ void _Event_Seize(
_ISR_Disable( level );
sync_state = _Event_Sync_state;
- _Event_Sync_state = EVENT_SYNC_SYNCHRONIZED;
-
- switch ( sync_state ) {
- case EVENT_SYNC_SYNCHRONIZED:
- /*
- * This cannot happen. It indicates that this routine did not
- * enter the synchronization states above.
- */
- break;
-
- case EVENT_SYNC_NOTHING_HAPPENED:
- _ISR_Enable( level );
- break;
-
- case EVENT_SYNC_TIMEOUT:
- executing->Wait.return_code = RTEMS_TIMEOUT;
- _ISR_Enable( level );
- _Thread_Unblock( executing );
- break;
-
- case EVENT_SYNC_SATISFIED:
- if ( _Watchdog_Is_active( &executing->Timer ) ) {
- _Watchdog_Deactivate( &executing->Timer );
- _ISR_Enable( level );
- (void) _Watchdog_Remove( &executing->Timer );
- } else
- _ISR_Enable( level );
- _Thread_Unblock( executing );
- break;
+ _Event_Sync_state = THREAD_BLOCKING_OPERATION_SYNCHRONIZED;
+ if ( sync_state == THREAD_BLOCKING_OPERATION_NOTHING_HAPPENED ) {
+ _ISR_Enable( level );
+ return;
}
+
+ /*
+ * An interrupt completed the thread's blocking request.
+ * The blocking thread was satisfied by an ISR or timed out.
+ *
+ * WARNING! Returning with interrupts disabled!
+ */
+ _Thread_blocking_operation_Cancel( sync_state, executing, level );
}
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 );
diff --git a/cpukit/rtems/src/eventtimeout.c b/cpukit/rtems/src/eventtimeout.c
index b01d8199ad..04abe71766 100644
--- a/cpukit/rtems/src/eventtimeout.c
+++ b/cpukit/rtems/src/eventtimeout.c
@@ -1,7 +1,7 @@
/*
* Event Manager
*
- * COPYRIGHT (c) 1989-2007.
+ * COPYRIGHT (c) 1989-2008.
* On-Line Applications Research Corporation (OAR).
*
* The license and distribution terms for this file may be
@@ -64,25 +64,26 @@ void _Event_Timeout(
* a timeout is not allowed to occur.
*/
+
_ISR_Disable( level );
- if ( the_thread->Wait.count ) { /* verify thread is waiting */
+ if ( !the_thread->Wait.count ) { /* verify thread is waiting */
+ _Thread_Unnest_dispatch();
+ _ISR_Enable( level );
+ return;
+ }
+
the_thread->Wait.count = 0;
- if ( _Event_Sync_state != EVENT_SYNC_SYNCHRONIZED &&
- _Thread_Is_executing( the_thread ) ) {
- if ( _Event_Sync_state != EVENT_SYNC_SATISFIED ) {
- _Event_Sync_state = EVENT_SYNC_TIMEOUT;
+ if ( _Thread_Is_executing( the_thread ) ) {
+ Thread_blocking_operation_States sync = _Event_Sync_state;
+ if ( (sync == THREAD_BLOCKING_OPERATION_SYNCHRONIZED) ||
+ (sync == THREAD_BLOCKING_OPERATION_NOTHING_HAPPENED) ) {
+ _Event_Sync_state = THREAD_BLOCKING_OPERATION_TIMEOUT;
}
- _ISR_Enable( level );
- } else {
- the_thread->Wait.return_code = RTEMS_TIMEOUT;
- _ISR_Enable( level );
- _Thread_Unblock( the_thread );
}
- }
- else {
- _ISR_Enable( level );
- }
+ the_thread->Wait.return_code = RTEMS_TIMEOUT;
+ _ISR_Enable( level );
+ _Thread_Unblock( the_thread );
_Thread_Unnest_dispatch();
break;