* env.c -> env.cpp
* Squashed TODO: Use a benaphore for locking to improve performance. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@27360 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -10,7 +10,7 @@ MergeObject posix_stdlib.o :
|
|||||||
atoi.c
|
atoi.c
|
||||||
bsearch.c
|
bsearch.c
|
||||||
div.c
|
div.c
|
||||||
env.c
|
env.cpp
|
||||||
exit.c
|
exit.c
|
||||||
heapsort.c
|
heapsort.c
|
||||||
merge.c
|
merge.c
|
||||||
|
|||||||
@@ -4,15 +4,16 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#include <OS.h>
|
#include <errno.h>
|
||||||
|
|
||||||
#include <libroot_private.h>
|
|
||||||
#include <user_runtime.h>
|
|
||||||
|
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <errno.h>
|
|
||||||
|
#include <OS.h>
|
||||||
|
|
||||||
|
#include <libroot_lock.h>
|
||||||
|
#include <libroot_private.h>
|
||||||
|
#include <user_runtime.h>
|
||||||
|
|
||||||
|
|
||||||
#define RETURN_AND_SET_ERRNO(err) \
|
#define RETURN_AND_SET_ERRNO(err) \
|
||||||
@@ -23,8 +24,7 @@
|
|||||||
return err;
|
return err;
|
||||||
|
|
||||||
|
|
||||||
// TODO: Use benaphore!
|
static benaphore sEnvLock;
|
||||||
static sem_id sEnvLock;
|
|
||||||
static char **sManagedEnviron;
|
static char **sManagedEnviron;
|
||||||
|
|
||||||
char **environ = NULL;
|
char **environ = NULL;
|
||||||
@@ -33,15 +33,14 @@ char **environ = NULL;
|
|||||||
static inline void
|
static inline void
|
||||||
lock_variables(void)
|
lock_variables(void)
|
||||||
{
|
{
|
||||||
while (acquire_sem(sEnvLock) == B_INTERRUPTED)
|
benaphore_lock(&sEnvLock);
|
||||||
;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static inline void
|
static inline void
|
||||||
unlock_variables(void)
|
unlock_variables(void)
|
||||||
{
|
{
|
||||||
release_sem(sEnvLock);
|
benaphore_unlock(&sEnvLock);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -81,7 +80,7 @@ static int32
|
|||||||
add_variable(void)
|
add_variable(void)
|
||||||
{
|
{
|
||||||
int32 count = count_variables() + 1;
|
int32 count = count_variables() + 1;
|
||||||
char **newEnviron = realloc(environ, (count + 1) * sizeof(char *));
|
char **newEnviron = (char**)realloc(environ, (count + 1) * sizeof(char *));
|
||||||
if (newEnviron == NULL)
|
if (newEnviron == NULL)
|
||||||
return B_NO_MEMORY;
|
return B_NO_MEMORY;
|
||||||
|
|
||||||
@@ -133,7 +132,7 @@ copy_environ_to_heap_if_needed(void)
|
|||||||
// free previously used "environ" if it has been changed by an application
|
// free previously used "environ" if it has been changed by an application
|
||||||
free_variables();
|
free_variables();
|
||||||
|
|
||||||
sManagedEnviron = malloc((count_variables() + 1) * sizeof(char *));
|
sManagedEnviron = (char**)malloc((count_variables() + 1) * sizeof(char *));
|
||||||
if (sManagedEnviron == NULL)
|
if (sManagedEnviron == NULL)
|
||||||
return B_NO_MEMORY;
|
return B_NO_MEMORY;
|
||||||
|
|
||||||
@@ -177,7 +176,7 @@ update_variable(const char *name, int32 length, const char *value,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (update) {
|
if (update) {
|
||||||
environ[index] = malloc(length + 2 + strlen(value));
|
environ[index] = (char*)malloc(length + 2 + strlen(value));
|
||||||
if (environ[index] == NULL)
|
if (environ[index] == NULL)
|
||||||
return B_NO_MEMORY;
|
return B_NO_MEMORY;
|
||||||
|
|
||||||
@@ -193,7 +192,7 @@ update_variable(const char *name, int32 length, const char *value,
|
|||||||
static void
|
static void
|
||||||
environ_fork_hook(void)
|
environ_fork_hook(void)
|
||||||
{
|
{
|
||||||
sEnvLock = create_sem(1, "env lock");
|
benaphore_init(&sEnvLock, "env lock");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -206,7 +205,7 @@ __init_env(const struct user_space_program_args *args)
|
|||||||
// Following POSIX, there is no need to make any of the environment
|
// Following POSIX, there is no need to make any of the environment
|
||||||
// functions thread-safe - but we do it anyway as much as possible to
|
// functions thread-safe - but we do it anyway as much as possible to
|
||||||
// protect our implementation
|
// protect our implementation
|
||||||
sEnvLock = create_sem(1, "env lock");
|
benaphore_init(&sEnvLock, "env lock");
|
||||||
environ = args->env;
|
environ = args->env;
|
||||||
sManagedEnviron = NULL;
|
sManagedEnviron = NULL;
|
||||||
|
|
||||||
Reference in New Issue
Block a user