Filesystem: Thread life protection for env changes

This commit is contained in:
Sebastian Huber
2015-05-19 12:00:44 +02:00
parent 4a3c920d30
commit 776a50c47a
+10 -10
View File
@@ -23,7 +23,7 @@
#include <stdlib.h>
#include <rtems/libio_.h>
#include <rtems/score/threaddispatch.h>
#include <rtems/score/threadimpl.h>
/**
* Instantiate a private user environment for the calling thread.
@@ -50,13 +50,6 @@ void rtems_libio_free_user_env(void *arg)
}
}
static void free_user_env_protected(rtems_user_env_t *env)
{
_Thread_Disable_dispatch();
rtems_libio_free_user_env(env);
_Thread_Enable_dispatch();
}
rtems_status_code rtems_libio_set_private_env(void)
{
rtems_status_code sc = RTEMS_SUCCESSFUL;
@@ -64,6 +57,7 @@ rtems_status_code rtems_libio_set_private_env(void)
bool uses_global_env = old_env == &rtems_global_user_env;
if (uses_global_env) {
bool life_protection = _Thread_Set_life_protection(true);
rtems_user_env_t *new_env = calloc(1, sizeof(*new_env));
if (new_env != NULL) {
@@ -83,7 +77,7 @@ rtems_status_code rtems_libio_set_private_env(void)
);
if (eno == 0) {
free_user_env_protected(old_env);
rtems_libio_free_user_env(old_env);
} else {
sc = RTEMS_TOO_MANY;
}
@@ -97,6 +91,8 @@ rtems_status_code rtems_libio_set_private_env(void)
} else {
sc = RTEMS_NO_MEMORY;
}
_Thread_Set_life_protection(life_protection);
}
return sc;
@@ -108,7 +104,11 @@ void rtems_libio_use_global_env(void)
bool uses_private_env = env != &rtems_global_user_env;
if (uses_private_env) {
free_user_env_protected(env);
bool life_protection = _Thread_Set_life_protection(true);
rtems_libio_free_user_env(env);
pthread_setspecific(rtems_current_user_env_key, NULL);
_Thread_Set_life_protection(life_protection);
}
}