source: rtems/cpukit/libcsupport/src/libio_init.c @ e22af78

4.115
Last change on this file since e22af78 was 5c0c0cf, checked in by Christian Mauderer <Christian.Mauderer@…>, on 03/27/14 at 13:23:21

privateenv: Use POSIX keys instead of task variables.

  • Property mode set to 100644
File size: 2.3 KB
Line 
1/**
2 *  @file
3 *
4 *  @brief RTEMS LibIO Initialization
5 *  @ingroup LibIO
6 */
7
8/*
9 *  COPYRIGHT (c) 1989-2010.
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 <rtems/libio_.h>               /* libio_.h pulls in rtems */
22#include <rtems.h>
23#include <rtems/assoc.h>                /* assoc.h not included by rtems.h */
24
25#include <stdio.h>                      /* O_RDONLY, et.al. */
26#include <fcntl.h>                      /* O_RDONLY, et.al. */
27#include <errno.h>
28
29#include <errno.h>
30#include <string.h>                     /* strcmp */
31#include <unistd.h>
32#include <stdlib.h>                     /* calloc() */
33
34#include <rtems/libio.h>                /* libio.h not pulled in by rtems */
35
36/*
37 *  File descriptor Table Information
38 */
39
40rtems_id           rtems_libio_semaphore;
41rtems_libio_t     *rtems_libio_iops;
42rtems_libio_t     *rtems_libio_iop_freelist;
43
44void rtems_libio_init( void )
45{
46    rtems_status_code rc;
47    uint32_t i;
48    rtems_libio_t *iop;
49    int eno;
50
51    if (rtems_libio_number_iops > 0)
52    {
53        rtems_libio_iops = (rtems_libio_t *) calloc(rtems_libio_number_iops,
54                                                    sizeof(rtems_libio_t));
55        if (rtems_libio_iops == NULL)
56            rtems_fatal_error_occurred(RTEMS_NO_MEMORY);
57
58        iop = rtems_libio_iop_freelist = rtems_libio_iops;
59        for (i = 0 ; (i + 1) < rtems_libio_number_iops ; i++, iop++)
60          iop->data1 = iop + 1;
61        iop->data1 = NULL;
62    }
63
64  /*
65   *  Create the posix key for user environment.
66   */
67  eno = pthread_key_create(
68    &rtems_current_user_env_key,
69    rtems_libio_free_user_env
70  );
71  if (eno != 0) {
72    rtems_fatal_error_occurred( RTEMS_UNSATISFIED );
73  }
74
75  /*
76   *  Create the binary semaphore used to provide mutual exclusion
77   *  on the IOP Table.
78   */
79
80  rc = rtems_semaphore_create(
81    RTEMS_LIBIO_SEM,
82    1,
83    RTEMS_BINARY_SEMAPHORE | RTEMS_INHERIT_PRIORITY | RTEMS_PRIORITY,
84    RTEMS_NO_PRIORITY,
85    &rtems_libio_semaphore
86  );
87  if ( rc != RTEMS_SUCCESSFUL )
88    rtems_fatal_error_occurred( rc );
89
90  /*
91   *  Initialize the base file system infrastructure.
92   */
93  (* rtems_fs_init_helper)();
94}
Note: See TracBrowser for help on using the repository browser.