forked from Imagelibrary/rtems
When a thread is removed from a thread queue or is unblocked by receiving an event, the same actions are required. + timeout watchdog canceled, + thread must be unblocked, and + (MP only) proxy cleaned up This patch makes sure there is only one copy of this code.
99 lines
2.5 KiB
C
99 lines
2.5 KiB
C
/**
|
|
* @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 );
|
|
}
|