@@ -87,23 +87,25 @@ const pthread_attr_t g_default_pthread_attr = PTHREAD_ATTR_INITIALIZER;
87
87
*
88
88
****************************************************************************/
89
89
90
- static inline void pthread_tcb_setup (FAR struct pthread_tcb_s * ptcb ,
90
+ static inline void pthread_tcb_setup (FAR struct tcb_s * ptcb ,
91
91
FAR struct tcb_s * parent ,
92
92
pthread_trampoline_t trampoline ,
93
93
pthread_addr_t arg )
94
94
{
95
+ FAR struct pthread_entry_s * entry ;
95
96
#if CONFIG_TASK_NAME_SIZE > 0
96
97
/* Copy the pthread name into the TCB */
97
98
98
- strlcpy (ptcb -> cmn . name , parent -> name , CONFIG_TASK_NAME_SIZE );
99
+ strlcpy (ptcb -> name , parent -> name , CONFIG_TASK_NAME_SIZE );
99
100
#endif /* CONFIG_TASK_NAME_SIZE */
100
101
101
102
/* For pthreads, args are strictly pass-by-value; that actual
102
103
* type wrapped by pthread_addr_t is unknown.
103
104
*/
104
105
105
- ptcb -> trampoline = trampoline ;
106
- ptcb -> arg = arg ;
106
+ entry = (FAR struct pthread_entry_s * )(ptcb + 1 );
107
+ entry -> trampoline = trampoline ;
108
+ entry -> arg = arg ;
107
109
}
108
110
109
111
/****************************************************************************
@@ -119,29 +121,31 @@ static inline void pthread_tcb_setup(FAR struct pthread_tcb_s *ptcb,
119
121
120
122
static void pthread_start (void )
121
123
{
122
- FAR struct pthread_tcb_s * ptcb = (FAR struct pthread_tcb_s * )this_task ();
124
+ FAR struct tcb_s * ptcb = this_task ();
125
+ FAR struct pthread_entry_s * entry =
126
+ (FAR struct pthread_entry_s * )(ptcb + 1 );
123
127
124
128
/* The priority of this thread may have been boosted to avoid priority
125
129
* inversion problems. If that is the case, then drop to the correct
126
130
* execution priority.
127
131
*/
128
132
129
- if (ptcb -> cmn . sched_priority > ptcb -> cmn . init_priority )
133
+ if (ptcb -> sched_priority > ptcb -> init_priority )
130
134
{
131
- DEBUGVERIFY (nxsched_set_priority (& ptcb -> cmn , ptcb -> cmn . init_priority ));
135
+ DEBUGVERIFY (nxsched_set_priority (ptcb , ptcb -> init_priority ));
132
136
}
133
137
134
138
/* Pass control to the thread entry point. In the kernel build this has to
135
139
* be handled differently if we are starting a user-space pthread; we have
136
140
* to switch to user-mode before calling into the pthread.
137
141
*/
138
142
139
- DEBUGASSERT (ptcb -> trampoline != NULL && ptcb -> cmn . entry .pthread != NULL );
143
+ DEBUGASSERT (entry -> trampoline != NULL && ptcb -> entry .pthread != NULL );
140
144
141
145
#ifdef CONFIG_BUILD_FLAT
142
- ptcb -> trampoline (ptcb -> cmn . entry .pthread , ptcb -> arg );
146
+ entry -> trampoline (ptcb -> entry .pthread , entry -> arg );
143
147
#else
144
- up_pthread_start (ptcb -> trampoline , ptcb -> cmn . entry .pthread , ptcb -> arg );
148
+ up_pthread_start (entry -> trampoline , ptcb -> entry .pthread , entry -> arg );
145
149
#endif
146
150
147
151
/* The thread has returned (should never happen) */
@@ -181,7 +185,7 @@ int nx_pthread_create(pthread_trampoline_t trampoline, FAR pthread_t *thread,
181
185
pthread_startroutine_t entry , pthread_addr_t arg )
182
186
{
183
187
pthread_attr_t default_attr = g_default_pthread_attr ;
184
- FAR struct pthread_tcb_s * ptcb ;
188
+ FAR struct tcb_s * ptcb ;
185
189
struct sched_param param ;
186
190
FAR struct tcb_s * parent ;
187
191
int policy ;
@@ -209,21 +213,21 @@ int nx_pthread_create(pthread_trampoline_t trampoline, FAR pthread_t *thread,
209
213
210
214
/* Allocate a TCB for the new task. */
211
215
212
- ptcb = kmm_zalloc (sizeof (struct pthread_tcb_s ));
216
+ ptcb = kmm_zalloc (sizeof (struct tcb_s ) + sizeof ( struct pthread_entry_s ));
213
217
if (!ptcb )
214
218
{
215
219
serr ("ERROR: Failed to allocate TCB\n" );
216
220
return ENOMEM ;
217
221
}
218
222
219
- ptcb -> cmn . flags |= TCB_FLAG_FREE_TCB ;
223
+ ptcb -> flags |= TCB_FLAG_FREE_TCB ;
220
224
221
225
/* Initialize the task join */
222
226
223
- nxtask_joininit (& ptcb -> cmn );
227
+ nxtask_joininit (ptcb );
224
228
225
229
#ifndef CONFIG_PTHREAD_MUTEX_UNSAFE
226
- spin_lock_init (& ptcb -> cmn . mutex_lock );
230
+ spin_lock_init (& ptcb -> mutex_lock );
227
231
#endif
228
232
229
233
/* Bind the parent's group to the new TCB (we have not yet joined the
@@ -235,7 +239,7 @@ int nx_pthread_create(pthread_trampoline_t trampoline, FAR pthread_t *thread,
235
239
#ifdef CONFIG_ARCH_ADDRENV
236
240
/* Share the address environment of the parent task group. */
237
241
238
- ret = addrenv_join (this_task (), ( FAR struct tcb_s * ) ptcb );
242
+ ret = addrenv_join (this_task (), ptcb );
239
243
if (ret < 0 )
240
244
{
241
245
errcode = - ret ;
@@ -245,22 +249,20 @@ int nx_pthread_create(pthread_trampoline_t trampoline, FAR pthread_t *thread,
245
249
246
250
if (attr -> detachstate == PTHREAD_CREATE_DETACHED )
247
251
{
248
- ptcb -> cmn . flags |= TCB_FLAG_DETACHED ;
252
+ ptcb -> flags |= TCB_FLAG_DETACHED ;
249
253
}
250
254
251
255
if (attr -> stackaddr )
252
256
{
253
257
/* Use pre-allocated stack */
254
258
255
- ret = up_use_stack ((FAR struct tcb_s * )ptcb , attr -> stackaddr ,
256
- attr -> stacksize );
259
+ ret = up_use_stack (ptcb , attr -> stackaddr , attr -> stacksize );
257
260
}
258
261
else
259
262
{
260
263
/* Allocate the stack for the TCB */
261
264
262
- ret = up_create_stack ((FAR struct tcb_s * )ptcb , attr -> stacksize ,
263
- TCB_FLAG_TTYPE_PTHREAD );
265
+ ret = up_create_stack (ptcb , attr -> stacksize , TCB_FLAG_TTYPE_PTHREAD );
264
266
}
265
267
266
268
if (ret != OK )
@@ -273,7 +275,7 @@ int nx_pthread_create(pthread_trampoline_t trampoline, FAR pthread_t *thread,
273
275
defined(CONFIG_BUILD_KERNEL ) && defined(CONFIG_ARCH_KERNEL_STACK )
274
276
/* Allocate the kernel stack */
275
277
276
- ret = up_addrenv_kstackalloc (& ptcb -> cmn );
278
+ ret = up_addrenv_kstackalloc (ptcb );
277
279
if (ret < 0 )
278
280
{
279
281
errcode = ENOMEM ;
@@ -283,7 +285,7 @@ int nx_pthread_create(pthread_trampoline_t trampoline, FAR pthread_t *thread,
283
285
284
286
/* Initialize thread local storage */
285
287
286
- ret = tls_init_info (& ptcb -> cmn );
288
+ ret = tls_init_info (ptcb );
287
289
if (ret != OK )
288
290
{
289
291
errcode = - ret ;
@@ -358,10 +360,10 @@ int nx_pthread_create(pthread_trampoline_t trampoline, FAR pthread_t *thread,
358
360
359
361
/* Initialize the sporadic policy */
360
362
361
- ret = nxsched_initialize_sporadic (& ptcb -> cmn );
363
+ ret = nxsched_initialize_sporadic (ptcb );
362
364
if (ret >= 0 )
363
365
{
364
- sporadic = ptcb -> cmn . sporadic ;
366
+ sporadic = ptcb -> sporadic ;
365
367
DEBUGASSERT (sporadic != NULL );
366
368
367
369
/* Save the sporadic scheduling parameters */
@@ -374,7 +376,7 @@ int nx_pthread_create(pthread_trampoline_t trampoline, FAR pthread_t *thread,
374
376
375
377
/* And start the first replenishment interval */
376
378
377
- ret = nxsched_start_sporadic (& ptcb -> cmn );
379
+ ret = nxsched_start_sporadic (ptcb );
378
380
}
379
381
380
382
/* Handle any failures */
@@ -407,7 +409,7 @@ int nx_pthread_create(pthread_trampoline_t trampoline, FAR pthread_t *thread,
407
409
408
410
if (attr -> affinity != 0 )
409
411
{
410
- ptcb -> cmn . affinity = attr -> affinity ;
412
+ ptcb -> affinity = attr -> affinity ;
411
413
}
412
414
#endif
413
415
@@ -423,25 +425,25 @@ int nx_pthread_create(pthread_trampoline_t trampoline, FAR pthread_t *thread,
423
425
424
426
/* Set the appropriate scheduling policy in the TCB */
425
427
426
- ptcb -> cmn . flags &= ~TCB_FLAG_POLICY_MASK ;
428
+ ptcb -> flags &= ~TCB_FLAG_POLICY_MASK ;
427
429
switch (policy )
428
430
{
429
431
default :
430
432
case SCHED_FIFO :
431
- ptcb -> cmn . flags |= TCB_FLAG_SCHED_FIFO ;
433
+ ptcb -> flags |= TCB_FLAG_SCHED_FIFO ;
432
434
break ;
433
435
434
436
#if CONFIG_RR_INTERVAL > 0
435
437
case SCHED_OTHER :
436
438
case SCHED_RR :
437
- ptcb -> cmn . flags |= TCB_FLAG_SCHED_RR ;
438
- ptcb -> cmn . timeslice = MSEC2TICK (CONFIG_RR_INTERVAL );
439
+ ptcb -> flags |= TCB_FLAG_SCHED_RR ;
440
+ ptcb -> timeslice = MSEC2TICK (CONFIG_RR_INTERVAL );
439
441
break ;
440
442
#endif
441
443
442
444
#ifdef CONFIG_SCHED_SPORADIC
443
445
case SCHED_SPORADIC :
444
- ptcb -> cmn . flags |= TCB_FLAG_SCHED_SPORADIC ;
446
+ ptcb -> flags |= TCB_FLAG_SCHED_SPORADIC ;
445
447
break ;
446
448
#endif
447
449
}
@@ -450,21 +452,21 @@ int nx_pthread_create(pthread_trampoline_t trampoline, FAR pthread_t *thread,
450
452
451
453
if (thread != NULL )
452
454
{
453
- * thread = (pthread_t )ptcb -> cmn . pid ;
455
+ * thread = (pthread_t )ptcb -> pid ;
454
456
}
455
457
456
458
/* Then activate the task */
457
459
458
- nxtask_activate (( FAR struct tcb_s * ) ptcb );
460
+ nxtask_activate (ptcb );
459
461
460
462
return OK ;
461
463
462
464
errout_with_tcb :
463
465
464
466
/* Since we do not join the group, assign group to NULL to clear binding */
465
467
466
- ptcb -> cmn . group = NULL ;
468
+ ptcb -> group = NULL ;
467
469
468
- nxsched_release_tcb (( FAR struct tcb_s * ) ptcb , TCB_FLAG_TTYPE_PTHREAD );
470
+ nxsched_release_tcb (ptcb , TCB_FLAG_TTYPE_PTHREAD );
469
471
return errcode ;
470
472
}
0 commit comments