source: rtems/c/src/exec/score/src/threadinitialize.c @ eb02f47

4.104.114.84.95
Last change on this file since eb02f47 was eb02f47, checked in by Joel Sherrill <joel.sherrill@…>, on 11/10/99 at 13:48:27

Committed modifications from ITRON Task and Task Dependendent Synchronization
Working Group. Included are tests.

  • Property mode set to 100644
File size: 4.5 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 *  XXX
35 */
36
37boolean _Thread_Initialize(
38  Objects_Information                  *information,
39  Thread_Control                       *the_thread,
40  void                                 *stack_area,
41  unsigned32                            stack_size,
42  boolean                               is_fp,
43  Priority_Control                      priority,
44  boolean                               is_preemptible,
45  Thread_CPU_budget_algorithms          budget_algorithm,
46  Thread_CPU_budget_algorithm_callout   budget_callout,
47  unsigned32                            isr_level,
48  Objects_Name                          name
49)
50{
51  unsigned32           actual_stack_size = 0;
52  void                *stack = NULL;
53  void                *fp_area;
54  void                *extensions_area;
55
56  /*
57   *  Initialize the Ada self pointer
58   */
59
60  the_thread->rtems_ada_self = NULL;
61
62  /*
63   *  Allocate and Initialize the stack for this thread.
64   */
65
66
67  if ( !stack_area ) {
68    if ( !_Stack_Is_enough( stack_size ) )
69      actual_stack_size = STACK_MINIMUM_SIZE;
70    else
71      actual_stack_size = stack_size;
72
73    actual_stack_size = _Thread_Stack_Allocate( the_thread, actual_stack_size );
74 
75    if ( !actual_stack_size )
76      return FALSE;                     /* stack allocation failed */
77
78    stack = the_thread->Start.stack;
79    the_thread->Start.core_allocated_stack = TRUE;
80  } else {
81    stack = stack_area;
82    actual_stack_size = stack_size;
83    the_thread->Start.core_allocated_stack = FALSE;
84  }
85
86  _Stack_Initialize(
87     &the_thread->Start.Initial_stack,
88     stack,
89     actual_stack_size
90  );
91
92  /*
93   *  Allocate the floating point area for this thread
94   */
95 
96  if ( is_fp ) {
97
98    fp_area = _Workspace_Allocate( CONTEXT_FP_SIZE );
99    if ( !fp_area ) {
100      _Thread_Stack_Free( the_thread );
101      return FALSE;
102    }
103    fp_area = _Context_Fp_start( fp_area, 0 );
104
105  } else
106    fp_area = NULL;
107
108  the_thread->fp_context       = fp_area;
109  the_thread->Start.fp_context = fp_area;
110
111  /*
112   *  Allocate the extensions area for this thread
113   */
114
115  if ( _Thread_Maximum_extensions ) {
116    extensions_area = _Workspace_Allocate(
117      (_Thread_Maximum_extensions + 1) * sizeof( void * )
118    );
119
120    if ( !extensions_area ) {
121      if ( fp_area )
122        (void) _Workspace_Free( fp_area );
123
124      _Thread_Stack_Free( the_thread );
125
126      return FALSE;
127    }
128  } else
129    extensions_area = NULL;
130 
131  the_thread->extensions = (void **) extensions_area;
132
133  /*
134   *  General initialization
135   */
136
137  the_thread->Start.is_preemptible   = is_preemptible;
138  the_thread->Start.budget_algorithm = budget_algorithm;
139  the_thread->Start.budget_callout   = budget_callout;
140
141  switch ( budget_algorithm ) {
142    case THREAD_CPU_BUDGET_ALGORITHM_NONE:
143    case THREAD_CPU_BUDGET_ALGORITHM_RESET_TIMESLICE:
144      break;
145    case THREAD_CPU_BUDGET_ALGORITHM_EXHAUST_TIMESLICE:
146      the_thread->cpu_time_budget = _Thread_Ticks_per_timeslice;
147      break;
148    case THREAD_CPU_BUDGET_ALGORITHM_CALLOUT:
149      break;
150  }
151
152  the_thread->Start.isr_level        = isr_level;
153
154  the_thread->current_state          = STATES_DORMANT;
155  the_thread->resource_count         = 0;
156  the_thread->suspend_count          = 0;
157  the_thread->real_priority          = priority;
158  the_thread->Start.initial_priority = priority;
159  the_thread->ticks_executed         = 0;
160 
161  _Thread_Set_priority( the_thread, priority );
162
163  /*
164   *  Open the object
165   */
166
167  _Objects_Open( information, &the_thread->Object, name );
168
169  /*
170   *  Invoke create extensions
171   */
172
173  if ( !_User_extensions_Thread_create( the_thread ) ) {
174
175    if ( extensions_area )
176      (void) _Workspace_Free( extensions_area );
177
178    if ( fp_area )
179      (void) _Workspace_Free( fp_area );
180
181    _Thread_Stack_Free( the_thread );
182
183    return FALSE;
184  }
185
186  return TRUE;
187   
188}
Note: See TracBrowser for help on using the repository browser.