source: rtems/c/src/exec/score/src/threadstackallocate.c @ dfbfa2b0

4.104.114.84.95
Last change on this file since dfbfa2b0 was 05df0a8, checked in by Joel Sherrill <joel.sherrill@…>, on 05/17/99 at 20:41:13

Thread Handler split into multiple files. Eventually, as RTEMS is
split into one function per file, this will decrease the size of executables.

  • Property mode set to 100644
File size: 2.2 KB
Line 
1/*
2 *  Thread Handler
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 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/score/apiext.h>
18#include <rtems/score/context.h>
19#include <rtems/score/interr.h>
20#include <rtems/score/isr.h>
21#include <rtems/score/object.h>
22#include <rtems/score/priority.h>
23#include <rtems/score/states.h>
24#include <rtems/score/sysstate.h>
25#include <rtems/score/thread.h>
26#include <rtems/score/threadq.h>
27#include <rtems/score/userext.h>
28#include <rtems/score/wkspace.h>
29
30/*PAGE
31 *
32 *  _Thread_Stack_Allocate
33 *
34 *  Allocate the requested stack space for the thread.
35 *  return the actual size allocated after any adjustment
36 *  or return zero if the allocation failed.
37 *  Set the Start.stack field to the address of the stack
38 */
39
40unsigned32 _Thread_Stack_Allocate(
41  Thread_Control *the_thread,
42  unsigned32 stack_size
43)
44{
45  void *stack_addr = 0;
46 
47  if ( !_Stack_Is_enough( stack_size ) )
48    stack_size = STACK_MINIMUM_SIZE;
49 
50  /*
51   * Call ONLY the CPU table stack allocate hook, _or_ the
52   * the RTEMS workspace allocate.  This is so the stack free
53   * routine can call the correct deallocation routine.
54   */
55
56  if ( _CPU_Table.stack_allocate_hook )
57  {
58    stack_addr = (*_CPU_Table.stack_allocate_hook)( stack_size );
59  } else {
60
61    /*
62     *  First pad the requested size so we allocate enough memory
63     *  so the context initialization can align it properly.  The address
64     *  returned the workspace allocate must be directly stored in the
65     *  stack control block because it is later used in the free sequence.
66     *
67     *  Thus it is the responsibility of the CPU dependent code to
68     *  get and keep the stack adjust factor, the stack alignment, and
69     *  the context initialization sequence in sync.
70     */
71
72    stack_size = _Stack_Adjust_size( stack_size );
73    stack_addr = _Workspace_Allocate( stack_size );
74  }
75 
76  if ( !stack_addr )
77      stack_size = 0;
78 
79  the_thread->Start.stack = stack_addr;
80 
81  return stack_size;
82}
Note: See TracBrowser for help on using the repository browser.