source: rtems/cpukit/score/src/threadinitialize.c @ 5472ad41

4.115
Last change on this file since 5472ad41 was 64adc13, checked in by Joel Sherrill <joel.sherrill@…>, on 07/24/11 at 23:55:15

2011-07-24 Joel Sherrill <joel.sherrill@…>

  • ftpd/ftpd.c, libcsupport/src/geteuid.c, libcsupport/src/getgroups.c, libcsupport/src/getpgrp.c, libcsupport/src/getpid.c, libcsupport/src/getppid.c, libcsupport/src/setpgid.c, libcsupport/src/setsid.c, libcsupport/src/utsname.c, libmisc/stackchk/check.c, posix/include/rtems/posix/mqueue.h, posix/inline/rtems/posix/cond.inl, posix/inline/rtems/posix/mqueue.inl, posix/inline/rtems/posix/mutex.inl, posix/inline/rtems/posix/pthread.inl, posix/inline/rtems/posix/semaphore.inl, posix/inline/rtems/posix/timer.inl, posix/src/alarm.c, posix/src/barrierattrdestroy.c, posix/src/barrierattrgetpshared.c, posix/src/barrierattrinit.c, posix/src/barrierattrsetpshared.c, posix/src/cleanuppop.c, posix/src/cleanuppush.c, posix/src/clockgetcpuclockid.c, posix/src/clockgetenableattr.c, posix/src/clockgetres.c, posix/src/clockgettime.c, posix/src/clocksetenableattr.c, posix/src/clocksettime.c, posix/src/cond.c, posix/src/condattrdestroy.c, posix/src/condattrgetpshared.c, posix/src/condattrinit.c, posix/src/condattrsetpshared.c, posix/src/condbroadcast.c, posix/src/conddefaultattributes.c, posix/src/conddestroy.c, posix/src/condinit.c, posix/src/condsignal.c, posix/src/condsignalsupp.c, posix/src/condtimedwait.c, posix/src/condwait.c, posix/src/condwaitsupp.c, posix/src/keygetspecific.c, posix/src/keyrundestructors.c, posix/src/keysetspecific.c, posix/src/mprotect.c, posix/src/mqueue.c, posix/src/mqueuecreatesupp.c, posix/src/mqueuedeletesupp.c, posix/src/mqueuegetattr.c, posix/src/mqueuenotify.c, posix/src/mqueuereceive.c, posix/src/mqueuesend.c, posix/src/mqueuesendsupp.c, posix/src/mqueuesetattr.c, posix/src/mqueuetimedreceive.c, posix/src/mqueuetimedsend.c, posix/src/mqueuetranslatereturncode.c, posix/src/mqueueunlink.c, posix/src/mutex.c, posix/src/mutexattrdestroy.c, posix/src/mutexattrgetprioceiling.c, posix/src/mutexattrgetprotocol.c, posix/src/mutexattrgetpshared.c, posix/src/mutexattrinit.c, posix/src/mutexattrsetprioceiling.c, posix/src/mutexattrsetprotocol.c, posix/src/mutexattrsetpshared.c, posix/src/mutexdestroy.c, posix/src/mutexgetprioceiling.c, posix/src/mutexinit.c, posix/src/mutexlock.c, posix/src/mutexlocksupp.c, posix/src/mutexsetprioceiling.c, posix/src/mutextimedlock.c, posix/src/mutextrylock.c, posix/src/mutexunlock.c, posix/src/nanosleep.c, posix/src/psignal.c, posix/src/psignalchecksignal.c, posix/src/psignalclearprocesssignals.c, posix/src/psignalclearsignals.c, posix/src/psignalsetprocesssignals.c, posix/src/psignalunblockthread.c, posix/src/pthreadinitthreads.c, posix/src/rwlockattrdestroy.c, posix/src/rwlockattrgetpshared.c, posix/src/rwlockattrinit.c, posix/src/rwlockattrsetpshared.c, posix/src/semaphore.c, posix/src/semaphoredeletesupp.c, posix/src/semaphorenametoid.c, posix/src/semaphorewaitsupp.c, posix/src/semclose.c, posix/src/semdestroy.c, posix/src/semgetvalue.c, posix/src/seminit.c, posix/src/semopen.c, posix/src/sempost.c, posix/src/semtimedwait.c, posix/src/semtrywait.c, posix/src/semunlink.c, posix/src/semwait.c, posix/src/sysconf.c, posix/src/testcancel.c, posix/src/ualarm.c, rtems/src/clockgetuptime.c, rtems/src/clockset.c, rtems/src/clocksetnsecshandler.c, rtems/src/clocktick.c, rtems/src/clocktodtoseconds.c, rtems/src/clocktodvalidate.c, rtems/src/dpmem.c, rtems/src/dpmemcreate.c, rtems/src/dpmemdelete.c, rtems/src/dpmemexternal2internal.c, rtems/src/dpmemident.c, rtems/src/dpmeminternal2external.c, rtems/src/event.c, rtems/src/eventmp.c, rtems/src/eventreceive.c, rtems/src/eventseize.c, rtems/src/eventsend.c, rtems/src/eventsurrender.c, rtems/src/eventtimeout.c, rtems/src/mp.c, rtems/src/msg.c, rtems/src/msgmp.c, rtems/src/msgqallocate.c, rtems/src/msgqbroadcast.c, rtems/src/msgqcreate.c, rtems/src/msgqdelete.c, rtems/src/msgqflush.c, rtems/src/msgqgetnumberpending.c, rtems/src/msgqident.c, rtems/src/msgqreceive.c, rtems/src/msgqtranslatereturncode.c, rtems/src/msgqurgent.c, rtems/src/part.c, rtems/src/partcreate.c, rtems/src/partdelete.c, rtems/src/partgetbuffer.c, rtems/src/partident.c, rtems/src/partmp.c, rtems/src/partreturnbuffer.c, rtems/src/ratemon.c, rtems/src/ratemoncancel.c, rtems/src/ratemoncreate.c, rtems/src/ratemondelete.c, rtems/src/ratemongetstatistics.c, rtems/src/ratemongetstatus.c, rtems/src/ratemonident.c, rtems/src/ratemonperiod.c, rtems/src/ratemonresetstatistics.c, rtems/src/ratemontimeout.c, rtems/src/region.c, rtems/src/regioncreate.c, rtems/src/regiondelete.c, rtems/src/regionextend.c, rtems/src/regiongetfreeinfo.c, rtems/src/regiongetinfo.c, rtems/src/regiongetsegment.c, rtems/src/regiongetsegmentsize.c, rtems/src/regionident.c, rtems/src/regionmp.c, rtems/src/regionprocessqueue.c, rtems/src/regionresizesegment.c, rtems/src/regionreturnsegment.c, rtems/src/rtemsobjectgetclassicname.c, rtems/src/rtemstimer.c, rtems/src/sem.c, rtems/src/semcreate.c, rtems/src/semdelete.c, rtems/src/semflush.c, rtems/src/semident.c, rtems/src/semmp.c, rtems/src/semobtain.c, rtems/src/semrelease.c, rtems/src/semtranslatereturncode.c, rtems/src/signal.c, rtems/src/signalcatch.c, rtems/src/signalmp.c, rtems/src/signalsend.c, rtems/src/taskcreate.c, rtems/src/taskdelete.c, rtems/src/taskgetnote.c, rtems/src/taskident.c, rtems/src/taskinitusers.c, rtems/src/taskissuspended.c, rtems/src/taskmp.c, rtems/src/taskrestart.c, rtems/src/taskresume.c, rtems/src/tasks.c, rtems/src/tasksetnote.c, rtems/src/tasksetpriority.c, rtems/src/taskstart.c, rtems/src/tasksuspend.c, rtems/src/taskwakeafter.c, rtems/src/taskwakewhen.c, rtems/src/timercancel.c, rtems/src/timercreate.c, rtems/src/timerdelete.c, rtems/src/timerfireafter.c, rtems/src/timerfirewhen.c, rtems/src/timergetinfo.c, rtems/src/timerident.c, rtems/src/timerreset.c, rtems/src/timerserverfireafter.c, rtems/src/timerserverfirewhen.c, sapi/src/debug.c, sapi/src/extension.c, sapi/src/posixapi.c, sapi/src/rtemsapi.c, score/src/apiext.c, score/src/chain.c, score/src/corebarrier.c, score/src/corebarrierrelease.c, score/src/corebarrierwait.c, score/src/coremsgbroadcast.c, score/src/coremsgclose.c, score/src/coremsgflush.c, score/src/coremsgflushsupp.c, score/src/coremsgflushwait.c, score/src/coremsginsert.c, score/src/coremsgseize.c, score/src/coremsgsubmit.c, score/src/coremutex.c, score/src/coremutexflush.c, score/src/coremutexseize.c, score/src/corerwlock.c, score/src/corerwlockobtainread.c, score/src/corerwlockobtainwrite.c, score/src/corerwlockrelease.c, score/src/coresem.c, score/src/coresemflush.c, score/src/coresemsurrender.c, score/src/corespinlock.c, score/src/corespinlockrelease.c, score/src/corespinlockwait.c, score/src/coretod.c, score/src/coretodset.c, score/src/coretodtickle.c, score/src/heap.c, score/src/interr.c, score/src/mpci.c, score/src/objectallocate.c, score/src/objectextendinformation.c, score/src/objectfree.c, score/src/objectget.c, score/src/objectgetisr.c, score/src/objectgetnext.c, score/src/objectgetnoprotection.c, score/src/objectinitializeinformation.c, score/src/objectmp.c, score/src/objectnametoid.c, score/src/objectnametoidstring.c, score/src/objectshrinkinformation.c, score/src/rbtree.c, score/src/threaddelayended.c, score/src/threadhandler.c, score/src/threadinitialize.c, score/src/threadloadenv.c, score/src/threadmp.c, score/src/threadq.c, score/src/threadqdequeue.c, score/src/threadqdequeuefifo.c, score/src/threadqdequeuepriority.c, score/src/threadqenqueue.c, score/src/threadqenqueuefifo.c, score/src/threadqenqueuepriority.c, score/src/threadqextract.c, score/src/threadqextractfifo.c, score/src/threadqextractpriority.c, score/src/threadqextractwithproxy.c, score/src/threadqfirst.c, score/src/threadqfirstfifo.c, score/src/threadqfirstpriority.c, score/src/threadqflush.c, score/src/threadqrequeue.c, score/src/threadstackallocate.c, score/src/threadstartmultitasking.c, score/src/watchdog.c, score/src/watchdogadjust.c, score/src/watchdoginsert.c, score/src/watchdogremove.c, score/src/watchdogtickle.c: Remove /*PAGE markers which were interpreted by a long dead print script.
  • Property mode set to 100644
File size: 6.8 KB
Line 
1/*
2 *  Thread Handler / Thread Initialize
3 *
4 *  COPYRIGHT (c) 1989-2011.
5 *  On-Line Applications Research Corporation (OAR).
6 *
7 *  The license and distribution terms for this file may be
8 *  found in the file LICENSE in this distribution or at
9 *  http://www.rtems.com/license/LICENSE.
10 *
11 *  $Id$
12 */
13
14#if HAVE_CONFIG_H
15#include "config.h"
16#endif
17
18#include <rtems/system.h>
19#include <rtems/score/apiext.h>
20#include <rtems/score/context.h>
21#include <rtems/score/interr.h>
22#include <rtems/score/isr.h>
23#include <rtems/score/object.h>
24#include <rtems/score/priority.h>
25#include <rtems/score/scheduler.h>
26#include <rtems/score/states.h>
27#include <rtems/score/sysstate.h>
28#include <rtems/score/thread.h>
29#include <rtems/score/threadq.h>
30#include <rtems/score/userext.h>
31#include <rtems/score/watchdog.h>
32#include <rtems/score/wkspace.h>
33
34/*
35 *  _Thread_Initialize
36 *
37 *  This routine initializes the specified the thread.  It allocates
38 *  all memory associated with this thread.  It completes by adding
39 *  the thread to the local object table so operations on this
40 *  thread id are allowed.
41 */
42
43bool _Thread_Initialize(
44  Objects_Information                  *information,
45  Thread_Control                       *the_thread,
46  void                                 *stack_area,
47  size_t                                stack_size,
48  bool                                  is_fp,
49  Priority_Control                      priority,
50  bool                                  is_preemptible,
51  Thread_CPU_budget_algorithms          budget_algorithm,
52  Thread_CPU_budget_algorithm_callout   budget_callout,
53  uint32_t                              isr_level,
54  Objects_Name                          name
55)
56{
57  size_t               actual_stack_size = 0;
58  void                *stack = NULL;
59  #if ( CPU_HARDWARE_FP == TRUE ) || ( CPU_SOFTWARE_FP == TRUE )
60    void              *fp_area;
61  #endif
62  void                *sched = NULL;
63  void                *extensions_area;
64  bool                 extension_status;
65  int                  i;
66
67  /*
68   *  Initialize the Ada self pointer
69   */
70  #if __RTEMS_ADA__
71    the_thread->rtems_ada_self = NULL;
72  #endif
73
74  /*
75   *  Zero out all the allocated memory fields
76   */
77  for ( i=0 ; i <= THREAD_API_LAST ; i++ )
78    the_thread->API_Extensions[i] = NULL;
79
80  extensions_area = NULL;
81  the_thread->libc_reent = NULL;
82
83  #if ( CPU_HARDWARE_FP == TRUE ) || ( CPU_SOFTWARE_FP == TRUE )
84    fp_area = NULL;
85  #endif
86
87  /*
88   *  Allocate and Initialize the stack for this thread.
89   */
90  #if !defined(RTEMS_SCORE_THREAD_ENABLE_USER_PROVIDED_STACK_VIA_API)
91    actual_stack_size = _Thread_Stack_Allocate( the_thread, stack_size );
92    if ( !actual_stack_size || actual_stack_size < stack_size )
93      return false;                     /* stack allocation failed */
94
95    stack = the_thread->Start.stack;
96  #else
97    if ( !stack_area ) {
98      actual_stack_size = _Thread_Stack_Allocate( the_thread, stack_size );
99      if ( !actual_stack_size || actual_stack_size < stack_size )
100        return false;                     /* stack allocation failed */
101
102      stack = the_thread->Start.stack;
103      the_thread->Start.core_allocated_stack = true;
104    } else {
105      stack = stack_area;
106      actual_stack_size = stack_size;
107      the_thread->Start.core_allocated_stack = false;
108    }
109  #endif
110
111  _Stack_Initialize(
112     &the_thread->Start.Initial_stack,
113     stack,
114     actual_stack_size
115  );
116
117  /*
118   *  Allocate the floating point area for this thread
119   */
120  #if ( CPU_HARDWARE_FP == TRUE ) || ( CPU_SOFTWARE_FP == TRUE )
121    if ( is_fp ) {
122      fp_area = _Workspace_Allocate( CONTEXT_FP_SIZE );
123      if ( !fp_area )
124        goto failed;
125      fp_area = _Context_Fp_start( fp_area, 0 );
126    }
127    the_thread->fp_context       = fp_area;
128    the_thread->Start.fp_context = fp_area;
129  #endif
130
131  /*
132   *  Initialize the thread timer
133   */
134  _Watchdog_Initialize( &the_thread->Timer, NULL, 0, NULL );
135
136  #ifdef __RTEMS_STRICT_ORDER_MUTEX__
137    /* Initialize the head of chain of held mutexes */
138    _Chain_Initialize_empty(&the_thread->lock_mutex);
139  #endif
140
141  /*
142   *  Allocate the extensions area for this thread
143   */
144  if ( _Thread_Maximum_extensions ) {
145    extensions_area = _Workspace_Allocate(
146      (_Thread_Maximum_extensions + 1) * sizeof( void * )
147    );
148    if ( !extensions_area )
149      goto failed;
150  }
151  the_thread->extensions = (void **) extensions_area;
152
153  /*
154   * Clear the extensions area so extension users can determine
155   * if they are linked to the thread. An extension user may
156   * create the extension long after tasks have been created
157   * so they cannot rely on the thread create user extension
158   * call.
159   */
160  if ( the_thread->extensions ) {
161    for ( i = 0; i <= _Thread_Maximum_extensions ; i++ )
162      the_thread->extensions[i] = NULL;
163  }
164
165  /*
166   *  General initialization
167   */
168
169  the_thread->Start.is_preemptible   = is_preemptible;
170  the_thread->Start.budget_algorithm = budget_algorithm;
171  the_thread->Start.budget_callout   = budget_callout;
172
173  switch ( budget_algorithm ) {
174    case THREAD_CPU_BUDGET_ALGORITHM_NONE:
175    case THREAD_CPU_BUDGET_ALGORITHM_RESET_TIMESLICE:
176      break;
177    #if defined(RTEMS_SCORE_THREAD_ENABLE_EXHAUST_TIMESLICE)
178      case THREAD_CPU_BUDGET_ALGORITHM_EXHAUST_TIMESLICE:
179        the_thread->cpu_time_budget = _Thread_Ticks_per_timeslice;
180        break;
181    #endif
182    #if defined(RTEMS_SCORE_THREAD_ENABLE_SCHEDULER_CALLOUT)
183      case THREAD_CPU_BUDGET_ALGORITHM_CALLOUT:
184        break;
185    #endif
186  }
187
188  the_thread->Start.isr_level         = isr_level;
189
190  the_thread->current_state           = STATES_DORMANT;
191  the_thread->Wait.queue              = NULL;
192  the_thread->resource_count          = 0;
193  the_thread->real_priority           = priority;
194  the_thread->Start.initial_priority  = priority;
195  sched =_Scheduler_Allocate( the_thread );
196  if ( !sched )
197    goto failed;
198  _Thread_Set_priority( the_thread, priority );
199
200  /*
201   *  Initialize the CPU usage statistics
202   */
203  #ifndef __RTEMS_USE_TICKS_FOR_STATISTICS__
204    _Timestamp_Set_to_zero( &the_thread->cpu_time_used );
205  #else
206    the_thread->cpu_time_used = 0;
207  #endif
208
209  /*
210   *  Open the object
211   */
212  _Objects_Open( information, &the_thread->Object, name );
213
214  /*
215   *  We assume the Allocator Mutex is locked and dispatching is
216   *  enabled when we get here.  We want to be able to run the
217   *  user extensions with dispatching enabled.  The Allocator
218   *  Mutex provides sufficient protection to let the user extensions
219   *  run safely.
220   */
221  extension_status = _User_extensions_Thread_create( the_thread );
222  if ( extension_status )
223    return true;
224
225failed:
226  _Workspace_Free( the_thread->libc_reent );
227
228  for ( i=0 ; i <= THREAD_API_LAST ; i++ )
229    _Workspace_Free( the_thread->API_Extensions[i] );
230
231  _Workspace_Free( extensions_area );
232
233  #if ( CPU_HARDWARE_FP == TRUE ) || ( CPU_SOFTWARE_FP == TRUE )
234    _Workspace_Free( fp_area );
235  #endif
236
237   _Workspace_Free( sched );
238
239   _Thread_Stack_Free( the_thread );
240  return false;
241}
Note: See TracBrowser for help on using the repository browser.