source: rtems/cpukit/rtems/src/taskcreate.c @ 63d229d6

4.115
Last change on this file since 63d229d6 was 63d229d6, checked in by Sebastian Huber <sebastian.huber@…>, on 07/23/13 at 09:12:52

rtems: Create attr implementation header

Move implementation specific parts of attr.h and attr.inl into new
header file attrimpl.h. The attr.h contains now only the application
visible API.

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