source: rtems/cpukit/posix/src/pthreadinitthreads.c @ fe100e16

5
Last change on this file since fe100e16 was fe100e16, checked in by Sebastian Huber <sebastian.huber@…>, on 12/22/15 at 08:13:08

score: Add fatal errors for NULL entry init tasks

This simplifies the global construction.

Update #2514.

  • Property mode set to 100644
File size: 2.7 KB
Line 
1/**
2 * @file
3 *
4 * @brief POSIX Threads Initialize User Threads Body
5 * @ingroup POSIX_PTHREAD
6 */
7
8/*
9 *  COPYRIGHT (c) 1989-2008.
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 <errno.h>
22#include <pthread.h>
23#include <limits.h>
24
25#include <rtems/system.h>
26#include <rtems/config.h>
27#include <rtems/score/apiext.h>
28#include <rtems/score/stack.h>
29#include <rtems/score/thread.h>
30#include <rtems/score/wkspace.h>
31#include <rtems/posix/cancel.h>
32#include <rtems/posix/posixapi.h>
33#include <rtems/posix/pthreadimpl.h>
34#include <rtems/posix/priorityimpl.h>
35#include <rtems/posix/config.h>
36#include <rtems/rtems/config.h>
37
38void _POSIX_Threads_Initialize_user_threads_body(void)
39{
40  int                                 eno;
41  uint32_t                            index;
42  uint32_t                            maximum;
43  posix_initialization_threads_table *user_threads;
44  pthread_t                           thread_id;
45  pthread_attr_t                      attr;
46  bool                                register_global_construction;
47  void                             *(*thread_entry)(void *);
48
49  user_threads = Configuration_POSIX_API.User_initialization_threads_table;
50  maximum      = Configuration_POSIX_API.number_of_initialization_threads;
51
52  if ( !user_threads )
53    return;
54
55  register_global_construction =
56    Configuration_RTEMS_API.number_of_initialization_tasks == 0;
57
58  /*
59   *  Be careful .. if the default attribute set changes, this may need to.
60   *
61   *  Setting the attributes explicitly is critical, since we don't want
62   *  to inherit the idle tasks attributes.
63   */
64
65  for ( index=0 ; index < maximum ; index++ ) {
66    /*
67     * There is no way for these calls to fail in this situation.
68     */
69    eno = pthread_attr_init( &attr );
70    _Assert( eno == 0 );
71    eno = pthread_attr_setinheritsched( &attr, PTHREAD_EXPLICIT_SCHED );
72    _Assert( eno == 0 );
73    eno = pthread_attr_setstacksize(&attr, user_threads[ index ].stack_size);
74    _Assert( eno == 0 );
75
76    thread_entry = user_threads[ index ].thread_entry;
77    if ( thread_entry == NULL ) {
78      _Terminate(
79        INTERNAL_ERROR_CORE,
80        false,
81        INTERNAL_ERROR_POSIX_INIT_THREAD_ENTRY_IS_NULL
82      );
83    }
84
85    if ( register_global_construction ) {
86      register_global_construction = false;
87      thread_entry = (void *(*)(void *)) _Thread_Global_construction;
88    }
89
90    eno = pthread_create(
91      &thread_id,
92      &attr,
93      thread_entry,
94      NULL
95    );
96    if ( eno )
97      _POSIX_Fatal_error( POSIX_FD_PTHREAD, eno );
98  }
99}
Note: See TracBrowser for help on using the repository browser.