source: rtems/cpukit/rtems/src/taskcreate.c @ 811804fe

4.104.114.84.95
Last change on this file since 811804fe was c4d69e2, checked in by Joel Sherrill <joel.sherrill@…>, on 05/17/99 at 21:02:16

Split Task Manager into multiple files. Eventually this effort will
reduce the size of executables.

  • Property mode set to 100644
File size: 5.7 KB
Line 
1/*
2 *  RTEMS Task Manager
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 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/rtems/status.h>
18#include <rtems/rtems/support.h>
19#include <rtems/rtems/modes.h>
20#include <rtems/score/object.h>
21#include <rtems/score/stack.h>
22#include <rtems/score/states.h>
23#include <rtems/rtems/tasks.h>
24#include <rtems/score/thread.h>
25#include <rtems/score/threadq.h>
26#include <rtems/score/tod.h>
27#include <rtems/score/userext.h>
28#include <rtems/score/wkspace.h>
29#include <rtems/score/apiext.h>
30#include <rtems/score/sysstate.h>
31
32/*PAGE
33 *
34 *  rtems_task_create
35 *
36 *  This directive creates a thread by allocating and initializing a
37 *  thread control block and a stack.  The newly created thread is
38 *  placed in the dormant state.
39 *
40 *  Input parameters:
41 *    name             - user defined thread name
42 *    initial_priority - thread priority
43 *    stack_size       - stack size in bytes
44 *    initial_modes    - initial thread mode
45 *    attribute_set    - thread attributes
46 *    id               - pointer to thread id
47 *
48 *  Output parameters:
49 *    id                - thread id
50 *    RTEMS_SUCCESSFUL - if successful
51 *    error code        - if unsuccessful
52 */
53
54rtems_status_code rtems_task_create(
55  rtems_name           name,
56  rtems_task_priority  initial_priority,
57  unsigned32           stack_size,
58  rtems_mode           initial_modes,
59  rtems_attribute      attribute_set,
60  Objects_Id          *id
61)
62{
63  register Thread_Control *the_thread;
64  boolean                  is_fp;
65#if defined(RTEMS_MULTIPROCESSING)
66  Objects_MP_Control      *the_global_object = NULL;
67  boolean                  is_global;
68#endif
69  boolean                  status;
70  rtems_attribute          the_attribute_set;
71  Priority_Control         core_priority;
72  RTEMS_API_Control       *api;
73  ASR_Information         *asr;
74 
75
76  if ( !rtems_is_name_valid( name ) )
77    return RTEMS_INVALID_NAME;
78
79  /*
80   *  Core Thread Initialize insures we get the minimum amount of
81   *  stack space.
82   */
83
84#if 0
85  if ( !_Stack_Is_enough( stack_size ) )
86    return RTEMS_INVALID_SIZE;
87#endif
88
89  /*
90   *  Fix the attribute set to match the attributes which
91   *  this processor (1) requires and (2) is able to support.
92   *  First add in the required flags for attribute_set
93   *  Typically this might include FP if the platform
94   *  or application required all tasks to be fp aware.
95   *  Then turn off the requested bits which are not supported.
96   */
97
98  the_attribute_set = _Attributes_Set( attribute_set, ATTRIBUTES_REQUIRED );
99  the_attribute_set =
100    _Attributes_Clear( the_attribute_set, ATTRIBUTES_NOT_SUPPORTED );
101
102  if ( _Attributes_Is_floating_point( the_attribute_set ) )
103    is_fp = TRUE;
104  else
105    is_fp = FALSE;
106
107  /*
108   *  Validate the RTEMS API priority and convert it to the core priority range.
109   */
110
111  if ( !_Attributes_Is_system_task( the_attribute_set ) ) {
112    if ( !_RTEMS_tasks_Priority_is_valid( initial_priority ) )
113      return RTEMS_INVALID_PRIORITY;
114  }
115
116  core_priority = _RTEMS_tasks_Priority_to_Core( initial_priority );
117
118#if defined(RTEMS_MULTIPROCESSING)
119  if ( _Attributes_Is_global( the_attribute_set ) ) {
120
121    is_global = TRUE;
122
123    if ( !_System_state_Is_multiprocessing )
124      return RTEMS_MP_NOT_CONFIGURED;
125
126  } else
127    is_global = FALSE;
128#endif
129
130  /*
131   *  Make sure system is MP if this task is global
132   */
133
134  /*
135   *  Disable dispatch for protection
136   */
137
138  _Thread_Disable_dispatch();
139
140  /*
141   *  Allocate the thread control block and -- if the task is global --
142   *  allocate a global object control block.
143   *
144   *  NOTE:  This routine does not use the combined allocate and open
145   *         global object routine because this results in a lack of
146   *         control over when memory is allocated and can be freed in
147   *         the event of an error.
148   */
149
150  the_thread = _RTEMS_tasks_Allocate();
151
152  if ( !the_thread ) {
153    _Thread_Enable_dispatch();
154    return RTEMS_TOO_MANY;
155  }
156
157#if defined(RTEMS_MULTIPROCESSING)
158  if ( is_global ) {
159    the_global_object = _Objects_MP_Allocate_global_object();
160
161    if ( _Objects_MP_Is_null_global_object( the_global_object ) ) {
162      _RTEMS_tasks_Free( the_thread );
163      _Thread_Enable_dispatch();
164      return RTEMS_TOO_MANY;
165    }
166  }
167#endif
168
169  /*
170   *  Initialize the core thread for this task.
171   */
172
173  status = _Thread_Initialize(
174    &_RTEMS_tasks_Information,
175    the_thread,
176    NULL,
177    stack_size,
178    is_fp,
179    core_priority,
180    _Modes_Is_preempt(initial_modes)   ? TRUE : FALSE,
181    _Modes_Is_timeslice(initial_modes) ?
182      THREAD_CPU_BUDGET_ALGORITHM_RESET_TIMESLICE :
183      THREAD_CPU_BUDGET_ALGORITHM_NONE,
184    NULL,        /* no budget algorithm callout */
185    _Modes_Get_interrupt_level(initial_modes),
186    &name
187  );
188
189  if ( !status ) {
190#if defined(RTEMS_MULTIPROCESSING)
191    if ( is_global )
192      _Objects_MP_Free_global_object( the_global_object );
193#endif
194    _RTEMS_tasks_Free( the_thread );
195    _Thread_Enable_dispatch();
196    return RTEMS_UNSATISFIED;
197  }
198
199  api = the_thread->API_Extensions[ THREAD_API_RTEMS ];
200  asr = &api->Signal;
201 
202  asr->is_enabled = _Modes_Is_asr_disabled(initial_modes) ? FALSE : TRUE;
203
204  *id = the_thread->Object.id;
205
206#if defined(RTEMS_MULTIPROCESSING)
207  if ( is_global ) {
208
209    the_thread->is_global = TRUE;
210
211    _Objects_MP_Open(
212      &_RTEMS_tasks_Information,
213      the_global_object,
214      name,
215      the_thread->Object.id
216    );
217
218    _RTEMS_tasks_MP_Send_process_packet(
219      RTEMS_TASKS_MP_ANNOUNCE_CREATE,
220      the_thread->Object.id,
221      name
222    );
223
224   }
225#endif
226
227  _Thread_Enable_dispatch();
228  return RTEMS_SUCCESSFUL;
229}
Note: See TracBrowser for help on using the repository browser.