Changeset 5c0c0cf in rtems


Ignore:
Timestamp:
Mar 27, 2014, 1:23:21 PM (6 years ago)
Author:
Christian Mauderer <Christian.Mauderer@…>
Branches:
4.11, master
Children:
0cd2b777
Parents:
7d5c27e
git-author:
Christian Mauderer <Christian.Mauderer@…> (03/27/14 13:23:21)
git-committer:
Sebastian Huber <sebastian.huber@…> (03/27/14 13:50:36)
Message:

privateenv: Use POSIX keys instead of task variables.

Files:
4 added
18 edited

Legend:

Unmodified
Added
Removed
  • cpukit/include/rtems/userenv.h

    r7d5c27e r5c0c0cf  
    6767} rtems_user_env_t;
    6868
    69 extern rtems_user_env_t * rtems_current_user_env;
    70 extern rtems_user_env_t   rtems_global_user_env;
     69extern rtems_user_env_t rtems_global_user_env;
     70
     71/**
     72 * @brief Fetch the pointer to the current user environment.
     73 *
     74 * If the task has a private user environment the pointer to it will be
     75 * returned. Otherwise the pointer to rtems_global_user_env will be returned.
     76 */
     77rtems_user_env_t * rtems_current_user_env_get(void);
     78
     79#define rtems_current_user_env rtems_current_user_env_get()
    7180
    7281#define rtems_filesystem_current     (rtems_current_user_env->current_directory)
     
    8695 * function must be called from normal thread context and may block on a mutex.
    8796 * Thread dispatching is disabled to protect some critical sections.
     97 *
     98 * The private environment internally uses a POSIX key. The key is added to the
     99 * configuration implicitly. But for each thread that uses a private environment
     100 * a key value pair has to be configured by the application. If only the global
     101 * environment is used there is no need to configure a key value pair.
    88102 *
    89103 * @retval RTEMS_SUCCESSFUL Successful operation.
  • cpukit/libcsupport/include/rtems/libio_.h

    r7d5c27e r5c0c0cf  
    2525#include <errno.h>
    2626#include <limits.h>
     27#include <pthread.h>
    2728
    2829#include <rtems.h>
     
    238239 */
    239240#include <rtems/userenv.h>
     241
     242void rtems_libio_free_user_env( void *env );
     243
     244extern pthread_key_t rtems_current_user_env_key;
    240245
    241246static inline void rtems_libio_lock( void )
  • cpukit/libcsupport/src/__usrenv.c

    r7d5c27e r5c0c0cf  
    258258};
    259259
    260 rtems_user_env_t *rtems_current_user_env = &rtems_global_user_env;
     260pthread_key_t rtems_current_user_env_key;
  • cpukit/libcsupport/src/libio_init.c

    r7d5c27e r5c0c0cf  
    4747    uint32_t i;
    4848    rtems_libio_t *iop;
     49    int eno;
    4950
    5051    if (rtems_libio_number_iops > 0)
     
    6061        iop->data1 = NULL;
    6162    }
     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  }
    6274
    6375  /*
  • cpukit/libcsupport/src/privateenv.c

    r7d5c27e r5c0c0cf  
    3030 */
    3131
    32 static void free_user_env(void *arg)
     32rtems_user_env_t * rtems_current_user_env_get(void)
     33{
     34  void *ptr = pthread_getspecific(rtems_current_user_env_key);
     35  if (ptr == NULL) {
     36    ptr = &rtems_global_user_env;
     37  }
     38  return (rtems_user_env_t *) ptr;
     39}
     40
     41void rtems_libio_free_user_env(void *arg)
    3342{
    3443  rtems_user_env_t *env = arg;
     
    4554{
    4655  _Thread_Disable_dispatch();
    47   free_user_env(env);
     56  rtems_libio_free_user_env(env);
    4857  _Thread_Enable_dispatch();
    4958}
     
    6978          && !rtems_filesystem_global_location_is_null(new_env->current_directory)
    7079      ) {
    71         sc = rtems_task_variable_add(
    72           RTEMS_SELF,
    73           (void **) &rtems_current_user_env,
    74           free_user_env
     80        int eno = pthread_setspecific(
     81          rtems_current_user_env_key,
     82          new_env
    7583        );
    76         if (sc == RTEMS_SUCCESSFUL) {
     84
     85        if (eno == 0) {
    7786          free_user_env_protected(old_env);
    78           rtems_current_user_env = new_env;
    7987        } else {
    8088          sc = RTEMS_TOO_MANY;
     
    8593
    8694      if (sc != RTEMS_SUCCESSFUL) {
    87         free_user_env(new_env);
     95        rtems_libio_free_user_env(new_env);
    8896      }
    8997    } else {
     
    102110
    103111  if (uses_private_env) {
    104     sc = rtems_task_variable_delete(
    105       RTEMS_SELF,
    106       (void **) &rtems_current_user_env
    107     );
    108     if (sc != RTEMS_SUCCESSFUL) {
    109       rtems_fatal_error_occurred(0xdeadbeef);
    110     }
    111 
    112     rtems_current_user_env = &rtems_global_user_env;
     112    free_user_env_protected(env);
     113    pthread_setspecific(rtems_current_user_env_key, NULL);
    113114  }
    114115}
  • cpukit/sapi/include/confdefs.h

    r7d5c27e r5c0c0cf  
    148148 */
    149149#define CONFIGURE_LIBIO_SEMAPHORES 1
     150
     151/**
     152 * POSIX key count used by the IO library.
     153 */
     154#define CONFIGURE_LIBIO_POSIX_KEYS 1
    150155
    151156#ifdef CONFIGURE_INIT
     
    17351740
    17361741#ifndef CONFIGURE_MAXIMUM_POSIX_KEYS
    1737   #define CONFIGURE_MAXIMUM_POSIX_KEYS            0
    1738   #define CONFIGURE_MAXIMUM_POSIX_KEY_VALUE_PAIRS 0
    1739 #else
    1740   #ifndef CONFIGURE_MAXIMUM_POSIX_KEY_VALUE_PAIRS
    1741     #define CONFIGURE_MAXIMUM_POSIX_KEY_VALUE_PAIRS \
    1742       (CONFIGURE_MAXIMUM_POSIX_KEYS * \
    1743        (CONFIGURE_MAXIMUM_POSIX_THREADS + CONFIGURE_MAXIMUM_TASKS))
    1744   #endif
    1745 #endif
     1742  #define CONFIGURE_MAXIMUM_POSIX_KEYS 0
     1743#endif
     1744
     1745#ifndef CONFIGURE_MAXIMUM_POSIX_KEY_VALUE_PAIRS
     1746  #define CONFIGURE_MAXIMUM_POSIX_KEY_VALUE_PAIRS \
     1747    (CONFIGURE_MAXIMUM_POSIX_KEYS * \
     1748     (CONFIGURE_MAXIMUM_POSIX_THREADS + CONFIGURE_MAXIMUM_TASKS))
     1749#endif
     1750
     1751#define CONFIGURE_POSIX_KEYS \
     1752  (CONFIGURE_MAXIMUM_POSIX_KEYS + CONFIGURE_LIBIO_POSIX_KEYS)
    17461753
    17471754#define CONFIGURE_MEMORY_FOR_POSIX_KEYS(_keys, _key_value_pairs) \
     
    22232230   CONFIGURE_MEMORY_FOR_CLASSIC + \
    22242231   CONFIGURE_MEMORY_FOR_POSIX_KEYS( \
    2225       CONFIGURE_MAXIMUM_POSIX_KEYS, \
     2232      CONFIGURE_POSIX_KEYS, \
    22262233      CONFIGURE_MAXIMUM_POSIX_KEY_VALUE_PAIRS ) + \
    22272234   CONFIGURE_MEMORY_FOR_POSIX + \
     
    23982405    CONFIGURE_STACK_SPACE_SIZE,               /* required stack space */
    23992406    CONFIGURE_MAXIMUM_USER_EXTENSIONS,        /* maximum dynamic extensions */
    2400     CONFIGURE_MAXIMUM_POSIX_KEYS,             /* POSIX keys are always */
     2407    CONFIGURE_POSIX_KEYS,                     /* POSIX keys are always */
    24012408    CONFIGURE_MAXIMUM_POSIX_KEY_VALUE_PAIRS,  /*   enabled */
    24022409    CONFIGURE_MICROSECONDS_PER_TICK,          /* microseconds per clock tick */
     
    25932600    CONFIGURE_MEMORY_FOR_BARRIERS(CONFIGURE_BARRIERS),
    25942601    CONFIGURE_MEMORY_FOR_USER_EXTENSIONS(CONFIGURE_MAXIMUM_USER_EXTENSIONS),
    2595     CONFIGURE_MEMORY_FOR_POSIX_KEYS( CONFIGURE_MAXIMUM_POSIX_KEYS, \
     2602    CONFIGURE_MEMORY_FOR_POSIX_KEYS( CONFIGURE_POSIX_KEYS, \
    25962603                                     CONFIGURE_MAXIMUM_POSIX_KEY_VALUE_PAIRS ),
    25972604
  • doc/shell/file.t

    r7d5c27e r5c0c0cf  
    11491149When building a custom command set, define
    11501150@code{CONFIGURE_SHELL_COMMAND_CHROOT} to have this
    1151 command included.
     1151command included. Additional to that you have to add one
     1152POSIX key value pair for each thread where you want to use
     1153the command.
    11521154
    11531155This command can be excluded from the shell command set by
  • testsuites/fstests/imfs_support/fs_support.c

    r7d5c27e r5c0c0cf  
    4242#define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS 40
    4343#define CONFIGURE_INIT_TASK_STACK_SIZE (16 * 1024)
     44#define CONFIGURE_MAXIMUM_POSIX_KEY_VALUE_PAIRS  1
    4445
    4546#define CONFIGURE_INIT
  • testsuites/fstests/jffs2_support/fs_support.c

    r7d5c27e r5c0c0cf  
    158158#define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
    159159
     160#define CONFIGURE_MAXIMUM_POSIX_KEY_VALUE_PAIRS 1
     161
    160162#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
    161163
  • testsuites/fstests/mdosfs_support/fs_support.c

    r7d5c27e r5c0c0cf  
    9292#define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS    40
    9393#define CONFIGURE_INIT_TASK_STACK_SIZE (16 * 1024)
     94#define CONFIGURE_MAXIMUM_POSIX_KEY_VALUE_PAIRS     1
    9495
    9596#define CONFIGURE_APPLICATION_NEEDS_LIBBLOCK
  • testsuites/fstests/mimfs_support/fs_support.c

    r7d5c27e r5c0c0cf  
    5757#define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS 40
    5858#define CONFIGURE_INIT_TASK_STACK_SIZE (16 * 1024)
     59#define CONFIGURE_MAXIMUM_POSIX_KEY_VALUE_PAIRS  1
    5960
    6061#define CONFIGURE_INIT
  • testsuites/fstests/mrfs_support/fs_support.c

    r7d5c27e r5c0c0cf  
    7171#define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS    40
    7272#define CONFIGURE_INIT_TASK_STACK_SIZE (32 * 1024)
     73#define CONFIGURE_MAXIMUM_POSIX_KEY_VALUE_PAIRS     1
    7374
    7475#define CONFIGURE_APPLICATION_NEEDS_LIBBLOCK
  • testsuites/libtests/ftp01/init.c

    r7d5c27e r5c0c0cf  
    247247#define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
    248248
     249#define CONFIGURE_MAXIMUM_POSIX_KEY_VALUE_PAIRS 2
     250
    249251#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
    250252
  • testsuites/psxtests/psxchroot01/main.c

    r7d5c27e r5c0c0cf  
    3535#define CONFIGURE_MAXIMUM_TASKS 1
    3636
     37#define CONFIGURE_MAXIMUM_POSIX_KEY_VALUE_PAIRS 1
     38
    3739#define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
    3840
  • testsuites/psxtests/psxmount/main.c

    r7d5c27e r5c0c0cf  
    3737#define CONFIGURE_MAXIMUM_TASKS 1
    3838
     39#define CONFIGURE_MAXIMUM_POSIX_KEY_VALUE_PAIRS 1
     40
    3941#define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
    4042
  • testsuites/sptests/Makefile.am

    r7d5c27e r5c0c0cf  
    1919    spfatal08 spfatal09 spfatal10 spfatal11 spfatal12 spfatal13 spfatal14 \
    2020    spfatal15 spfatal16 spfatal17 spfatal18 spfatal19 spfatal20 \
    21     spfatal22 spfatal24 spfatal25 \
     21    spfatal22 spfatal24 spfatal25 spfatal27\
    2222    spfifo01 spfifo02 spfifo03 spfifo04 spfifo05 \
    2323    spfreechain01 \
  • testsuites/sptests/configure.ac

    r7d5c27e r5c0c0cf  
    167167spfatal24/Makefile
    168168spfatal25/Makefile
     169spfatal27/Makefile
    169170spfifo01/Makefile
    170171spfifo02/Makefile
  • testsuites/sptests/spprivenv01/init.c

    r7d5c27e r5c0c0cf  
    6464  puts( "Init - allocating most of workspace memory" );
    6565  opaque = rtems_workspace_greedy_allocate( NULL, 0 );
    66  
    67   puts( "Init - attempt to reset env - expect RTEMS_TOO_MANY" );
     66
     67  puts( "Init - attempt to reset env - expect RTEMS_SUCCESSFUL" );
    6868  sc = rtems_libio_set_private_env();
    69   rtems_test_assert( sc == RTEMS_TOO_MANY );
     69  rtems_test_assert( sc == RTEMS_SUCCESSFUL );
     70  rtems_test_assert( rtems_current_user_env != &rtems_global_user_env );
    7071
    7172  puts( "Init - freeing the workspace memory" );
    7273  rtems_workspace_greedy_free( opaque );
     74
     75  puts( "Init - Reset to global environment" );
     76  rtems_libio_use_global_env();
     77  rtems_test_assert( rtems_current_user_env == &rtems_global_user_env );
    7378
    7479  puts( "Init - Attempt to get a private environment" );
     
    119124#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
    120125
     126#define CONFIGURE_MAXIMUM_POSIX_KEYS 1
     127#define CONFIGURE_MAXIMUM_POSIX_KEY_VALUE_PAIRS 2
     128
    121129#define CONFIGURE_INIT
    122130
Note: See TracChangeset for help on using the changeset viewer.