summaryrefslogtreecommitdiffstats
path: root/cpukit/libcsupport/src
diff options
context:
space:
mode:
authorChristian Mauderer <Christian.Mauderer@embedded-brains.de>2014-03-27 14:23:21 +0100
committerSebastian Huber <sebastian.huber@embedded-brains.de>2014-03-27 14:50:36 +0100
commit5c0c0cf2a6a9e3fdbcd1ada3f79399c453b1fbd1 (patch)
treedba573cb48c77127b711bdce1f94816025fdf942 /cpukit/libcsupport/src
parentprivateenv: Remove sharing of user environment between threads. (diff)
downloadrtems-5c0c0cf2a6a9e3fdbcd1ada3f79399c453b1fbd1.tar.bz2
privateenv: Use POSIX keys instead of task variables.
Diffstat (limited to 'cpukit/libcsupport/src')
-rw-r--r--cpukit/libcsupport/src/__usrenv.c2
-rw-r--r--cpukit/libcsupport/src/libio_init.c12
-rw-r--r--cpukit/libcsupport/src/privateenv.c37
3 files changed, 32 insertions, 19 deletions
diff --git a/cpukit/libcsupport/src/__usrenv.c b/cpukit/libcsupport/src/__usrenv.c
index 3ce6a2dfea..71efda9d7f 100644
--- a/cpukit/libcsupport/src/__usrenv.c
+++ b/cpukit/libcsupport/src/__usrenv.c
@@ -257,4 +257,4 @@ rtems_user_env_t rtems_global_user_env = {
.umask = S_IWGRP | S_IWOTH
};
-rtems_user_env_t *rtems_current_user_env = &rtems_global_user_env;
+pthread_key_t rtems_current_user_env_key;
diff --git a/cpukit/libcsupport/src/libio_init.c b/cpukit/libcsupport/src/libio_init.c
index 4d705fb8ee..e64ddd6e3a 100644
--- a/cpukit/libcsupport/src/libio_init.c
+++ b/cpukit/libcsupport/src/libio_init.c
@@ -46,6 +46,7 @@ void rtems_libio_init( void )
rtems_status_code rc;
uint32_t i;
rtems_libio_t *iop;
+ int eno;
if (rtems_libio_number_iops > 0)
{
@@ -61,6 +62,17 @@ void rtems_libio_init( void )
}
/*
+ * Create the posix key for user environment.
+ */
+ eno = pthread_key_create(
+ &rtems_current_user_env_key,
+ rtems_libio_free_user_env
+ );
+ if (eno != 0) {
+ rtems_fatal_error_occurred( RTEMS_UNSATISFIED );
+ }
+
+ /*
* Create the binary semaphore used to provide mutual exclusion
* on the IOP Table.
*/
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);
}
}