source: rtems/cpukit/rtems/src/taskcreate.c @ 9b4422a2

4.115
Last change on this file since 9b4422a2 was 9b4422a2, checked in by Joel Sherrill <joel.sherrill@…>, on 05/03/12 at 15:09:24

Remove All CVS Id Strings Possible Using a Script

Script does what is expected and tries to do it as
smartly as possible.

+ remove occurrences of two blank comment lines

next to each other after Id string line removed.

+ remove entire comment blocks which only exited to

contain CVS Ids

+ If the processing left a blank line at the top of

a file, it was removed.

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