score: Move _Thread_blocking_operation_Cancel()

Move _Thread_blocking_operation_Cancel() and make static since it is
only used by _Thread_queue_Enqueue_with_handler().

Move _Thread_blocking_operation_Finalize().
This commit is contained in:
Sebastian Huber
2015-03-22 10:37:52 +01:00
parent 40a2466164
commit 24297668a3
4 changed files with 90 additions and 124 deletions

View File

@@ -288,8 +288,7 @@ libscore_a_SOURCES += src/thread.c src/threadchangepriority.c \
src/threadrestart.c src/threadsetpriority.c \
src/threadsetstate.c \
src/threadstackallocate.c src/threadstackfree.c src/threadstart.c \
src/threadstartmultitasking.c src/iterateoverthreads.c \
src/threadblockingoperationcancel.c
src/threadstartmultitasking.c src/iterateoverthreads.c
libscore_a_SOURCES += src/threadglobalconstruction.c
libscore_a_SOURCES += src/threadyield.c

View File

@@ -417,30 +417,6 @@ Thread_Control *_Thread_Acquire(
*/
Thread_Control *_Thread_Acquire_executing( ISR_lock_Context *lock_context );
/**
* @brief Cancel a blocking operation due to ISR.
*
* This method is used to cancel a blocking operation that was
* satisfied from an ISR while the thread executing was in the
* process of blocking.
*
* This method will restore the previous ISR disable level during the cancel
* operation. Thus it is an implicit _ISR_Enable().
*
* @param[in] sync_state is the synchronization state
* @param[in] the_thread is the thread whose blocking is canceled
* @param[in] level is the previous ISR disable level
*
* @note This is a rare routine in RTEMS. It is called with
* interrupts disabled and only when an ISR completed
* a blocking condition in process.
*/
void _Thread_blocking_operation_Cancel(
Thread_blocking_operation_States sync_state,
Thread_Control *the_thread,
ISR_Level level
);
/**
* @brief Finalize a blocking operation.
*

View File

@@ -1,98 +0,0 @@
/**
* @file
*
* @brief Cancel a Blocking Operation
* @ingroup ScoreThread
*/
/*
* COPYRIGHT (c) 1989-2007.
* On-Line Applications Research Corporation (OAR).
*
* The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at
* http://www.rtems.org/license/LICENSE.
*/
#if HAVE_CONFIG_H
#include "config.h"
#endif
#include <rtems/score/threadimpl.h>
#if defined(RTEMS_DEBUG)
#include <rtems/score/interr.h>
#endif
#include <rtems/score/watchdogimpl.h>
void _Thread_blocking_operation_Finalize(
Thread_Control *the_thread,
ISR_Level level
)
{
/*
* The thread is not waiting on anything after this completes.
*/
the_thread->Wait.queue = NULL;
/*
* If the sync state is timed out, this is very likely not needed.
* But better safe than sorry when it comes to critical sections.
*/
if ( _Watchdog_Is_active( &the_thread->Timer ) ) {
_Watchdog_Deactivate( &the_thread->Timer );
_ISR_Enable( level );
(void) _Watchdog_Remove( &the_thread->Timer );
} else
_ISR_Enable( level );
/*
* Global objects with thread queue's should not be operated on from an
* ISR. But the sync code still must allow short timeouts to be processed
* correctly.
*/
_Thread_Unblock( the_thread );
#if defined(RTEMS_MULTIPROCESSING)
if ( !_Objects_Is_local_id( the_thread->Object.id ) )
_Thread_MP_Free_proxy( the_thread );
#endif
}
void _Thread_blocking_operation_Cancel(
#if defined(RTEMS_DEBUG)
Thread_blocking_operation_States sync_state,
#else
Thread_blocking_operation_States sync_state __attribute__((unused)),
#endif
Thread_Control *the_thread,
ISR_Level level
)
{
/*
* Cases that should not happen and why.
*
* THREAD_BLOCKING_OPERATION_SYNCHRONIZED:
*
* This indicates that someone did not enter a blocking
* operation critical section.
*
* THREAD_BLOCKING_OPERATION_NOTHING_HAPPENED:
*
* This indicates that there was nothing to cancel so
* we should not have been called.
*/
#if defined(RTEMS_DEBUG)
if ( (sync_state == THREAD_BLOCKING_OPERATION_SYNCHRONIZED) ||
(sync_state == THREAD_BLOCKING_OPERATION_NOTHING_HAPPENED) ) {
_Terminate(
INTERNAL_ERROR_CORE,
true,
INTERNAL_ERROR_IMPLEMENTATION_BLOCKING_OPERATION_CANCEL
);
}
#endif
_Thread_blocking_operation_Finalize( the_thread, level );
}

View File

@@ -23,6 +23,95 @@
#include <rtems/score/threadimpl.h>
#include <rtems/score/watchdogimpl.h>
void _Thread_blocking_operation_Finalize(
Thread_Control *the_thread,
ISR_Level level
)
{
/*
* The thread is not waiting on anything after this completes.
*/
the_thread->Wait.queue = NULL;
/*
* If the sync state is timed out, this is very likely not needed.
* But better safe than sorry when it comes to critical sections.
*/
if ( _Watchdog_Is_active( &the_thread->Timer ) ) {
_Watchdog_Deactivate( &the_thread->Timer );
_ISR_Enable( level );
(void) _Watchdog_Remove( &the_thread->Timer );
} else
_ISR_Enable( level );
/*
* Global objects with thread queue's should not be operated on from an
* ISR. But the sync code still must allow short timeouts to be processed
* correctly.
*/
_Thread_Unblock( the_thread );
#if defined(RTEMS_MULTIPROCESSING)
if ( !_Objects_Is_local_id( the_thread->Object.id ) )
_Thread_MP_Free_proxy( the_thread );
#endif
}
/**
* @brief Cancel a blocking operation due to ISR.
*
* This method is used to cancel a blocking operation that was
* satisfied from an ISR while the thread executing was in the
* process of blocking.
*
* This method will restore the previous ISR disable level during the cancel
* operation. Thus it is an implicit _ISR_Enable().
*
* @param[in] sync_state is the synchronization state
* @param[in] the_thread is the thread whose blocking is canceled
* @param[in] level is the previous ISR disable level
*
* @note This is a rare routine in RTEMS. It is called with
* interrupts disabled and only when an ISR completed
* a blocking condition in process.
*/
static void _Thread_blocking_operation_Cancel(
Thread_blocking_operation_States sync_state,
Thread_Control *the_thread,
ISR_Level level
)
{
/*
* Cases that should not happen and why.
*
* THREAD_BLOCKING_OPERATION_SYNCHRONIZED:
*
* This indicates that someone did not enter a blocking
* operation critical section.
*
* THREAD_BLOCKING_OPERATION_NOTHING_HAPPENED:
*
* This indicates that there was nothing to cancel so
* we should not have been called.
*/
#if defined(RTEMS_DEBUG)
if ( (sync_state == THREAD_BLOCKING_OPERATION_SYNCHRONIZED) ||
(sync_state == THREAD_BLOCKING_OPERATION_NOTHING_HAPPENED) ) {
_Terminate(
INTERNAL_ERROR_CORE,
true,
INTERNAL_ERROR_IMPLEMENTATION_BLOCKING_OPERATION_CANCEL
);
}
#else
(void) sync_state;
#endif
_Thread_blocking_operation_Finalize( the_thread, level );
}
void _Thread_queue_Enqueue_with_handler(
Thread_queue_Control *the_thread_queue,
Thread_Control *the_thread,