source: rtems/cpukit/rtems/src/taskcreate.c @ 3a638ce

4.115
Last change on this file since 3a638ce was 3a638ce, checked in by Joel Sherrill <joel.sherrill@…>, on 01/31/14 at 16:55:17

rtems/*.c: Remove use of register keyword

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