source: rtems/cpukit/score/src/threadstartmultitasking.c @ 7ee4e72

4.115
Last change on this file since 7ee4e72 was 7ee4e72, checked in by Sebastian Huber <sebastian.huber@…>, on 02/20/14 at 16:05:44

score: _Thread_Start_multitasking()

Fix serious race-condition. Read the heir after the per-CPU lock
acquire.

  • Property mode set to 100644
File size: 1.9 KB
Line 
1/**
2 *  @file
3 *
4 *  @brief Start Thread Multitasking
5 *  @ingroup ScoreThread
6 */
7
8/*
9 *  COPYRIGHT (c) 1989-2006.
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.com/license/LICENSE.
15 */
16
17#if HAVE_CONFIG_H
18#include "config.h"
19#endif
20
21#include <rtems/score/threadimpl.h>
22
23void _Thread_Start_multitasking( void )
24{
25  Per_CPU_Control *self_cpu = _Per_CPU_Get();
26  Thread_Control  *heir;
27
28#if defined(RTEMS_SMP)
29  _Per_CPU_Change_state( self_cpu, PER_CPU_STATE_UP );
30
31  /*
32   * Threads begin execution in the _Thread_Handler() function.   This
33   * function will set the thread dispatch disable level to zero and calls
34   * _Per_CPU_Release().
35   */
36  _Per_CPU_Acquire( self_cpu );
37  self_cpu->thread_dispatch_disable_level = 1;
38#endif
39
40  heir = self_cpu->heir;
41
42#if defined(RTEMS_SMP)
43  self_cpu->executing->is_executing = false;
44  heir->is_executing = true;
45#endif
46
47  self_cpu->dispatch_necessary = false;
48  self_cpu->executing = heir;
49
50   /*
51    * Get the init task(s) running.
52    *
53    * Note: Thread_Dispatch() is normally used to dispatch threads.  As
54    *       part of its work, Thread_Dispatch() restores floating point
55    *       state for the heir task.
56    *
57    *       This code avoids Thread_Dispatch(), and so we have to restore
58    *       (actually initialize) the floating point state "by hand".
59    *
60    *       Ignore the CPU_USE_DEFERRED_FP_SWITCH because we must always
61    *       switch in the first thread if it is FP.
62    */
63#if ( CPU_HARDWARE_FP == TRUE ) || ( CPU_SOFTWARE_FP == TRUE )
64   /*
65    *  don't need to worry about saving BSP's floating point state
66    */
67
68   if ( heir->fp_context != NULL )
69     _Context_Restore_fp( &heir->fp_context );
70#endif
71
72#if defined(_CPU_Start_multitasking)
73    _CPU_Start_multitasking( &heir->Registers );
74#else
75    _CPU_Context_Restart_self( &heir->Registers );
76#endif
77}
Note: See TracBrowser for help on using the repository browser.