OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [rtems/] [c/] [src/] [exec/] [score/] [src/] [threadinitialize.c] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 158 chris
/*
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 208 chris
 *  $Id: threadinitialize.c,v 1.2 2001-09-27 11:59:34 chris Exp $
13 158 chris
 */
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
 
39
boolean _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
  void                *fp_area;
56
  void                *extensions_area;
57
 
58
  /*
59
   *  Initialize the Ada self pointer
60
   */
61
 
62
  the_thread->rtems_ada_self = NULL;
63
 
64
  /*
65
   *  Allocate and Initialize the stack for this thread.
66
   */
67
 
68
 
69
  if ( !stack_area ) {
70
    if ( !_Stack_Is_enough( stack_size ) )
71
      actual_stack_size = STACK_MINIMUM_SIZE;
72
    else
73
      actual_stack_size = stack_size;
74
 
75
    actual_stack_size = _Thread_Stack_Allocate( the_thread, actual_stack_size );
76
 
77
    if ( !actual_stack_size )
78
      return FALSE;                     /* stack allocation failed */
79
 
80
    stack = the_thread->Start.stack;
81
    the_thread->Start.core_allocated_stack = TRUE;
82
  } else {
83
    stack = stack_area;
84
    actual_stack_size = stack_size;
85
    the_thread->Start.core_allocated_stack = FALSE;
86
  }
87
 
88
  _Stack_Initialize(
89
     &the_thread->Start.Initial_stack,
90
     stack,
91
     actual_stack_size
92
  );
93
 
94
  /*
95
   *  Allocate the floating point area for this thread
96
   */
97
 
98
  if ( is_fp ) {
99
 
100
    fp_area = _Workspace_Allocate( CONTEXT_FP_SIZE );
101
    if ( !fp_area ) {
102
      _Thread_Stack_Free( the_thread );
103
      return FALSE;
104
    }
105
    fp_area = _Context_Fp_start( fp_area, 0 );
106
 
107
  } else
108
    fp_area = NULL;
109
 
110
  the_thread->fp_context       = fp_area;
111
  the_thread->Start.fp_context = fp_area;
112
 
113
  /*
114
   *  Allocate the extensions area for this thread
115
   */
116
 
117
  if ( _Thread_Maximum_extensions ) {
118
    extensions_area = _Workspace_Allocate(
119
      (_Thread_Maximum_extensions + 1) * sizeof( void * )
120
    );
121
 
122
    if ( !extensions_area ) {
123
      if ( fp_area )
124
        (void) _Workspace_Free( fp_area );
125
 
126
      _Thread_Stack_Free( the_thread );
127
 
128
      return FALSE;
129
    }
130
  } else
131
    extensions_area = NULL;
132
 
133
  the_thread->extensions = (void **) extensions_area;
134
 
135
  /*
136
   *  General initialization
137
   */
138
 
139
  the_thread->Start.is_preemptible   = is_preemptible;
140
  the_thread->Start.budget_algorithm = budget_algorithm;
141
  the_thread->Start.budget_callout   = budget_callout;
142
 
143
  switch ( budget_algorithm ) {
144
    case THREAD_CPU_BUDGET_ALGORITHM_NONE:
145
    case THREAD_CPU_BUDGET_ALGORITHM_RESET_TIMESLICE:
146
      break;
147
    case THREAD_CPU_BUDGET_ALGORITHM_EXHAUST_TIMESLICE:
148
      the_thread->cpu_time_budget = _Thread_Ticks_per_timeslice;
149
      break;
150
    case THREAD_CPU_BUDGET_ALGORITHM_CALLOUT:
151
      break;
152
  }
153
 
154
  the_thread->Start.isr_level        = isr_level;
155
 
156
  the_thread->current_state          = STATES_DORMANT;
157
  the_thread->resource_count         = 0;
158
  the_thread->suspend_count          = 0;
159
  the_thread->real_priority          = priority;
160
  the_thread->Start.initial_priority = priority;
161
  the_thread->ticks_executed         = 0;
162
 
163
  _Thread_Set_priority( the_thread, priority );
164
 
165
  /*
166
   *  Open the object
167
   */
168
 
169
  _Objects_Open( information, &the_thread->Object, name );
170
 
171
  /*
172
   *  Invoke create extensions
173
   */
174
 
175
  if ( !_User_extensions_Thread_create( the_thread ) ) {
176
 
177
    if ( extensions_area )
178
      (void) _Workspace_Free( extensions_area );
179
 
180
    if ( fp_area )
181
      (void) _Workspace_Free( fp_area );
182
 
183
    _Thread_Stack_Free( the_thread );
184
 
185
    return FALSE;
186
  }
187
 
188
  return TRUE;
189
 
190
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.