rtems_status_code rtems_libio_share_private_env(rtems_id task_id) { rtems_status_code sc; rtems_user_env_t * shared_user_env; rtems_id current_task_id; /* * get current task id */ current_task_id = rtems_task_self(); /* * If this was an attempt to share the task with self, * if somebody wanted to do it... Lets tell them, its shared */ if( task_id == current_task_id ) return RTEMS_SUCCESSFUL; /* * Try to get the requested user environment */ sc = rtems_task_variable_get( task_id, (void*)&rtems_current_user_env, (void*)&shared_user_env ); /* * If it was not successful, return the error code */ if (sc != RTEMS_SUCCESSFUL) return sc; /* * If we are here, we have the required environment to be * shared with the current task */ /* * If we have a current environment in place, we need to * free it, since we will be sharing the variable with the * shared_user_env */ if (rtems_current_user_env->task_id==current_task_id) { rtems_user_env_t *tmp = rtems_current_user_env; free_user_env( tmp ); } /* the current_user_env is the same pointer that remote env */ rtems_current_user_env = shared_user_env; /* increase the reference count */ #ifdef HAVE_USERENV_REFCNT rtems_current_user_env->refcnt++; #endif return RTEMS_SUCCESSFUL; }
epos_status_code epos_libio_share_private_env(epos_id task_id) { epos_status_code sc; epos_user_env_t * shared_user_env; epos_id current_task_id; sc=epos_task_ident(RTEMS_SELF,0,¤t_task_id); if (sc != RTEMS_SUCCESSFUL) return sc; if (epos_current_user_env->task_id==current_task_id) { /* kill the current user env & task_var*/ epos_user_env_t *tmp = epos_current_user_env; sc = epos_task_variable_delete(RTEMS_SELF,(void*)&epos_current_user_env); if (sc != RTEMS_SUCCESSFUL) return sc; free_user_env(tmp); }; /* AT THIS POINT, epos_current_user_env is DANGLING */ sc = epos_task_variable_get(task_id,(void*)&epos_current_user_env, (void*)&shared_user_env ); if (sc != RTEMS_SUCCESSFUL) goto bailout; sc = epos_task_variable_add(RTEMS_SELF,(void*)&epos_current_user_env,free_user_env); if (sc != RTEMS_SUCCESSFUL) goto bailout; /* the current_user_env is the same pointer that remote env */ epos_current_user_env = shared_user_env; /* increase the reference count */ #ifdef HAVE_USERENV_REFCNT epos_current_user_env->refcnt++; #endif return RTEMS_SUCCESSFUL; bailout: /* fallback to the global env */ epos_current_user_env = &epos_global_user_env; return sc; }