1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
|
/***************************************************************************/
/* Copyright (c) 2024 Microsoft Corporation */
/* Copyright (c) 2026 Eclipse ThreadX contributors */
/* */
/* This program and the accompanying materials are made available under */
/* the terms of the MIT License which is available at */
/* https://opensource.org/licenses/MIT. */
/* */
/* SPDX-License-Identifier: MIT */
/***************************************************************************/
/* Simple nested-signaling test. */
#include "pthread.h"
#define DEMO_STACK_SIZE 2048
#define DEMO_BYTE_POOL_SIZE 9120
/* Define the POSIX pthread object control blocks ... */
pthread_t pthread_0;
/* Define pthread attributes objects */
pthread_attr_t ptattr0;
/* Define the counters used in this test application... */
ULONG pthread_0_counter;
ULONG pthread_0_signal_counter15;
ULONG pthread_0_signal_counter14;
ULONG pthread_0_signal_counter13;
/* Define pthread function prototypes. */
VOID *pthread_0_entry(VOID *);
/* Define signal handlers. */
VOID pthread_0_signal_handler15(int);
VOID pthread_0_signal_handler14(int);
VOID pthread_0_signal_handler13(int);
ULONG free_memory[192*1024 / sizeof(ULONG)];
/* Define main entry point. */
INT main()
{
/* Enter the ThreadX kernel. */
tx_kernel_enter();
}
/* Define what the initial system looks like. */
VOID tx_application_define(VOID *first_unused_memory)
{
VOID* storage_ptr;
struct sched_param param;
/* Init POSIX Wrapper */
storage_ptr = (VOID*) posix_initialize((VOID* )free_memory);
/* Put system definition stuff in here, e.g. pthread creates and other assoerted
create information. */
/* Create pthread attributes. */
pthread_attr_init(&ptattr0);
/* Create a sched_param structure */
memset(¶m, 0, sizeof(param));
/* Now create all pthreads , firstly modify respective ptheread
attribute with desired priority and stack start address and then create the pthread */
/* Create pthread 0. */
param.sched_priority = 10;
pthread_attr_setschedparam(&ptattr0, ¶m);
pthread_attr_setstackaddr(&ptattr0, storage_ptr );
storage_ptr = (int *) storage_ptr + DEMO_STACK_SIZE;
pthread_create (&pthread_0, &ptattr0,pthread_0_entry,NULL);
}
VOID error_handler(void)
{
while(1)
{
}
}
/* Define the signal handlers. */
VOID pthread_0_signal_handler13(int signo)
{
/* Check for pthread self call not pthread 0. The signal handler should appear to be
called from pthread 0. */
if (pthread_self() != pthread_0)
{
/* Call error handler. */
error_handler();
}
/* Check for proper signal. */
if (signo != 13)
{
/* Call error handler. */
error_handler();
}
/* Just increment the signal counter for this test. */
pthread_0_signal_counter13++;
}
VOID pthread_0_signal_handler14(int signo)
{
/* Check for pthread self call not pthread 0. The signal handler should appear to be
called from pthread 0. */
if (pthread_self() != pthread_0)
{
/* Call error handler. */
error_handler();
}
/* Check for proper signal. */
if (signo != 14)
{
/* Call error handler. */
error_handler();
}
/* Just increment the signal counter for this test. */
pthread_0_signal_counter14++;
/* Raise another signal for nesting test. */
pthread_kill(pthread_0, 13);
}
VOID pthread_0_signal_handler15(int signo)
{
/* Check for pthread self call not pthread 0. The signal handler should appear to be
called from pthread 0. */
if (pthread_self() != pthread_0)
{
/* Call error handler. */
error_handler();
}
/* Check for proper signal. */
if (signo != 15)
{
/* Call error handler. */
error_handler();
}
/* Just increment the signal counter for this test. */
pthread_0_signal_counter15++;
/* Raise another signal for nesting test. */
pthread_kill(pthread_0, 14);
}
/* Define the test pthreads */
INT pt0_status=0;
/* Self signal test. */
VOID *pthread_0_entry(VOID *pthread0_input)
{
/* Register the signal handlers. */
pt0_status = signal(15, pthread_0_signal_handler15);
/* Check for error. */
if (pt0_status)
error_handler();
pt0_status = signal(14, pthread_0_signal_handler14);
/* Check for error. */
if (pt0_status)
error_handler();
pt0_status = signal(13, pthread_0_signal_handler13);
/* Check for error. */
if (pt0_status)
error_handler();
/* This pthread simply sits in while-forever-sleep loop */
while(1)
{
/* Increment the pthread counter.*/
pthread_0_counter++;
/* Raise the signal. */
pt0_status = pthread_kill(pthread_0, 15);
/* Check for errors. */
if ((pt0_status) ||
(pthread_0_counter != pthread_0_signal_counter15) ||
(pthread_0_counter != pthread_0_signal_counter14) ||
(pthread_0_counter != pthread_0_signal_counter13))
{
error_handler();
break;
}
}
return(&pt0_status);
}
|