Revision 732a4657 kernel/patches/introduce-thread-hierarchy.patch
kernel/patches/introduce-thread-hierarchy.patch | ||
---|---|---|
1 | 1 |
diff --git a/os/rt/include/chschd.h b/os/rt/include/chschd.h |
2 |
index 1d11d17..c71d8b4 100644 |
|
3 | 2 |
--- a/os/rt/include/chschd.h |
4 | 3 |
+++ b/os/rt/include/chschd.h |
5 |
@@ -177,6 +177,23 @@ struct ch_thread { |
|
4 |
@@ -176,6 +176,23 @@ struct ch_thread { |
|
5 |
* @brief References to this thread. |
|
6 | 6 |
*/ |
7 | 7 |
trefs_t refs; |
8 |
#endif
|
|
8 |
+#endif
|
|
9 | 9 |
+#if (CH_CFG_USE_THREADHIERARCHY == TRUE) || defined(__DOXYGEN__) |
10 | 10 |
+ /** |
11 | 11 |
+ * @brief Pointer to the parent thread. |
... | ... | |
22 | 22 |
+ * @brief NULL if there are no more child threads. |
23 | 23 |
+ */ |
24 | 24 |
+ thread_t *sibling; |
25 |
+#endif
|
|
25 |
#endif
|
|
26 | 26 |
/** |
27 | 27 |
* @brief Number of ticks remaining to this thread. |
28 |
*/ |
|
29 | 28 |
diff --git a/os/rt/include/chthreads.h b/os/rt/include/chthreads.h |
30 |
index 166d566..b767d74 100644 |
|
31 | 29 |
--- a/os/rt/include/chthreads.h |
32 | 30 |
+++ b/os/rt/include/chthreads.h |
33 |
@@ -79,6 +79,10 @@ typedef struct {
|
|
31 |
@@ -79,6 +79,12 @@ typedef struct {
|
|
34 | 32 |
* @brief Thread argument. |
35 | 33 |
*/ |
36 | 34 |
void *arg; |
35 |
+#if (CH_CFG_USE_THREADHIERARCHY) == TRUE || defined(__DOXYGEN__) |
|
37 | 36 |
+ /** |
38 | 37 |
+ * @brief Pointer to the parent thread. |
39 | 38 |
+ */ |
40 | 39 |
+ thread_t *parent; |
40 |
+#endif |
|
41 | 41 |
} thread_descriptor_t; |
42 | 42 |
|
43 | 43 |
/*===========================================================================*/ |
44 |
@@ -220,7 +224,7 @@ typedef struct {
|
|
44 |
@@ -220,7 +226,11 @@ typedef struct {
|
|
45 | 45 |
#ifdef __cplusplus |
46 | 46 |
extern "C" { |
47 | 47 |
#endif |
48 |
- thread_t *_thread_init(thread_t *tp, const char *name, tprio_t prio);
|
|
48 |
+#if CH_CFG_USE_THREADHIERARCHY == TRUE
|
|
49 | 49 |
+ thread_t *_thread_init(thread_t *tp, thread_t* parent, const char *name, tprio_t prio); |
50 |
+#else |
|
51 |
thread_t *_thread_init(thread_t *tp, const char *name, tprio_t prio); |
|
52 |
+#endif |
|
50 | 53 |
#if CH_DBG_FILL_THREADS == TRUE |
51 | 54 |
void _thread_memfill(uint8_t *startp, uint8_t *endp, uint8_t v); |
52 | 55 |
#endif |
53 |
@@ -228,8 +232,13 @@ extern "C" {
|
|
56 |
@@ -228,8 +238,13 @@ extern "C" {
|
|
54 | 57 |
thread_t *chThdCreateSuspended(const thread_descriptor_t *tdp); |
55 | 58 |
thread_t *chThdCreateI(const thread_descriptor_t *tdp); |
56 | 59 |
thread_t *chThdCreate(const thread_descriptor_t *tdp); |
... | ... | |
65 | 68 |
#if CH_CFG_USE_REGISTRY == TRUE |
66 | 69 |
thread_t *chThdAddRef(thread_t *tp); |
67 | 70 |
diff --git a/os/rt/src/chsys.c b/os/rt/src/chsys.c |
68 |
index 346a8ba..c789d01 100644 |
|
69 | 71 |
--- a/os/rt/src/chsys.c |
70 | 72 |
+++ b/os/rt/src/chsys.c |
71 |
@@ -126,13 +126,13 @@ void chSysInit(void) {
|
|
73 |
@@ -126,14 +126,26 @@ void chSysInit(void) {
|
|
72 | 74 |
#if CH_CFG_NO_IDLE_THREAD == FALSE |
73 | 75 |
/* Now this instructions flow becomes the main thread.*/ |
74 | 76 |
#if CH_CFG_USE_REGISTRY == TRUE |
75 |
- currp = _thread_init(&ch.mainthread, (const char *)&ch_debug, NORMALPRIO);
|
|
77 |
+#if CH_CFG_USE_THREADHIERARCHY == TRUE
|
|
76 | 78 |
+ currp = _thread_init(&ch.mainthread, NULL, (const char *)&ch_debug, NORMALPRIO); |
77 |
#else |
|
78 |
- currp = _thread_init(&ch.mainthread, "main", NORMALPRIO); |
|
79 |
+#else |
|
80 |
currp = _thread_init(&ch.mainthread, (const char *)&ch_debug, NORMALPRIO); |
|
81 |
+#endif |
|
82 |
+#else |
|
83 |
+#if CH_CFG_USE_THREADHIERARCHY == TRUE |
|
79 | 84 |
+ currp = _thread_init(&ch.mainthread, NULL, "main", NORMALPRIO); |
85 |
#else |
|
86 |
currp = _thread_init(&ch.mainthread, "main", NORMALPRIO); |
|
80 | 87 |
#endif |
88 |
+#endif |
|
81 | 89 |
#else |
82 | 90 |
/* Now this instructions flow becomes the idle thread.*/ |
83 |
- currp = _thread_init(&ch.mainthread, "idle", IDLEPRIO);
|
|
91 |
+#if CH_CFG_USE_THREADHIERARCHY == TRUE
|
|
84 | 92 |
+ currp = _thread_init(&ch.mainthread, NULL, "idle", IDLEPRIO); |
93 |
+#else |
|
94 |
currp = _thread_init(&ch.mainthread, "idle", IDLEPRIO); |
|
85 | 95 |
#endif |
96 |
+#endif |
|
86 | 97 |
|
87 | 98 |
#if CH_DBG_ENABLE_STACK_CHECK == TRUE |
88 |
@@ -172,6 +172,7 @@ void chSysInit(void) { |
|
99 |
{ |
|
100 |
@@ -172,6 +184,9 @@ void chSysInit(void) { |
|
89 | 101 |
THD_WORKING_AREA_END(ch_idle_thread_wa), |
90 | 102 |
IDLEPRIO, |
91 | 103 |
_idle_thread, |
104 |
+#if CH_CFG_USE_THREADHIERARCHY == TRUE |
|
92 | 105 |
+ NULL, |
106 |
+#endif |
|
93 | 107 |
NULL |
94 | 108 |
}; |
95 | 109 |
|
96 | 110 |
diff --git a/os/rt/src/chthreads.c b/os/rt/src/chthreads.c |
97 |
index 171c683..6bc0f78 100644 |
|
98 | 111 |
--- a/os/rt/src/chthreads.c |
99 | 112 |
+++ b/os/rt/src/chthreads.c |
100 |
@@ -70,6 +70,46 @@
|
|
113 |
@@ -70,22 +70,67 @@
|
|
101 | 114 |
/* Module local functions. */ |
102 | 115 |
/*===========================================================================*/ |
103 | 116 |
|
... | ... | |
144 | 157 |
/*===========================================================================*/ |
145 | 158 |
/* Module exported functions. */ |
146 | 159 |
/*===========================================================================*/ |
147 |
@@ -79,13 +119,14 @@ |
|
160 |
|
|
161 |
+#if CH_CFG_USE_THREADHIERARCHY == TRUE || defined(__DOXYGEN__) |
|
162 |
/** |
|
163 |
* @brief Initializes a thread structure. |
|
148 | 164 |
* @note This is an internal functions, do not use it in application code. |
149 | 165 |
* |
150 | 166 |
* @param[in] tp pointer to the thread |
... | ... | |
155 | 171 |
* |
156 | 172 |
* @notapi |
157 | 173 |
*/ |
158 |
-thread_t *_thread_init(thread_t *tp, const char *name, tprio_t prio) { |
|
159 | 174 |
+thread_t *_thread_init(thread_t *tp, thread_t *parent, const char *name, tprio_t prio) { |
175 |
+#else |
|
176 |
thread_t *_thread_init(thread_t *tp, const char *name, tprio_t prio) { |
|
177 |
+#endif |
|
160 | 178 |
|
161 | 179 |
tp->prio = prio; |
162 | 180 |
tp->state = CH_STATE_WTSTART; |
163 |
@@ -110,6 +151,17 @@ thread_t *_thread_init(thread_t *tp, const char *name, tprio_t prio) {
|
|
181 |
@@ -110,6 +155,17 @@ thread_t *_thread_init(thread_t *tp, const char *name, tprio_t prio) {
|
|
164 | 182 |
#else |
165 | 183 |
(void)name; |
166 | 184 |
#endif |
... | ... | |
178 | 196 |
#if CH_CFG_USE_WAITEXIT == TRUE |
179 | 197 |
list_init(&tp->waiting); |
180 | 198 |
#endif |
181 |
@@ -190,7 +242,7 @@ thread_t *chThdCreateSuspendedI(const thread_descriptor_t *tdp) {
|
|
199 |
@@ -190,7 +246,11 @@ thread_t *chThdCreateSuspendedI(const thread_descriptor_t *tdp) {
|
|
182 | 200 |
PORT_SETUP_CONTEXT(tp, tdp->wbase, tp, tdp->funcp, tdp->arg); |
183 | 201 |
|
184 | 202 |
/* The driver object is initialized but not started.*/ |
185 |
- return _thread_init(tp, tdp->name, tdp->prio);
|
|
203 |
+#if CH_CFG_USE_THREADHIERARCHY == TRUE
|
|
186 | 204 |
+ return _thread_init(tp, tdp->parent, tdp->name, tdp->prio); |
205 |
+#else |
|
206 |
return _thread_init(tp, tdp->name, tdp->prio); |
|
207 |
+#endif |
|
208 |
} |
|
209 |
|
|
210 |
/** |
|
211 |
@@ -300,6 +360,7 @@ thread_t *chThdCreate(const thread_descriptor_t *tdp) { |
|
212 |
return tp; |
|
187 | 213 |
} |
188 | 214 |
|
215 |
+#if CH_CFG_USE_THREADHIERARCHY == TRUE || defined(__DOXYGEN__) |
|
189 | 216 |
/** |
190 |
@@ -315,13 +367,21 @@ thread_t *chThdCreate(const thread_descriptor_t *tdp) { |
|
217 |
* @brief Creates a new thread into a static memory area. |
|
218 |
* @post The created thread has a reference counter set to one, it is |
|
219 |
@@ -315,13 +376,20 @@ thread_t *chThdCreate(const thread_descriptor_t *tdp) { |
|
191 | 220 |
* @param[in] pf the thread function |
192 | 221 |
* @param[in] arg an argument passed to the thread function. It can be |
193 | 222 |
* @p NULL. |
... | ... | |
199 | 228 |
* |
200 | 229 |
* @api |
201 | 230 |
*/ |
202 |
+#if (CH_CFG_USE_THREADHIERARCHY == TRUE) || defined(__DOXYGEN__) |
|
203 | 231 |
+thread_t *chThdCreateStatic(void *wsp, size_t size, |
204 | 232 |
+ tprio_t prio, tfunc_t pf, void *arg, thread_t *parent) { |
205 | 233 |
+#else |
... | ... | |
209 | 237 |
thread_t *tp; |
210 | 238 |
|
211 | 239 |
chDbgCheck((wsp != NULL) && |
212 |
@@ -358,7 +418,11 @@ thread_t *chThdCreateStatic(void *wsp, size_t size,
|
|
240 |
@@ -358,7 +426,11 @@ thread_t *chThdCreateStatic(void *wsp, size_t size,
|
|
213 | 241 |
/* Setting up the port-dependent part of the working area.*/ |
214 | 242 |
PORT_SETUP_CONTEXT(tp, wsp, tp, pf, arg); |
215 | 243 |
|
216 |
- tp = _thread_init(tp, "noname", prio); |
|
217 | 244 |
+#if CH_CFG_USE_THREADHIERARCHY == TRUE |
218 | 245 |
+ tp = _thread_init(tp, parent, "noname", prio); |
219 | 246 |
+#else |
220 |
+ tp = _thread_init(tp, NULL, "noname", prio);
|
|
247 |
tp = _thread_init(tp, "noname", prio);
|
|
221 | 248 |
+#endif |
222 | 249 |
|
223 | 250 |
/* Starting the thread immediately.*/ |
224 | 251 |
chSchWakeupS(tp, MSG_OK); |
225 |
@@ -529,6 +593,30 @@ void chThdExitS(msg_t msg) {
|
|
252 |
@@ -529,6 +601,30 @@ void chThdExitS(msg_t msg) {
|
|
226 | 253 |
#endif |
227 | 254 |
#endif |
228 | 255 |
|
... | ... | |
253 | 280 |
/* Going into final state.*/ |
254 | 281 |
chSchGoSleepS(CH_STATE_FINAL); |
255 | 282 |
|
256 |
@@ -611,6 +699,43 @@ tprio_t chThdSetPriority(tprio_t newprio) { |
|
283 |
@@ -610,6 +706,43 @@ tprio_t chThdSetPriority(tprio_t newprio) { |
|
284 |
#else |
|
257 | 285 |
oldprio = currp->prio; |
258 | 286 |
currp->prio = newprio; |
259 |
#endif
|
|
287 |
+#endif
|
|
260 | 288 |
+#if (CH_CFG_USE_THREADHIERARCHY == TRUE) && (CH_CFG_THREADHIERARCHY_ORDERED == TRUE) |
261 | 289 |
+ /* Reorder sibling list. */ |
262 | 290 |
+ if (currp->parent != NULL && newprio != oldprio) { |
... | ... | |
293 | 321 |
+ } |
294 | 322 |
+ } |
295 | 323 |
+ } |
296 |
+#endif
|
|
324 |
#endif
|
|
297 | 325 |
chSchRescheduleS(); |
298 | 326 |
chSysUnlock(); |
299 |
|
|
300 | 327 |
diff --git a/test/rt/source/test/rt_test_root.c b/test/rt/source/test/rt_test_root.c |
301 |
index e03d0f1..150d33d 100644 |
|
302 | 328 |
--- a/test/rt/source/test/rt_test_root.c |
303 | 329 |
+++ b/test/rt/source/test/rt_test_root.c |
304 | 330 |
@@ -106,6 +106,14 @@ void * ROMCONST wa[5] = {test_buffer + (WA_SIZE * 0), |
... | ... | |
317 | 343 |
* Sets a termination request in all the test-spawned threads. |
318 | 344 |
*/ |
319 | 345 |
diff --git a/test/rt/source/test/rt_test_root.h b/test/rt/source/test/rt_test_root.h |
320 |
index 6da777b..0cd40fc 100644 |
|
321 | 346 |
--- a/test/rt/source/test/rt_test_root.h |
322 | 347 |
+++ b/test/rt/source/test/rt_test_root.h |
323 | 348 |
@@ -88,6 +88,7 @@ extern thread_t *threads[MAX_THREADS]; |
... | ... | |
329 | 354 |
void test_wait_threads(void); |
330 | 355 |
systime_t test_wait_tick(void); |
331 | 356 |
diff --git a/test/rt/source/test/rt_test_sequence_001.c b/test/rt/source/test/rt_test_sequence_001.c |
332 |
index 6f2b96f..f91c23f 100644 |
|
333 | 357 |
--- a/test/rt/source/test/rt_test_sequence_001.c |
334 | 358 |
+++ b/test/rt/source/test/rt_test_sequence_001.c |
335 | 359 |
@@ -193,6 +193,12 @@ static void rt_test_001_003_execute(void) { |
... | ... | |
347 | 371 |
test_println(""); |
348 | 372 |
@@ -207,7 +213,7 @@ static void rt_test_001_003_execute(void) { |
349 | 373 |
test_println(""); |
350 |
test_print("--- CH_CFG_USE_MUTEXES_RECURS: ");
|
|
374 |
test_print("--- CH_CFG_USE_MUTEXES_RECURSIVE: ");
|
|
351 | 375 |
test_printn(CH_CFG_USE_MUTEXES_RECURSIVE); |
352 | 376 |
- test_println(""); |
353 | 377 |
+ test_println(""); |
... | ... | |
355 | 379 |
test_printn(CH_CFG_USE_CONDVARS); |
356 | 380 |
test_println(""); |
357 | 381 |
diff --git a/test/rt/source/test/rt_test_sequence_003.c b/test/rt/source/test/rt_test_sequence_003.c |
358 |
index 8598b12..f1ece71 100644 |
|
359 | 382 |
--- a/test/rt/source/test/rt_test_sequence_003.c |
360 | 383 |
+++ b/test/rt/source/test/rt_test_sequence_003.c |
361 | 384 |
@@ -46,6 +46,20 @@ static THD_FUNCTION(thread, p) { |
... | ... | |
836 | 859 |
/**************************************************************************** |
837 | 860 |
* Exported data. |
838 | 861 |
****************************************************************************/ |
839 |
@@ -339,6 +752,9 @@ const testcase_t * const rt_test_sequence_003_array[] = { |
|
862 |
@@ -338,6 +751,9 @@ const testcase_t * const rt_test_sequence_003_array[] = { |
|
863 |
&rt_test_003_003, |
|
840 | 864 |
#if (CH_CFG_USE_MUTEXES) || defined(__DOXYGEN__) |
841 | 865 |
&rt_test_003_004, |
842 |
#endif
|
|
866 |
+#endif
|
|
843 | 867 |
+#if (CH_CFG_USE_THREADHIERARCHY) || defined(__DOXYGEN__) |
844 | 868 |
+ &rt_test_003_005, |
845 |
+#endif
|
|
869 |
#endif
|
|
846 | 870 |
NULL |
847 | 871 |
}; |
848 |
|
|
849 | 872 |
diff --git a/test/rt/source/test/rt_test_sequence_004.c b/test/rt/source/test/rt_test_sequence_004.c |
850 |
index 7ad2ab5..4226ffc 100644 |
|
851 | 873 |
--- a/test/rt/source/test/rt_test_sequence_004.c |
852 | 874 |
+++ b/test/rt/source/test/rt_test_sequence_004.c |
853 | 875 |
@@ -83,7 +83,7 @@ static void rt_test_004_001_execute(void) { |
... | ... | |
860 | 882 |
msg = chThdSuspendTimeoutS(&tr1, TIME_INFINITE); |
861 | 883 |
chSysUnlock(); |
862 | 884 |
diff --git a/test/rt/source/test/rt_test_sequence_005.c b/test/rt/source/test/rt_test_sequence_005.c |
863 |
index 29cebb9..3cde985 100644 |
|
864 | 885 |
--- a/test/rt/source/test/rt_test_sequence_005.c |
865 | 886 |
+++ b/test/rt/source/test/rt_test_sequence_005.c |
866 | 887 |
@@ -178,11 +178,11 @@ static void rt_test_005_002_execute(void) { |
... | ... | |
917 | 938 |
} |
918 | 939 |
|
919 | 940 |
diff --git a/test/rt/source/test/rt_test_sequence_006.c b/test/rt/source/test/rt_test_sequence_006.c |
920 |
index 3694755..4d50caa 100644 |
|
921 | 941 |
--- a/test/rt/source/test/rt_test_sequence_006.c |
922 | 942 |
+++ b/test/rt/source/test/rt_test_sequence_006.c |
923 | 943 |
@@ -276,11 +276,11 @@ static void rt_test_006_001_execute(void) { |
... | ... | |
1038 | 1058 |
|
1039 | 1059 |
/* [6.9.5] Signaling C1: TA wakes up, unlocks M1 and priority goes to |
1040 | 1060 |
diff --git a/test/rt/source/test/rt_test_sequence_007.c b/test/rt/source/test/rt_test_sequence_007.c |
1041 |
index 62a9df9..6dabea2 100644 |
|
1042 | 1061 |
--- a/test/rt/source/test/rt_test_sequence_007.c |
1043 | 1062 |
+++ b/test/rt/source/test/rt_test_sequence_007.c |
1044 | 1063 |
@@ -79,7 +79,7 @@ static void rt_test_007_001_execute(void) { |
... | ... | |
1051 | 1070 |
} |
1052 | 1071 |
|
1053 | 1072 |
diff --git a/test/rt/source/test/rt_test_sequence_008.c b/test/rt/source/test/rt_test_sequence_008.c |
1054 |
index d2bb805..cead16b 100644 |
|
1055 | 1073 |
--- a/test/rt/source/test/rt_test_sequence_008.c |
1056 | 1074 |
+++ b/test/rt/source/test/rt_test_sequence_008.c |
1057 | 1075 |
@@ -226,7 +226,7 @@ static void rt_test_008_003_execute(void) { |
... | ... | |
1091 | 1109 |
} |
1092 | 1110 |
|
1093 | 1111 |
diff --git a/test/rt/source/test/rt_test_sequence_010.c b/test/rt/source/test/rt_test_sequence_010.c |
1094 |
index 1c77343..e21c840 100644 |
|
1095 | 1112 |
--- a/test/rt/source/test/rt_test_sequence_010.c |
1096 | 1113 |
+++ b/test/rt/source/test/rt_test_sequence_010.c |
1097 | 1114 |
@@ -169,7 +169,7 @@ static void rt_test_010_001_execute(void) { |
Also available in: Unified diff