RTEMS
threads.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: BSD-2-Clause */
2 
11 /*
12  * Copyright (C) 2020 embedded brains GmbH (http://www.embedded-brains.de)
13  *
14  * Redistribution and use in source and binary forms, with or without
15  * modification, are permitted provided that the following conditions
16  * are met:
17  * 1. Redistributions of source code must retain the above copyright
18  * notice, this list of conditions and the following disclaimer.
19  * 2. Redistributions in binary form must reproduce the above copyright
20  * notice, this list of conditions and the following disclaimer in the
21  * documentation and/or other materials provided with the distribution.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
27  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33  * POSSIBILITY OF SUCH DAMAGE.
34  */
35 
36 #ifndef _RTEMS_CONFDEFS_THREADS_H
37 #define _RTEMS_CONFDEFS_THREADS_H
38 
39 #ifndef __CONFIGURATION_TEMPLATE_h
40 #error "Do not include this file directly, use <rtems/confdefs.h> instead"
41 #endif
42 
43 #ifdef CONFIGURE_INIT
44 
45 #include <rtems/confdefs/bdbuf.h>
47 #include <rtems/confdefs/percpu.h>
50 #include <rtems/score/thread.h>
51 #include <rtems/rtems/tasksdata.h>
52 
53 #ifdef RTEMS_POSIX_API
54  #include <rtems/posix/threadsup.h>
55 #endif
56 
57 #ifndef CONFIGURE_MAXIMUM_TASKS
58  #define CONFIGURE_MAXIMUM_TASKS 0
59 #endif
60 
61 #define _CONFIGURE_TASKS ( CONFIGURE_MAXIMUM_TASKS + _CONFIGURE_LIBBLOCK_TASKS )
62 
63 #ifndef CONFIGURE_MINIMUM_TASKS_WITH_USER_PROVIDED_STORAGE
64  #define CONFIGURE_MINIMUM_TASKS_WITH_USER_PROVIDED_STORAGE 0
65 #endif
66 
67 #if CONFIGURE_MINIMUM_TASKS_WITH_USER_PROVIDED_STORAGE > CONFIGURE_MAXIMUM_TASKS
68  #error "CONFIGURE_MINIMUM_TASKS_WITH_USER_PROVIDED_STORAGE shall be less than or equal to CONFIGURE_MAXIMUM_TASKS"
69 #endif
70 
71 #ifndef CONFIGURE_MAXIMUM_POSIX_THREADS
72  #define CONFIGURE_MAXIMUM_POSIX_THREADS 0
73 #endif
74 
75 #if CONFIGURE_MAXIMUM_POSIX_THREADS > 0
76  #include <rtems/posix/pthread.h>
77 #endif
78 
79 #if !defined(CONFIGURE_IDLE_TASK_INITIALIZES_APPLICATION) \
80  && CONFIGURE_MAXIMUM_TASKS == 0 \
81  && CONFIGURE_MAXIMUM_POSIX_THREADS == 0
82  #error "You must define one of CONFIGURE_IDLE_TASK_INITIALIZES_APPLICATION, CONFIGURE_MAXIMUM_TASKS, and CONFIGURE_MAXIMUM_POSIX_THREADS"
83 #endif
84 
85 #if !defined(CONFIGURE_RTEMS_INIT_TASKS_TABLE) \
86  && !defined(CONFIGURE_POSIX_INIT_THREAD_TABLE) \
87  && !defined(CONFIGURE_IDLE_TASK_INITIALIZES_APPLICATION)
88  #error "You must define one of CONFIGURE_IDLE_TASK_INITIALIZES_APPLICATION, CONFIGURE_RTEMS_INIT_TASKS_TABLE, and CONFIGURE_POSIX_INIT_THREAD_TABLE"
89 #endif
90 
91 #ifndef CONFIGURE_MAXIMUM_THREAD_NAME_SIZE
92  #define CONFIGURE_MAXIMUM_THREAD_NAME_SIZE THREAD_DEFAULT_MAXIMUM_NAME_SIZE
93 #endif
94 
95 #ifndef CONFIGURE_MAXIMUM_THREAD_LOCAL_STORAGE_SIZE
96  #define CONFIGURE_MAXIMUM_THREAD_LOCAL_STORAGE_SIZE 0
97 #endif
98 
99 #ifdef __cplusplus
100 extern "C" {
101 #endif
102 
103 typedef union {
104  Scheduler_Node Base;
105  #ifdef CONFIGURE_SCHEDULER_CBS
106  Scheduler_CBS_Node CBS;
107  #endif
108  #ifdef CONFIGURE_SCHEDULER_EDF
109  Scheduler_EDF_Node EDF;
110  #endif
111  #ifdef CONFIGURE_SCHEDULER_EDF_SMP
112  Scheduler_EDF_SMP_Node EDF_SMP;
113  #endif
114  #ifdef CONFIGURE_SCHEDULER_PRIORITY
115  Scheduler_priority_Node Priority;
116  #endif
117  #ifdef CONFIGURE_SCHEDULER_SIMPLE_SMP
118  Scheduler_SMP_Node Simple_SMP;
119  #endif
120  #ifdef CONFIGURE_SCHEDULER_PRIORITY_SMP
121  Scheduler_priority_SMP_Node Priority_SMP;
122  #endif
123  #ifdef CONFIGURE_SCHEDULER_PRIORITY_AFFINITY_SMP
124  Scheduler_priority_affinity_SMP_Node Priority_affinity_SMP;
125  #endif
126  #ifdef CONFIGURE_SCHEDULER_STRONG_APA
127  Scheduler_strong_APA_Node Strong_APA;
128  #endif
129  #ifdef CONFIGURE_SCHEDULER_USER_PER_THREAD
130  CONFIGURE_SCHEDULER_USER_PER_THREAD User;
131  #endif
132 } Configuration_Scheduler_node;
133 
134 #ifdef RTEMS_SMP
135  const size_t _Scheduler_Node_size = sizeof( Configuration_Scheduler_node );
136 #endif
137 
139 
140 const size_t _Thread_Maximum_TLS_size =
142 
144  Thread_Control Control;
145  #if CONFIGURE_MAXIMUM_USER_EXTENSIONS > 0
146  void *extensions[ CONFIGURE_MAXIMUM_USER_EXTENSIONS + 1 ];
147  #endif
148  Configuration_Scheduler_node Scheduler_nodes[ _CONFIGURE_SCHEDULER_COUNT ];
149  RTEMS_API_Control API_RTEMS;
150  #ifdef RTEMS_POSIX_API
151  POSIX_API_Control API_POSIX;
152  #endif
153  #if CONFIGURE_MAXIMUM_THREAD_NAME_SIZE > 1
155  #endif
156  #ifdef _CONFIGURE_ENABLE_NEWLIB_REENTRANCY
157  struct _reent Newlib;
158  #else
159  struct { /* Empty */ } Newlib;
160  #endif
161 };
162 
164  {
165  offsetof( Thread_Configured_control, Control.Scheduler.nodes ),
166  offsetof( Thread_Configured_control, Scheduler_nodes )
167  }, {
168  offsetof(
170  Control.API_Extensions[ THREAD_API_RTEMS ]
171  ),
172  offsetof( Thread_Configured_control, API_RTEMS )
173  }, {
174  offsetof(
176  Control.libc_reent
177  ),
178  offsetof( Thread_Configured_control, Newlib )
179  }
180  #if CONFIGURE_MAXIMUM_THREAD_NAME_SIZE > 1
181  , {
182  offsetof(
184  Control.Join_queue.Queue.name
185  ),
186  offsetof( Thread_Configured_control, name )
187  }
188  #endif
189  #ifdef RTEMS_POSIX_API
190  , {
191  offsetof(
193  Control.API_Extensions[ THREAD_API_POSIX ]
194  ),
195  offsetof( Thread_Configured_control, API_POSIX )
196  }
197  #endif
198 };
199 
200 const size_t _Thread_Control_add_on_count =
202 
203 #ifdef RTEMS_SMP
205  Thread_queue_Heads Heads;
206  Thread_queue_Priority_queue Priority[ _CONFIGURE_SCHEDULER_COUNT ];
207  };
208 
209  const size_t _Thread_queue_Heads_size =
211 #endif
212 
213 const size_t _Thread_Initial_thread_count =
214  rtems_resource_maximum_per_allocation( _CONFIGURE_TASKS ) +
216 
217 #if defined(RTEMS_MULTIPROCESSING) && defined(CONFIGURE_MP_APPLICATION)
218  #define _CONFIGURE_MPCI_RECEIVE_SERVER_COUNT 1
219 #else
220  #define _CONFIGURE_MPCI_RECEIVE_SERVER_COUNT 0
221 #endif
222 
223 THREAD_INFORMATION_DEFINE(
224  _Thread,
225  OBJECTS_INTERNAL_API,
226  OBJECTS_INTERNAL_THREADS,
227  _CONFIGURE_MAXIMUM_PROCESSORS + _CONFIGURE_MPCI_RECEIVE_SERVER_COUNT
228 );
229 
230 #if _CONFIGURE_TASKS > 0
231  THREAD_INFORMATION_DEFINE(
232  _RTEMS_tasks,
233  OBJECTS_CLASSIC_API,
234  OBJECTS_RTEMS_TASKS,
235  _CONFIGURE_TASKS
236  );
237 #endif
238 
239 #if CONFIGURE_MAXIMUM_POSIX_THREADS > 0
240  const size_t _POSIX_Threads_Minimum_stack_size =
242 
243  THREAD_INFORMATION_DEFINE(
244  _POSIX_Threads,
245  OBJECTS_POSIX_API,
246  OBJECTS_POSIX_THREADS,
248  );
249 #endif
250 
251 #ifdef __cplusplus
252 }
253 #endif
254 
255 #endif /* CONFIGURE_INIT */
256 
257 #endif /* _RTEMS_CONFDEFS_THREADS_H */
#define CONFIGURE_MAXIMUM_USER_EXTENSIONS
This configuration option is an integer define.
Definition: appl-config.h:977
Scheduler node specialization for EDF schedulers.
Definition: scheduleredf.h:90
Thread priority queue.
Definition: threadq.h:324
Evaluate Per-CPU Configuration Options.
Evaluate Unlimited Objects Configuration Options.
Evaluate Scheduler Configuration Options.
const size_t _Thread_Maximum_TLS_size
If this constant is greater than zero, then it defines the maximum thread-local storage size...
const size_t _Thread_Control_add_on_count
Thread control add-on count.
const Thread_Control_add_on _Thread_Control_add_ons[]
Thread control add-ons.
Thread queue heads.
Definition: threadq.h:360
Evaluate User Extensions Configuration Options.
Thread control add-on.
Definition: thread.h:893
Scheduler node specialization for SMP schedulers.
Definition: schedulersmp.h:100
#define CONFIGURE_MAXIMUM_THREAD_NAME_SIZE
This configuration option is an integer define.
Definition: appl-config.h:2727
Scheduler node specialization for Deterministic Priority schedulers.
#define rtems_resource_maximum_per_allocation(_resource)
Returns the maximum number per allocation of a resource number.
Definition: config.h:375
struct Thread_queue_Configured_heads Thread_queue_Configured_heads
The configured thread queue heads.
Definition: thread.h:981
#define CONFIGURE_MINIMUM_POSIX_THREAD_STACK_SIZE
This configuration option is an integer define.
Definition: appl-config.h:3819
const size_t _Scheduler_Node_size
The size of a scheduler node.
#define RTEMS_ARRAY_SIZE(_array)
Returns the element count of the specified array.
Definition: basedefs.h:459
const size_t _Thread_queue_Heads_size
Size of the thread queue heads of a particular application.
Scheduler node for per-thread data.
Definition: schedulernode.h:79
#define CONFIGURE_MAXIMUM_POSIX_THREADS
This configuration option is an integer define.
Definition: appl-config.h:3746
#define CONFIGURE_MAXIMUM_THREAD_LOCAL_STORAGE_SIZE
This configuration option is an integer define.
Definition: appl-config.h:910
Constants and Structures Related with the Thread Control Block.
struct Thread_Configured_control Thread_Configured_control
The configured thread control block.
Definition: thread.h:972
const size_t _Thread_Initial_thread_count
Count of configured threads.
Evaluate Block Device Cache Configuration Options.
const size_t _Thread_Maximum_name_size
Maximum size of a thread name in characters (including the terminating &#39;\0&#39; character).
Classic Tasks Manager Data Structures.