source: rtems/cpukit/score/src/threadinitialize.c @ 96d0b64

4.104.114.84.95
Last change on this file since 96d0b64 was 96d0b64, checked in by Joel Sherrill <joel.sherrill@…>, on 03/05/07 at 21:01:40

2007-03-05 Joel Sherrill <joel@…>

PR 1222/cpukit

  • score/Makefile.am, score/include/rtems/score/coremutex.h, score/include/rtems/score/threadq.h, score/inline/rtems/score/coremutex.inl, score/src/coremsgsubmit.c, score/src/coremutexsurrender.c, score/src/threadchangepriority.c, score/src/threadclearstate.c, score/src/threadhandler.c, score/src/threadinitialize.c, score/src/threadqdequeuefifo.c, score/src/threadqdequeuepriority.c, score/src/threadqenqueue.c, score/src/threadqenqueuefifo.c, score/src/threadqenqueuepriority.c, score/src/threadqextractfifo.c, score/src/threadqextractpriority.c, score/src/threadsetstate.c: Enhance so that when the prioirity of a thread that is blocked on a priority based thread queue is changed, that its placement in the queue is reevaluated based upon the new priority. This enhancement includes modifications to the SuperCore? as well as new test cases.
  • score/src/threadqrequeue.c: New file.
  • Property mode set to 100644
