source: rtems/cpukit/score/src/threadinitialize.c @ 81f6e8cc

4.104.114.84.9
Last change on this file since 81f6e8cc was 81f6e8cc, checked in by Joel Sherrill <joel.sherrill@…>, on Jan 8, 2001 at 7:16:26 PM

2001-01-08 Joel Sherrill <joel@…>

  • src/threadinitialize.c: Fix my bad hack of Ralf's fp_area warning removal patch. :(
  • Property mode set to 100644
File size: 4.9 KB
Line 
1/*
2 *  Thread Handler
3 *
4 *
5 *  COPYRIGHT (c) 1989-1999.
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.OARcorp.com/rtems/license.html.
11 *
12 *  $Id$
13 */
14
15#include <rtems/system.h>
16#include <rtems/score/apiext.h>
17#include <rtems/score/context.h>
18#include <rtems/score/interr.h>
19#include <rtems/score/isr.h>
20#include <rtems/score/object.h>
21#include <rtems/score/priority.h>
22#include <rtems/score/states.h>
23#include <rtems/score/sysstate.h>
24#include <rtems/score/thread.h>
25#include <rtems/score/threadq.h>
26#include <rtems/score/userext.h>
27#include <rtems/score/wkspace.h>
28
29/*PAGE
30 *
31 *  _Thread_Initialize
32 *
33 *  This routine initializes the specified the thread.  It allocates
34 *  all memory associated with this thread.  It completes by adding
35 *  the thread to the local object table so operations on this
36 *  thread id are allowed.
37 */
38
39boolean _Thread_Initialize(
40  Objects_Information                  *information,
41  Thread_Control                       *the_thread,
42  void                                 *stack_area,
43  unsigned32                            stack_size,
44  boolean                               is_fp,
45  Priority_Control                      priority,
46  boolean                               is_preemptible,
47  Thread_CPU_budget_algorithms          budget_algorithm,
48  Thread_CPU_budget_algorithm_callout   budget_callout,
49  unsigned32                            isr_level,
50  Objects_Name                          name
51)
52{
53  unsigned32           actual_stack_size = 0;
54  void                *stack = NULL;
55#if ( CPU_HARDWARE_FP == TRUE ) || ( CPU_SOFTWARE_FP == TRUE )
56  void                *fp_area;
57#endif
58  void                *extensions_area;
59
60  /*
61   *  Initialize the Ada self pointer
62   */
63
64  the_thread->rtems_ada_self = NULL;
65
66  /*
67   *  Allocate and Initialize the stack for this thread.
68   */
69
70
71  if ( !stack_area ) {
72    if ( !_Stack_Is_enough( stack_size ) )
73      actual_stack_size = STACK_MINIMUM_SIZE;
74    else
75      actual_stack_size = stack_size;
76
77    actual_stack_size = _Thread_Stack_Allocate( the_thread, actual_stack_size );
78 
79    if ( !actual_stack_size ) 
80      return FALSE;                     /* stack allocation failed */
81
82    stack = the_thread->Start.stack;
83    the_thread->Start.core_allocated_stack = TRUE;
84  } else {
85    stack = stack_area;
86    actual_stack_size = stack_size;
87    the_thread->Start.core_allocated_stack = FALSE;
88  }
89
90  _Stack_Initialize(
91     &the_thread->Start.Initial_stack,
92     stack,
93     actual_stack_size
94  );
95
96  /*
97   *  Allocate the floating point area for this thread
98   */
99 
100#if ( CPU_HARDWARE_FP == TRUE ) || ( CPU_SOFTWARE_FP == TRUE )
101  if ( is_fp ) {
102
103    fp_area = _Workspace_Allocate( CONTEXT_FP_SIZE );
104    if ( !fp_area ) {
105      _Thread_Stack_Free( the_thread );
106      return FALSE;
107    }
108    fp_area = _Context_Fp_start( fp_area, 0 );
109
110  } else
111    fp_area = NULL;
112
113  the_thread->fp_context       = fp_area;
114  the_thread->Start.fp_context = fp_area;
115#endif
116
117  /*
118   *  Allocate the extensions area for this thread
119   */
120
121  if ( _Thread_Maximum_extensions ) {
122    extensions_area = _Workspace_Allocate(
123      (_Thread_Maximum_extensions + 1) * sizeof( void * )
124    );
125
126    if ( !extensions_area ) {
127#if ( CPU_HARDWARE_FP == TRUE ) || ( CPU_SOFTWARE_FP == TRUE )
128      if ( fp_area )
129        (void) _Workspace_Free( fp_area );
130#endif
131
132      _Thread_Stack_Free( the_thread );
133
134      return FALSE;
135    }
136  } else 
137    extensions_area = NULL;
138 
139  the_thread->extensions = (void **) extensions_area;
140
141  /*
142   *  General initialization
143   */
144
145  the_thread->Start.is_preemptible   = is_preemptible;
146  the_thread->Start.budget_algorithm = budget_algorithm;
147  the_thread->Start.budget_callout   = budget_callout;
148
149  switch ( budget_algorithm ) {
150    case THREAD_CPU_BUDGET_ALGORITHM_NONE:
151    case THREAD_CPU_BUDGET_ALGORITHM_RESET_TIMESLICE:
152      break;
153    case THREAD_CPU_BUDGET_ALGORITHM_EXHAUST_TIMESLICE:
154      the_thread->cpu_time_budget = _Thread_Ticks_per_timeslice;
155      break;
156    case THREAD_CPU_BUDGET_ALGORITHM_CALLOUT:
157      break;
158  }
159
160  the_thread->Start.isr_level        = isr_level;
161
162  the_thread->current_state          = STATES_DORMANT;
163  the_thread->resource_count         = 0;
164  the_thread->suspend_count          = 0;
165  the_thread->real_priority          = priority;
166  the_thread->Start.initial_priority = priority;
167  the_thread->ticks_executed         = 0;
168 
169  _Thread_Set_priority( the_thread, priority );
170
171  /*
172   *  Open the object
173   */
174
175  _Objects_Open( information, &the_thread->Object, name );
176
177  /*
178   *  Invoke create extensions
179   */
180
181  if ( !_User_extensions_Thread_create( the_thread ) ) {
182
183    if ( extensions_area )
184      (void) _Workspace_Free( extensions_area );
185
186#if ( CPU_HARDWARE_FP == TRUE ) || ( CPU_SOFTWARE_FP == TRUE )
187    if ( fp_area )
188      (void) _Workspace_Free( fp_area );
189#endif
190
191    _Thread_Stack_Free( the_thread );
192
193    return FALSE;
194  }
195
196  return TRUE;
197   
198}
Note: See TracBrowser for help on using the repository browser.