From eb02f47b126b56091ffaeaad470a48e2ac6d57b5 Mon Sep 17 00:00:00 2001 From: Joel Sherrill Date: Wed, 10 Nov 1999 13:48:27 +0000 Subject: Committed modifications from ITRON Task and Task Dependendent Synchronization Working Group. Included are tests. --- c/src/exec/score/src/Makefile.in | 8 +-- c/src/exec/score/src/threadinitialize.c | 1 + c/src/exec/score/src/threadrestart.c | 3 +- c/src/exec/score/src/threadresume.c | 95 ++++++++++++++++++++++++++++++++ c/src/exec/score/src/threadrotatequeue.c | 93 +++++++++++++++++++++++++++++++ c/src/exec/score/src/threadsuspend.c | 83 ++++++++++++++++++++++++++++ 6 files changed, 278 insertions(+), 5 deletions(-) create mode 100644 c/src/exec/score/src/threadresume.c create mode 100644 c/src/exec/score/src/threadrotatequeue.c create mode 100644 c/src/exec/score/src/threadsuspend.c (limited to 'c/src/exec/score/src') diff --git a/c/src/exec/score/src/Makefile.in b/c/src/exec/score/src/Makefile.in index 28ad2ef6a3..99cce9fa76 100644 --- a/c/src/exec/score/src/Makefile.in +++ b/c/src/exec/score/src/Makefile.in @@ -42,10 +42,10 @@ OBJECT_C_PIECES = object objectallocate objectallocatebyindex \ THREAD_C_PIECES = thread threadchangepriority threadclearstate threadclose \ threadcreateidle threaddelayended threaddispatch threadevaluatemode \ threadget threadhandler threadidlebody threadinitialize threadloadenv \ - threadready threadresettimeslice threadrestart threadsetpriority \ - threadsetstate threadsettransient threadstackallocate threadstackfree \ - threadstart threadstartmultitasking threadtickletimeslice \ - threadyieldprocessor + threadready threadresettimeslice threadrestart threadresume \ + threadrotatequeue threadsetpriority threadsetstate threadsettransient \ + threadstackallocate threadstackfree threadstart threadstartmultitasking \ + threadsuspend threadtickletimeslice threadyieldprocessor THREADQ_C_PIECES= threadq threadqdequeue threadqdequeuefifo \ threadqdequeuepriority threadqenqueue threadqenqueuefifo \ diff --git a/c/src/exec/score/src/threadinitialize.c b/c/src/exec/score/src/threadinitialize.c index 28cfa324bc..f294d865bf 100644 --- a/c/src/exec/score/src/threadinitialize.c +++ b/c/src/exec/score/src/threadinitialize.c @@ -153,6 +153,7 @@ boolean _Thread_Initialize( the_thread->current_state = STATES_DORMANT; the_thread->resource_count = 0; + the_thread->suspend_count = 0; the_thread->real_priority = priority; the_thread->Start.initial_priority = priority; the_thread->ticks_executed = 0; diff --git a/c/src/exec/score/src/threadrestart.c b/c/src/exec/score/src/threadrestart.c index 7419514a4f..229dbe2d94 100644 --- a/c/src/exec/score/src/threadrestart.c +++ b/c/src/exec/score/src/threadrestart.c @@ -44,7 +44,8 @@ boolean _Thread_Restart( if ( !_States_Is_dormant( the_thread->current_state ) ) { _Thread_Set_transient( the_thread ); - the_thread->resource_count = 0; + the_thread->resource_count = 0; + the_thread->suspend_count = 0; the_thread->is_preemptible = the_thread->Start.is_preemptible; the_thread->budget_algorithm = the_thread->Start.budget_algorithm; the_thread->budget_callout = the_thread->Start.budget_callout; diff --git a/c/src/exec/score/src/threadresume.c b/c/src/exec/score/src/threadresume.c new file mode 100644 index 0000000000..067dc59610 --- /dev/null +++ b/c/src/exec/score/src/threadresume.c @@ -0,0 +1,95 @@ +/* + * Thread Handler + * + * + * COPYRIGHT (c) 1989-1998. + * On-Line Applications Research Corporation (OAR). + * Copyright assigned to U.S. Government, 1994. + * + * The license and distribution terms for this file may be + * found in found in the file LICENSE in this distribution or at + * http://www.OARcorp.com/rtems/license.html. + * + * $Id$ + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/*PAGE + * + * _Thread_Resume + * + * This kernel routine clears the SUSPEND state if the suspend_count + * drops below one. If the force parameter is set the suspend_count + * is forced back to zero. The thread ready chain is adjusted if + * necessary and the Heir thread is set accordingly. + * + * Input parameters: + * the_thread - pointer to thread control block + * force - force the suspend count back to 0 + * + * Output parameters: NONE + * + * INTERRUPT LATENCY: + * priority map + * select heir + */ + + +void _Thread_Resume( + Thread_Control *the_thread, + boolean force +) +{ + + ISR_Level level; + States_Control current_state; + + _ISR_Disable( level ); + + if ( force == TRUE ) + the_thread->suspend_count = 0; + else + the_thread->suspend_count--; + + if ( the_thread->suspend_count > 0 ) { + _ISR_Enable( level ); + return; + } + + current_state = the_thread->current_state; + if ( current_state & STATES_SUSPENDED ) { + current_state = + the_thread->current_state = _States_Clear(STATES_SUSPENDED, current_state); + + if ( _States_Is_ready( current_state ) ) { + + _Priority_Add_to_bit_map( &the_thread->Priority_map ); + + _Chain_Append_unprotected(the_thread->ready, &the_thread->Object.Node); + + _ISR_Flash( level ); + + if ( the_thread->current_priority < _Thread_Heir->current_priority ) { + _Thread_Heir = the_thread; + if ( _Thread_Executing->is_preemptible || + the_thread->current_priority == 0 ) + _Context_Switch_necessary = TRUE; + } + } + } + + _ISR_Enable( level ); +} diff --git a/c/src/exec/score/src/threadrotatequeue.c b/c/src/exec/score/src/threadrotatequeue.c new file mode 100644 index 0000000000..f7ee9c12f5 --- /dev/null +++ b/c/src/exec/score/src/threadrotatequeue.c @@ -0,0 +1,93 @@ +/* + * Thread Handler + * + * + * COPYRIGHT (c) 1989-1998. + * On-Line Applications Research Corporation (OAR). + * Copyright assigned to U.S. Government, 1994. + * + * The license and distribution terms for this file may be + * found in found in the file LICENSE in this distribution or at + * http://www.OARcorp.com/rtems/license.html. + * + * $Id$ + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/*PAGE + * + * _Thread_Rotate_Ready_Queue + * + * This kernel routine will rotate the ready queue. + * remove the running THREAD from the ready chain + * and place it immediatly at the rear of this chain. Reset timeslice + * and yield the processor functions both use this routine, therefore if + * reset is TRUE and this is the only thread on the chain then the + * timeslice counter is reset. The heir THREAD will be updated if the + * running is also the currently the heir. + * + * Input parameters: + * Priority of the queue we wish to modify. + * + * Output parameters: NONE + * + * INTERRUPT LATENCY: + * ready chain + * select heir + */ + +void _Thread_Rotate_Ready_Queue( + Priority_Control priority +) +{ + ISR_Level level; + Thread_Control *executing; + Chain_Control *ready; + Chain_Node *node; + + ready = &_Thread_Ready_chain[ priority ]; + executing = _Thread_Executing; + + if ( ready == executing->ready ) { + _Thread_Yield_processor(); + return; + } + + _ISR_Disable( level ); + + if ( !_Chain_Is_empty( ready ) ) { + if (!_Chain_Has_only_one_node( ready ) ) { + node = _Chain_Get_first_unprotected( ready ); + _Chain_Append_unprotected( ready, node ); + } + } + + _ISR_Flash( level ); + + if ( _Thread_Heir->ready == ready ) + _Thread_Heir = (Thread_Control *) ready->first; + + if ( executing != _Thread_Heir ) + _Context_Switch_necessary = TRUE; + + _ISR_Enable( level ); +} + + + + + + diff --git a/c/src/exec/score/src/threadsuspend.c b/c/src/exec/score/src/threadsuspend.c new file mode 100644 index 0000000000..82363054e5 --- /dev/null +++ b/c/src/exec/score/src/threadsuspend.c @@ -0,0 +1,83 @@ +/* + * Thread Handler + * + * + * COPYRIGHT (c) 1989-1998. + * On-Line Applications Research Corporation (OAR). + * Copyright assigned to U.S. Government, 1994. + * + * The license and distribution terms for this file may be + * found in found in the file LICENSE in this distribution or at + * http://www.OARcorp.com/rtems/license.html. + * + * $Id$ + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/*PAGE + * + * _Thread_Suspend + * + * This kernel routine sets the SUSPEND state in the THREAD. The + * THREAD chain and suspend count are adjusted if necessary. + * + * Input parameters: + * the_thread - pointer to thread control block + * + * Output parameters: NONE + * + * INTERRUPT LATENCY: + * ready chain + * select map + */ + +void _Thread_Suspend( + Thread_Control *the_thread +) +{ + ISR_Level level; + Chain_Control *ready; + + ready = the_thread->ready; + _ISR_Disable( level ); + the_thread->suspend_count++; + if ( !_States_Is_ready( the_thread->current_state ) ) { + the_thread->current_state = + _States_Set( STATES_SUSPENDED, the_thread->current_state ); + _ISR_Enable( level ); + return; + } + + the_thread->current_state = STATES_SUSPENDED; + + if ( _Chain_Has_only_one_node( ready ) ) { + + _Chain_Initialize_empty( ready ); + _Priority_Remove_from_bit_map( &the_thread->Priority_map ); + + } else + _Chain_Extract_unprotected( &the_thread->Object.Node ); + + _ISR_Flash( level ); + + if ( _Thread_Is_heir( the_thread ) ) + _Thread_Calculate_heir(); + + if ( _Thread_Is_executing( the_thread ) ) + _Context_Switch_necessary = TRUE; + + _ISR_Enable( level ); +} -- cgit v1.2.3