source: rtems/cpukit/score/src/thread.c @ 6e4f929

5
Last change on this file since 6e4f929 was 6e4f929, checked in by Sebastian Huber <sebastian.huber@…>, on 05/06/16 at 04:44:41

score: Introduce thread state lock

Update #2556.

  • Property mode set to 100644
File size: 3.1 KB
Line 
1/**
2 *  @file
3 *
4 *  @brief Initialize Thread Handler
5 *  @ingroup ScoreThread
6 */
7
8/*
9 *  COPYRIGHT (c) 1989-2011.
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.org/license/LICENSE.
15 */
16
17#if HAVE_CONFIG_H
18#include "config.h"
19#endif
20
21#include <rtems/score/threadimpl.h>
22#include <rtems/score/interr.h>
23#include <rtems/score/scheduler.h>
24#include <rtems/score/wkspace.h>
25
26#define THREAD_OFFSET_ASSERT( field ) \
27  RTEMS_STATIC_ASSERT( \
28    offsetof( Thread_Control, field ) == offsetof( Thread_Proxy_control, field ), \
29    field \
30  )
31
32THREAD_OFFSET_ASSERT( Object );
33THREAD_OFFSET_ASSERT( Join_queue );
34THREAD_OFFSET_ASSERT( current_state );
35THREAD_OFFSET_ASSERT( current_priority );
36THREAD_OFFSET_ASSERT( real_priority );
37THREAD_OFFSET_ASSERT( priority_generation );
38THREAD_OFFSET_ASSERT( priority_restore_hint );
39THREAD_OFFSET_ASSERT( resource_count );
40THREAD_OFFSET_ASSERT( Wait );
41THREAD_OFFSET_ASSERT( Timer );
42#if defined(RTEMS_MULTIPROCESSING)
43THREAD_OFFSET_ASSERT( receive_packet );
44#endif
45
46Thread_Information _Thread_Internal_information;
47
48void _Thread_Initialize_information(
49  Thread_Information  *information,
50  Objects_APIs         the_api,
51  uint16_t             the_class,
52  uint32_t             maximum,
53  bool                 is_string,
54  uint32_t             maximum_name_length
55)
56{
57  _Objects_Initialize_information(
58    &information->Objects,
59    the_api,
60    the_class,
61    maximum,
62    _Thread_Control_size,
63    is_string,
64    maximum_name_length,
65    NULL
66  );
67
68  _Freechain_Initialize(
69    &information->Free_thread_queue_heads,
70    _Workspace_Allocate_or_fatal_error,
71    _Objects_Maximum_per_allocation( maximum ),
72    THREAD_QUEUE_HEADS_SIZE( _Scheduler_Count )
73  );
74}
75
76void _Thread_Handler_initialization(void)
77{
78  rtems_stack_allocate_init_hook stack_allocate_init_hook =
79    rtems_configuration_get_stack_allocate_init_hook();
80  #if defined(RTEMS_MULTIPROCESSING)
81    uint32_t maximum_proxies =
82      _Configuration_MP_table->maximum_proxies;
83  #endif
84
85  if ( rtems_configuration_get_stack_allocate_hook() == NULL ||
86       rtems_configuration_get_stack_free_hook() == NULL)
87    _Terminate(
88      INTERNAL_ERROR_CORE,
89      true,
90      INTERNAL_ERROR_BAD_STACK_HOOK
91    );
92
93  if ( stack_allocate_init_hook != NULL )
94    (*stack_allocate_init_hook)( rtems_configuration_get_stack_space_size() );
95
96  #if defined(RTEMS_MULTIPROCESSING)
97    _Thread_MP_Handler_initialization( maximum_proxies );
98  #endif
99
100  /*
101   *  Initialize the internal class of threads.  We need an IDLE thread
102   *  per CPU in an SMP system.  In addition, if this is a loosely
103   *  coupled multiprocessing system, account for the MPCI Server Thread.
104   */
105  _Thread_Initialize_information(
106    &_Thread_Internal_information,
107    OBJECTS_INTERNAL_API,
108    OBJECTS_INTERNAL_THREADS,
109    _Thread_Get_maximum_internal_threads(),
110    false,                      /* true if names for this object are strings */
111    8                           /* maximum length of each object's name */
112  );
113
114}
Note: See TracBrowser for help on using the repository browser.