source: rtems/cpukit/score/src/threadqextractfifo.c @ 25f5730f

4.115
Last change on this file since 25f5730f was 91e7b0c, checked in by Sebastian Huber <sebastian.huber@…>, on 03/27/14 at 08:04:47

score: PR2172: _Thread_queue_Extract()

Add _Thread_queue_Extract_with_return_code(). On SMP this sequence in
_Thread_queue_Process_timeout() was broken:

[...]

/*

  • After we enable interrupts here, a lot may happen in the
  • meantime, e.g. nested interrupts may release the resource that
  • times out here. So we enter _Thread_queue_Extract()
  • speculatively. Inside this function we check the actual status
  • under ISR disable protection. This ensures that exactly one
  • executing context performs the extract operation (other parties
  • may call _Thread_queue_Dequeue()). If this context won, then
  • we have a timeout. *
  • We can use the_thread_queue pointer here even if
  • the_thread->Wait.queue is already set to NULL since the extract
  • operation will only use the thread queue discipline to select
  • the right extract operation. The timeout status is set during
  • thread queue initialization. */

we_did_it = _Thread_queue_Extract( the_thread_queue, the_thread );
if ( we_did_it ) {

the_thread->Wait.return_code = the_thread_queue->timeout_status;

}

[...]

In case _Thread_queue_Extract() successfully extracted a thread, then
this thread may start execution on a remote processor immediately and
read the the_thread->Wait.return_code before we update it here with the
timeout status. Thus it observes a successful operation even if it
timed out.

  • Property mode set to 100644
File size: 1.4 KB
Line 
1/**
2 * @file
3 *
4 * @brief Removes a Thread from a Thread  Queue
5 *
6 * @ingroup ScoreThreadQ
7 */
8
9/*
10 *  COPYRIGHT (c) 1989-2008.
11 *  On-Line Applications Research Corporation (OAR).
12 *
13 *  The license and distribution terms for this file may be
14 *  found in the file LICENSE in this distribution or at
15 *  http://www.rtems.org/license/LICENSE.
16 */
17
18#if HAVE_CONFIG_H
19#include "config.h"
20#endif
21
22#include <rtems/score/threadqimpl.h>
23#include <rtems/score/chainimpl.h>
24#include <rtems/score/isrlevel.h>
25#include <rtems/score/threadimpl.h>
26#include <rtems/score/watchdogimpl.h>
27
28void _Thread_queue_Extract_fifo(
29  Thread_Control       *the_thread,
30  uint32_t              return_code
31)
32{
33  ISR_Level level;
34
35  _ISR_Disable( level );
36
37  if ( !_States_Is_waiting_on_thread_queue( the_thread->current_state ) ) {
38    _ISR_Enable( level );
39    return;
40  }
41
42  _Chain_Extract_unprotected( &the_thread->Object.Node );
43
44  the_thread->Wait.queue = NULL;
45  the_thread->Wait.return_code = return_code;
46
47  if ( !_Watchdog_Is_active( &the_thread->Timer ) ) {
48    _ISR_Enable( level );
49  } else {
50    _Watchdog_Deactivate( &the_thread->Timer );
51    _ISR_Enable( level );
52    (void) _Watchdog_Remove( &the_thread->Timer );
53  }
54
55  _Thread_Unblock( the_thread );
56
57#if defined(RTEMS_MULTIPROCESSING)
58  if ( !_Objects_Is_local_id( the_thread->Object.id ) )
59    _Thread_MP_Free_proxy( the_thread );
60#endif
61}
Note: See TracBrowser for help on using the repository browser.