diff options
author | Christian Mauderer <Christian.Mauderer@embedded-brains.de> | 2014-03-27 14:23:21 +0100 |
---|---|---|
committer | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2014-03-27 14:50:36 +0100 |
commit | 5c0c0cf2a6a9e3fdbcd1ada3f79399c453b1fbd1 (patch) | |
tree | dba573cb48c77127b711bdce1f94816025fdf942 /cpukit/libcsupport/src/privateenv.c | |
parent | privateenv: Remove sharing of user environment between threads. (diff) | |
download | rtems-5c0c0cf2a6a9e3fdbcd1ada3f79399c453b1fbd1.tar.bz2 |
privateenv: Use POSIX keys instead of task variables.
Diffstat (limited to 'cpukit/libcsupport/src/privateenv.c')
-rw-r--r-- | cpukit/libcsupport/src/privateenv.c | 37 |
1 files changed, 19 insertions, 18 deletions
diff --git a/cpukit/libcsupport/src/privateenv.c b/cpukit/libcsupport/src/privateenv.c index bee94c117f..60207b0815 100644 --- a/cpukit/libcsupport/src/privateenv.c +++ b/cpukit/libcsupport/src/privateenv.c @@ -29,7 +29,16 @@ * Instantiate a private user environment for the calling thread. */ -static void free_user_env(void *arg) +rtems_user_env_t * rtems_current_user_env_get(void) +{ + void *ptr = pthread_getspecific(rtems_current_user_env_key); + if (ptr == NULL) { + ptr = &rtems_global_user_env; + } + return (rtems_user_env_t *) ptr; +} + +void rtems_libio_free_user_env(void *arg) { rtems_user_env_t *env = arg; bool uses_global_env = env == &rtems_global_user_env; @@ -44,7 +53,7 @@ static void free_user_env(void *arg) static void free_user_env_protected(rtems_user_env_t *env) { _Thread_Disable_dispatch(); - free_user_env(env); + rtems_libio_free_user_env(env); _Thread_Enable_dispatch(); } @@ -68,14 +77,13 @@ rtems_status_code rtems_libio_set_private_env(void) !rtems_filesystem_global_location_is_null(new_env->root_directory) && !rtems_filesystem_global_location_is_null(new_env->current_directory) ) { - sc = rtems_task_variable_add( - RTEMS_SELF, - (void **) &rtems_current_user_env, - free_user_env + int eno = pthread_setspecific( + rtems_current_user_env_key, + new_env ); - if (sc == RTEMS_SUCCESSFUL) { + + if (eno == 0) { free_user_env_protected(old_env); - rtems_current_user_env = new_env; } else { sc = RTEMS_TOO_MANY; } @@ -84,7 +92,7 @@ rtems_status_code rtems_libio_set_private_env(void) } if (sc != RTEMS_SUCCESSFUL) { - free_user_env(new_env); + rtems_libio_free_user_env(new_env); } } else { sc = RTEMS_NO_MEMORY; @@ -101,14 +109,7 @@ void rtems_libio_use_global_env(void) bool uses_private_env = env != &rtems_global_user_env; if (uses_private_env) { - sc = rtems_task_variable_delete( - RTEMS_SELF, - (void **) &rtems_current_user_env - ); - if (sc != RTEMS_SUCCESSFUL) { - rtems_fatal_error_occurred(0xdeadbeef); - } - - rtems_current_user_env = &rtems_global_user_env; + free_user_env_protected(env); + pthread_setspecific(rtems_current_user_env_key, NULL); } } |