File size: 5.7 KB
Line 
1/*
2 *  Thread Handler
3 *
4 *
5 *  COPYRIGHT (c) 1989-2006.
6 *  On-Line Applications Research Corporation (OAR).
7 *
8 *  The license and distribution terms for this file may be
9 *  found in found in the file LICENSE in this distribution or at
10 *  http://www.rtems.com/license/LICENSE.
11 *
12 *  $Id$
13 */
14
15#if HAVE_CONFIG_H
16#include "config.h"
17#endif
18
19#include <rtems/system.h>
20#include <rtems/score/apiext.h>
21#include <rtems/score/context.h>
22#include <rtems/score/interr.h>
23#include <rtems/score/isr.h>
24#include <rtems/score/object.h>
25#include <rtems/score/priority.h>
26#include <rtems/score/states.h>
27#include <rtems/score/sysstate.h>
28#include <rtems/score/thread.h>
29#include <rtems/score/threadq.h>
30#include <rtems/score/userext.h>
31#include <rtems/score/watchdog.h>
32#include <rtems/score/wkspace.h>
33
34/*PAGE
35 *
36 *  _Thread_Initialize
37 *
38 *  This routine initializes the specified the thread.  It allocates
39 *  all memory associated with this thread.  It completes by adding
40 *  the thread to the local object table so operations on this
41 *  thread id are allowed.
42 */
43
44boolean _Thread_Initialize(
45  Objects_Information                  *information,
46  Thread_Control                       *the_thread,
47  void                                 *stack_area,
48  uint32_t                              stack_size,
49  boolean                               is_fp,
50  Priority_Control                      priority,
51  boolean                               is_preemptible,
52  Thread_CPU_budget_algorithms          budget_algorithm,
53  Thread_CPU_budget_algorithm_callout   budget_callout,
54  uint32_t                              isr_level,
55  Objects_Name                          name
56)
57{
58  uint32_t             actual_stack_size = 0;
59  void                *stack = NULL;
60#if ( CPU_HARDWARE_FP == TRUE ) || ( CPU_SOFTWARE_FP == TRUE )
61  void                *fp_area;
62#endif
63  void                *extensions_area;
64
65  /*
66   *  Initialize the Ada self pointer
67   */
68
69  the_thread->rtems_ada_self = NULL;
70
71  /*
72   *  Allocate and Initialize the stack for this thread.
73   */
74
75
76  if ( !stack_area ) {
77    if ( !_Stack_Is_enough( stack_size ) )
78      actual_stack_size = STACK_MINIMUM_SIZE;
79    else
80      actual_stack_size = stack_size;
81
82    actual_stack_size = _Thread_Stack_Allocate( the_thread, actual_stack_size );
83
84    if ( !actual_stack_size || actual_stack_size < stack_size )
85      return FALSE;                     /* stack allocation failed */
86
87    stack = the_thread->Start.stack;
88    the_thread->Start.core_allocated_stack = TRUE;
89  } else {
90    stack = stack_area;
91    actual_stack_size = stack_size;
92    the_thread->Start.core_allocated_stack = FALSE;
93  }
94
95  _Stack_Initialize(
96     &the_thread->Start.Initial_stack,
97     stack,
98     actual_stack_size
99  );
100
101  /*
102   *  Allocate the floating point area for this thread
103   */
104
105#if ( CPU_HARDWARE_FP == TRUE ) || ( CPU_SOFTWARE_FP == TRUE )
106  if ( is_fp ) {
107
108    fp_area = _Workspace_Allocate( CONTEXT_FP_SIZE );
109    if ( !fp_area ) {
110      _Thread_Stack_Free( the_thread );
111      return FALSE;
112    }
113    fp_area = _Context_Fp_start( fp_area, 0 );
114
115  } else
116    fp_area = NULL;
117
118  the_thread->fp_context       = fp_area;
119  the_thread->Start.fp_context = fp_area;
120#endif
121
122  /*
123   *  Initialize the thread timer
124   */
125  _Watchdog_Initialize( &the_thread->Timer, NULL, 0, NULL );
126
127  /*
128   * Clear the libc reent hook.
129   */
130
131  the_thread->libc_reent = NULL;
132
133  /*
134   *  Allocate the extensions area for this thread
135   */
136
137  if ( _Thread_Maximum_extensions ) {
138    extensions_area = _Workspace_Allocate(
139      (_Thread_Maximum_extensions + 1) * sizeof( void * )
140    );
141
142    if ( !extensions_area ) {
143#if ( CPU_HARDWARE_FP == TRUE ) || ( CPU_SOFTWARE_FP == TRUE )
144      if ( fp_area )
145        (void) _Workspace_Free( fp_area );
146#endif
147
148      _Thread_Stack_Free( the_thread );
149
150      return FALSE;
151    }
152  } else
153    extensions_area = NULL;
154
155  the_thread->extensions = (void **) extensions_area;
156
157  /*
158   * Clear the extensions area so extension users can determine
159   * if they are linked to the thread. An extension user may
160   * create the extension long after tasks have been created
161   * so they cannot rely on the thread create user extension
162   * call.
163   */
164
165  if ( the_thread->extensions ) {
166    int i;
167    for ( i = 0; i < (_Thread_Maximum_extensions + 1); i++ )
168      the_thread->extensions[i] = NULL;
169  }
170
171  /*
172   *  General initialization
173   */
174
175  the_thread->Start.is_preemptible   = is_preemptible;
176  the_thread->Start.budget_algorithm = budget_algorithm;
177  the_thread->Start.budget_callout   = budget_callout;
178
179  switch ( budget_algorithm ) {
180    case THREAD_CPU_BUDGET_ALGORITHM_NONE:
181    case THREAD_CPU_BUDGET_ALGORITHM_RESET_TIMESLICE:
182      break;
183    case THREAD_CPU_BUDGET_ALGORITHM_EXHAUST_TIMESLICE:
184      the_thread->cpu_time_budget = _Thread_Ticks_per_timeslice;
185      break;
186    case THREAD_CPU_BUDGET_ALGORITHM_CALLOUT:
187      break;
188  }
189
190  the_thread->Start.isr_level        = isr_level;
191
192  the_thread->current_state          = STATES_DORMANT;
193  the_thread->Wait.queue             = NULL;
194  the_thread->resource_count         = 0;
195  the_thread->suspend_count          = 0;
196  the_thread->real_priority          = priority;
197  the_thread->Start.initial_priority = priority;
198  the_thread->ticks_executed         = 0;
199
200  _Thread_Set_priority( the_thread, priority );
201
202  /*
203   *  Open the object
204   */
205
206  _Objects_Open( information, &the_thread->Object, name );
207
208  /*
209   *  Invoke create extensions
210   */
211
212  if ( !_User_extensions_Thread_create( the_thread ) ) {
213
214    if ( extensions_area )
215      (void) _Workspace_Free( extensions_area );
216
217#if ( CPU_HARDWARE_FP == TRUE ) || ( CPU_SOFTWARE_FP == TRUE )
218    if ( fp_area )
219      (void) _Workspace_Free( fp_area );
220#endif
221
222    _Thread_Stack_Free( the_thread );
223
224    return FALSE;
225  }
226
227  return TRUE;
228
229}
Note: See TracBrowser for help on using the repository browser.