source: rtems/cpukit/posix/src/pthreadinitthreads.c @ 1d572eba

5
Last change on this file since 1d572eba was 3a659b04, checked in by Sebastian Huber <sebastian.huber@…>, on 12/09/16 at 06:19:22

score: Introduce _Internal_error()

  • Property mode set to 100644
File size: 2.9 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/stack.h>
28#include <rtems/score/thread.h>
29#include <rtems/score/wkspace.h>
30#include <rtems/posix/posixapi.h>
31#include <rtems/posix/pthreadimpl.h>
32#include <rtems/posix/priorityimpl.h>
33#include <rtems/posix/config.h>
34#include <rtems/rtems/config.h>
35
36static void *_POSIX_Global_construction( void *arg )
37{
38  Thread_Control           *executing = _Thread_Get_executing();
39  Thread_Entry_information  entry = executing->Start.Entry;
40
41  entry.Kinds.Pointer.entry = Configuration_POSIX_API
42    .User_initialization_threads_table[ 0 ].thread_entry;
43
44  (void) arg;
45  _Thread_Global_construction( executing, &entry );
46}
47
48void _POSIX_Threads_Initialize_user_threads_body(void)
49{
50  int                                 eno;
51  uint32_t                            index;
52  uint32_t                            maximum;
53  posix_initialization_threads_table *user_threads;
54  pthread_t                           thread_id;
55  pthread_attr_t                      attr;
56  bool                                register_global_construction;
57  void                             *(*thread_entry)(void *);
58
59  user_threads = Configuration_POSIX_API.User_initialization_threads_table;
60  maximum      = Configuration_POSIX_API.number_of_initialization_threads;
61
62  if ( !user_threads )
63    return;
64
65  register_global_construction =
66    Configuration_RTEMS_API.number_of_initialization_tasks == 0;
67
68  /*
69   *  Be careful .. if the default attribute set changes, this may need to.
70   *
71   *  Setting the attributes explicitly is critical, since we don't want
72   *  to inherit the idle tasks attributes.
73   */
74
75  for ( index=0 ; index < maximum ; index++ ) {
76    /*
77     * There is no way for these calls to fail in this situation.
78     */
79    eno = pthread_attr_init( &attr );
80    _Assert( eno == 0 );
81    eno = pthread_attr_setinheritsched( &attr, PTHREAD_EXPLICIT_SCHED );
82    _Assert( eno == 0 );
83    eno = pthread_attr_setstacksize(&attr, user_threads[ index ].stack_size);
84    _Assert( eno == 0 );
85
86    thread_entry = user_threads[ index ].thread_entry;
87    if ( thread_entry == NULL ) {
88      _Internal_error( INTERNAL_ERROR_POSIX_INIT_THREAD_ENTRY_IS_NULL );
89    }
90
91    if ( register_global_construction ) {
92      register_global_construction = false;
93      thread_entry = _POSIX_Global_construction;
94    }
95
96    eno = pthread_create(
97      &thread_id,
98      &attr,
99      thread_entry,
100      NULL
101    );
102    if ( eno != 0 ) {
103      _Internal_error( INTERNAL_ERROR_POSIX_INIT_THREAD_CREATE_FAILED );
104    }
105  }
106}
Note: See TracBrowser for help on using the repository browser.