source: rtems/cpukit/posix/src/pthreadinitthreads.c @ 0e16fa45

5
Last change on this file since 0e16fa45 was e97806a, checked in by Sebastian Huber <sebastian.huber@…>, on 10/14/18 at 17:20:05

posix: Split posix_api_configuration_table

Use separate configuration variables to avoid false dependencies.

Update #2514.

  • Property mode set to 100644
File size: 2.1 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
35void _POSIX_Threads_Initialize_user_threads_body(void)
36{
37  int                                 eno;
38  uint32_t                            index;
39  uint32_t                            maximum;
40  posix_initialization_threads_table *user_threads;
41  pthread_t                           thread_id;
42  pthread_attr_t                      attr;
43
44  user_threads = _Configuration_POSIX_Initialization_threads;
45  maximum      = _Configuration_POSIX_Initialization_thread_count;
46
47  if ( !user_threads )
48    return;
49
50  /*
51   *  Be careful .. if the default attribute set changes, this may need to.
52   *
53   *  Setting the attributes explicitly is critical, since we don't want
54   *  to inherit the idle tasks attributes.
55   */
56
57  for ( index=0 ; index < maximum ; index++ ) {
58    /*
59     * There is no way for these calls to fail in this situation.
60     */
61    eno = pthread_attr_init( &attr );
62    _Assert( eno == 0 );
63    eno = pthread_attr_setinheritsched( &attr, PTHREAD_EXPLICIT_SCHED );
64    _Assert( eno == 0 );
65    eno = pthread_attr_setstacksize(&attr, user_threads[ index ].stack_size);
66    _Assert( eno == 0 );
67
68    eno = pthread_create(
69      &thread_id,
70      &attr,
71      user_threads[ index ].thread_entry,
72      NULL
73    );
74    if ( eno != 0 ) {
75      _Internal_error( INTERNAL_ERROR_POSIX_INIT_THREAD_CREATE_FAILED );
76    }
77
78    if ( _Thread_Global_constructor == 0 ) {
79      _Thread_Global_constructor = thread_id;
80    }
81  }
82}
Note: See TracBrowser for help on using the repository browser.