source: rtems/cpukit/score/src/threadinitialize.c @ 0cb7cb9

4.104.114.84.95
Last change on this file since 0cb7cb9 was 0cb7cb9, checked in by Joel Sherrill <joel.sherrill@…>, on 11/16/99 at 16:10:39

Added comments.

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