source: rtems/cpukit/score/src/threadblockingoperationcancel.c @ 8ae37323

4.115
Last change on this file since 8ae37323 was 0ea6d07, checked in by Joel Sherrill <joel.sherrill@…>, on 07/09/14 at 18:22:28

Use Shared Method for Thread Unblock Cleanup

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.

  • Property mode set to 100644
File size: 2.5 KB
Line 
1/**
2 * @file
3 *
4 * @brief Cancel a Blocking Operation
5 * @ingroup ScoreThread
6 */
7
8/*
9 *  COPYRIGHT (c) 1989-2007.
10 *  On-Line Applications Research Corporation (OAR).
11 *
12 *  The license and distribution terms for this file may be
13 *  found in the file LICENSE in this distribution or at
14 *  http://www.rtems.org/license/LICENSE.
15 */
16
17#if HAVE_CONFIG_H
18#include "config.h"
19#endif
20
21#include <rtems/score/threadimpl.h>
22#if defined(RTEMS_DEBUG)
23#include <rtems/score/interr.h>
24#endif
25#include <rtems/score/watchdogimpl.h>
26
27void _Thread_blocking_operation_Finalize(
28  Thread_Control                   *the_thread,
29  ISR_Level                         level
30)
31{
32  /*
33   * The thread is not waiting on anything after this completes.
34   */
35  the_thread->Wait.queue = NULL;
36
37  /*
38   *  If the sync state is timed out, this is very likely not needed.
39   *  But better safe than sorry when it comes to critical sections.
40   */
41  if ( _Watchdog_Is_active( &the_thread->Timer ) ) {
42    _Watchdog_Deactivate( &the_thread->Timer );
43    _ISR_Enable( level );
44    (void) _Watchdog_Remove( &the_thread->Timer );
45  } else
46    _ISR_Enable( level );
47
48  /*
49   *  Global objects with thread queue's should not be operated on from an
50   *  ISR.  But the sync code still must allow short timeouts to be processed
51   *  correctly.
52   */
53
54  _Thread_Unblock( the_thread );
55
56#if defined(RTEMS_MULTIPROCESSING)
57  if ( !_Objects_Is_local_id( the_thread->Object.id ) )
58    _Thread_MP_Free_proxy( the_thread );
59#endif
60}
61
62void _Thread_blocking_operation_Cancel(
63#if defined(RTEMS_DEBUG)
64  Thread_blocking_operation_States  sync_state,
65#else
66  Thread_blocking_operation_States  sync_state __attribute__((unused)),
67#endif
68  Thread_Control                   *the_thread,
69  ISR_Level                         level
70)
71{
72  /*
73   *  Cases that should not happen and why.
74   *
75   *  THREAD_BLOCKING_OPERATION_SYNCHRONIZED:
76   *
77   *  This indicates that someone did not enter a blocking
78   *  operation critical section.
79   *
80   *  THREAD_BLOCKING_OPERATION_NOTHING_HAPPENED:
81   *
82   *  This indicates that there was nothing to cancel so
83   *  we should not have been called.
84   */
85
86  #if defined(RTEMS_DEBUG)
87    if ( (sync_state == THREAD_BLOCKING_OPERATION_SYNCHRONIZED) ||
88         (sync_state == THREAD_BLOCKING_OPERATION_NOTHING_HAPPENED) ) {
89      _Terminate(
90        INTERNAL_ERROR_CORE,
91        true,
92        INTERNAL_ERROR_IMPLEMENTATION_BLOCKING_OPERATION_CANCEL
93      );
94    }
95  #endif
96
97  _Thread_blocking_operation_Finalize( the_thread, level );
98}
Note: See TracBrowser for help on using the repository browser.