[PATCH 1/2] privateenv: Remove sharing of user environment between threads.
Gedare Bloom
gedare at rtems.org
Wed Mar 26 15:15:16 UTC 2014
Quick glance looks OK, but I leave it up to Sebastian or Chris to approve.
On Wed, Mar 26, 2014 at 8:29 AM, Christian Mauderer
<christian.mauderer at embedded-brains.de> wrote:
> From: Christian Mauderer <Christian.Mauderer at embedded-brains.de>
>
> ---
> cpukit/include/rtems/userenv.h | 20 ---------
> cpukit/libcsupport/src/privateenv.c | 60 ++------------------------
> testsuites/fstests/fsnofs01/fsnofs01.doc | 1 -
> testsuites/fstests/fsnofs01/init.c | 12 ------
> testsuites/sptests/spprivenv01/init.c | 40 +++++++----------
> testsuites/sptests/spprivenv01/spprivenv01.doc | 5 +--
> testsuites/sptests/spprivenv01/spprivenv01.scn | 15 +++----
> 7 files changed, 27 insertions(+), 126 deletions(-)
>
> diff --git a/cpukit/include/rtems/userenv.h b/cpukit/include/rtems/userenv.h
> index 7d874d3..8a9a4fc 100644
> --- a/cpukit/include/rtems/userenv.h
> +++ b/cpukit/include/rtems/userenv.h
> @@ -64,9 +64,6 @@ typedef struct {
> gid_t egid;
> char login_buffer[LOGIN_NAME_MAX];
> pid_t pgrp; /* process group id */
> - /* User environment maintenance */
> - rtems_id task_id;
> - int reference_count;
> } rtems_user_env_t;
>
> extern rtems_user_env_t * rtems_current_user_env;
> @@ -97,23 +94,6 @@ extern rtems_user_env_t rtems_global_user_env;
> rtems_status_code rtems_libio_set_private_env(void);
>
> /**
> - * @brief Creates a private environment shared with another task.
> - *
> - * An attempt to share the environment with itself has no effect. This
> - * function must be called from normal thread context and may block on a mutex.
> - * Thread dispatching is disabled to protect some critical sections.
> - *
> - * @param[in] task_id The private environment is shared with the task specified
> - * by this identifier.
> - *
> - * @retval RTEMS_SUCCESSFUL Successful operation.
> - * @retval RTEMS_UNSATISFIED No shared environment is available for this task
> - * @retval RTEMS_TOO_MANY Cannot register the shared environment.
> - * identifier.
> - */
> -rtems_status_code rtems_libio_share_private_env(rtems_id task_id) ;
> -
> -/**
> * @brief Use the global environment.
> *
> * A private environment will be released. This function may be called from
> diff --git a/cpukit/libcsupport/src/privateenv.c b/cpukit/libcsupport/src/privateenv.c
> index c7a65a5..bee94c1 100644
> --- a/cpukit/libcsupport/src/privateenv.c
> +++ b/cpukit/libcsupport/src/privateenv.c
> @@ -35,13 +35,9 @@ static void free_user_env(void *arg)
> bool uses_global_env = env == &rtems_global_user_env;
>
> if (!uses_global_env) {
> - if (env->reference_count == 1) {
> - rtems_filesystem_global_location_release(env->current_directory);
> - rtems_filesystem_global_location_release(env->root_directory);
> - free(env);
> - } else {
> - --env->reference_count;
> - }
> + rtems_filesystem_global_location_release(env->current_directory);
> + rtems_filesystem_global_location_release(env->root_directory);
> + free(env);
> }
> }
>
> @@ -55,18 +51,14 @@ static void free_user_env_protected(rtems_user_env_t *env)
> rtems_status_code rtems_libio_set_private_env(void)
> {
> rtems_status_code sc = RTEMS_SUCCESSFUL;
> - rtems_id self_task_id = rtems_task_self();
> rtems_user_env_t *old_env = rtems_current_user_env;
> bool uses_global_env = old_env == &rtems_global_user_env;
> - bool uses_shared_env = old_env->task_id != self_task_id;
>
> - if (uses_global_env || uses_shared_env) {
> + if (uses_global_env) {
> rtems_user_env_t *new_env = calloc(1, sizeof(*new_env));
>
> if (new_env != NULL) {
> *new_env = *old_env;
> - new_env->reference_count = 1;
> - new_env->task_id = self_task_id;
> new_env->root_directory =
> rtems_filesystem_global_location_obtain(&old_env->root_directory);
> new_env->current_directory =
> @@ -102,50 +94,6 @@ rtems_status_code rtems_libio_set_private_env(void)
> return sc;
> }
>
> -rtems_status_code rtems_libio_share_private_env(rtems_id task_id)
> -{
> - rtems_status_code sc = RTEMS_SUCCESSFUL;
> - rtems_id self_task_id = rtems_task_self();
> -
> - if (task_id != RTEMS_SELF && self_task_id != task_id) {
> - rtems_user_env_t *env;
> -
> - /*
> - * We have to disable the thread dispatching to prevent deletion of the
> - * environment in the meantime.
> - */
> - _Thread_Disable_dispatch();
> - sc = rtems_task_variable_get(
> - task_id,
> - (void *) &rtems_current_user_env,
> - (void *) &env
> - );
> - if (sc == RTEMS_SUCCESSFUL) {
> - ++env->reference_count;
> - } else {
> - sc = RTEMS_UNSATISFIED;
> - }
> - _Thread_Enable_dispatch();
> -
> - if (sc == RTEMS_SUCCESSFUL) {
> - sc = rtems_task_variable_add(
> - RTEMS_SELF,
> - (void **) &rtems_current_user_env,
> - free_user_env
> - );
> - if (sc == RTEMS_SUCCESSFUL) {
> - free_user_env_protected(rtems_current_user_env);
> - rtems_current_user_env = env;
> - } else {
> - free_user_env_protected(env);
> - sc = RTEMS_TOO_MANY;
> - }
> - }
> - }
> -
> - return sc;
> -}
> -
> void rtems_libio_use_global_env(void)
> {
> rtems_status_code sc = RTEMS_SUCCESSFUL;
> diff --git a/testsuites/fstests/fsnofs01/fsnofs01.doc b/testsuites/fstests/fsnofs01/fsnofs01.doc
> index 5980be8..3a47c46 100644
> --- a/testsuites/fstests/fsnofs01/fsnofs01.doc
> +++ b/testsuites/fstests/fsnofs01/fsnofs01.doc
> @@ -35,7 +35,6 @@ directives:
> + rtems_filesystem_location_free
> + rtems_filesystem_global_location_obtain_null
> + rtems_libio_set_private_env
> - + rtems_libio_share_private_env
> + rtems_libio_use_global_env
> + rmdir
> + stat
> diff --git a/testsuites/fstests/fsnofs01/init.c b/testsuites/fstests/fsnofs01/init.c
> index fdcf959..13cd709 100644
> --- a/testsuites/fstests/fsnofs01/init.c
> +++ b/testsuites/fstests/fsnofs01/init.c
> @@ -315,18 +315,6 @@ static void test_user_env(void)
> rtems_test_assert(node_count(loc_chain) == 1);
> rtems_test_assert(null_loc->reference_count == 4);
>
> - sc = rtems_libio_share_private_env(RTEMS_SELF);
> - rtems_test_assert(sc == RTEMS_SUCCESSFUL);
> -
> - rtems_test_assert(node_count(loc_chain) == 1);
> - rtems_test_assert(null_loc->reference_count == 4);
> -
> - sc = rtems_libio_share_private_env(rtems_task_self());
> - rtems_test_assert(sc == RTEMS_SUCCESSFUL);
> -
> - rtems_test_assert(node_count(loc_chain) == 1);
> - rtems_test_assert(null_loc->reference_count == 4);
> -
> rtems_libio_use_global_env();
>
> rtems_test_assert(node_count(loc_chain) == 1);
> diff --git a/testsuites/sptests/spprivenv01/init.c b/testsuites/sptests/spprivenv01/init.c
> index f60bcef..a670085 100644
> --- a/testsuites/sptests/spprivenv01/init.c
> +++ b/testsuites/sptests/spprivenv01/init.c
> @@ -31,6 +31,9 @@ rtems_task task_routine(rtems_task_argument not_used)
>
> sc = rtems_libio_set_private_env();
> directive_failed( sc, "set private env" );
> + rtems_test_assert( sc == RTEMS_SUCCESSFUL );
> + rtems_test_assert( rtems_current_user_env != &rtems_global_user_env );
> +
> sleep( 1 );
>
> rtems_task_delete( RTEMS_SELF );
> @@ -42,9 +45,9 @@ rtems_task Init(
> {
> rtems_status_code sc;
> void *opaque;
> - rtems_id current_task_id;
> rtems_id task_id;
> rtems_name another_task_name;
> + rtems_user_env_t *current_env;
>
> TEST_BEGIN();
>
> @@ -68,6 +71,12 @@ rtems_task Init(
> puts( "Init - freeing the workspace memory" );
> rtems_workspace_greedy_free( opaque );
>
> + puts( "Init - Attempt to get a private environment" );
> + sc = rtems_libio_set_private_env();
> + rtems_test_assert( sc == RTEMS_SUCCESSFUL );
> + current_env = rtems_current_user_env;
> + rtems_test_assert( current_env != &rtems_global_user_env );
> +
> puts( "Init - creating a task name and a task -- OK" );
>
> another_task_name =
> @@ -85,33 +94,14 @@ rtems_task Init(
> sc = rtems_task_start( task_id, task_routine, 0);
> rtems_test_assert( sc == RTEMS_SUCCESSFUL );
>
> - puts( "Init - attempt to share the env with another task -- Expect error" );
> - sc = rtems_libio_share_private_env( task_id );
> - rtems_test_assert( sc == RTEMS_UNSATISFIED );
> -
> sleep( 1 );
>
> - puts( "Init - attempt to share the env with another task -- OK" );
> - sc = rtems_libio_share_private_env( task_id );
> - rtems_test_assert( sc == RTEMS_SUCCESSFUL );
> - rtems_test_assert( rtems_current_user_env->task_id == task_id );
> -
> - puts( "Init - Get current task id" );
> - current_task_id = rtems_task_self();
> + puts( "Init - Check current private environment. Should be same as before." );
> + rtems_test_assert( rtems_current_user_env == current_env );
>
> - puts( "Init - Attempt to reset current task's environment" );
> - sc = rtems_libio_set_private_env();
> - rtems_test_assert( sc == RTEMS_SUCCESSFUL );
> - rtems_test_assert( rtems_current_user_env->task_id == current_task_id );
> -
> - puts( "Init - attempt to share the env with another task -- OK" );
> - sc = rtems_libio_share_private_env( task_id );
> - rtems_test_assert( sc == RTEMS_SUCCESSFUL );
> - rtems_test_assert( rtems_current_user_env->task_id == task_id );
> -
> - puts( "Init - attempt to share with self -- OK" );
> - sc = rtems_libio_share_private_env( task_id );
> - rtems_test_assert( sc == RTEMS_SUCCESSFUL );
> + puts( "Init - Reset to global environment" );
> + rtems_libio_use_global_env();
> + rtems_test_assert( rtems_current_user_env == &rtems_global_user_env );
>
> TEST_END();
>
> diff --git a/testsuites/sptests/spprivenv01/spprivenv01.doc b/testsuites/sptests/spprivenv01/spprivenv01.doc
> index cb5c1bc..71ed426 100644
> --- a/testsuites/sptests/spprivenv01/spprivenv01.doc
> +++ b/testsuites/sptests/spprivenv01/spprivenv01.doc
> @@ -13,10 +13,9 @@ test set name: spprivenv01
> directives:
>
> + rtems_libio_set_private_env
> - + rtems_libio_share_private_env
>
> concepts:
>
> -+ Exercise the routines at privateenv.c, which reset/share a task's
> -private environment
> ++ Exercise the routines at privateenv.c, which reset a task's private
> +environment
>
> diff --git a/testsuites/sptests/spprivenv01/spprivenv01.scn b/testsuites/sptests/spprivenv01/spprivenv01.scn
> index b95832c..1b71be1 100644
> --- a/testsuites/sptests/spprivenv01/spprivenv01.scn
> +++ b/testsuites/sptests/spprivenv01/spprivenv01.scn
> @@ -1,17 +1,14 @@
> -*** TEST USER ENVIRONMENT ROUTINE - 01 ***
> +*** BEGIN OF TEST SPPRIVENV 1 ***
> Init - allocating most of heap -- OK
> Init - attempt to reset env - expect RTEMS_NO_MEMORY
> Init - freeing the allocated memory
> Init - allocating most of workspace memory
> -Init - attempt to reset env - expect RTEMS_NO_MEMORY
> +Init - attempt to reset env - expect RTEMS_TOO_MANY
> Init - freeing the workspace memory
> +Init - Attempt to get a private environment
> Init - creating a task name and a task -- OK
> Init - starting the task_routine, to set its private environment
> -Init - attempt to share the env with another task -- Expect error
> task_routine - setting up a private environment
> -Init - attempt to share the env with another task -- OK
> -Init - Get current task id
> -Init - Attempt to reset current task's environment
> -Init - attempt to share the env with another task -- OK
> -Init - attempt to share with self -- OK
> -*** END OF TEST USER ENVIRONMENT ROUTINE - 01 ***
> +Init - Check current private environment. Should be same as before.
> +Init - Reset to global environment
> +*** END OF TEST SPPRIVENV 1 ***
> --
> 1.8.4.5
>
> _______________________________________________
> rtems-devel mailing list
> rtems-devel at rtems.org
> http://www.rtems.org/mailman/listinfo/rtems-devel
More information about the devel
mailing list