From b27c9bd52f4c5e891085c2cc72b69cfe1b93c478 Mon Sep 17 00:00:00 2001 From: Ingo Weinhold Date: Sun, 7 Sep 2008 15:28:39 +0000 Subject: [PATCH] * 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 --- src/system/libroot/posix/stdlib/Jamfile | 16 +++++----- .../libroot/posix/stdlib/{env.c => env.cpp} | 31 +++++++++---------- 2 files changed, 23 insertions(+), 24 deletions(-) rename src/system/libroot/posix/stdlib/{env.c => env.cpp} (92%) diff --git a/src/system/libroot/posix/stdlib/Jamfile b/src/system/libroot/posix/stdlib/Jamfile index 741cd2aaeb..149bbb2fa3 100644 --- a/src/system/libroot/posix/stdlib/Jamfile +++ b/src/system/libroot/posix/stdlib/Jamfile @@ -6,19 +6,19 @@ UsePrivateSystemHeaders ; MergeObject posix_stdlib.o : abs.c atfork.c - atof.c - atoi.c + atof.c + atoi.c bsearch.c - div.c - env.c + div.c + env.cpp exit.c - heapsort.c + heapsort.c merge.c mktemp.c pty.cpp - qsort.c - radixsort.c - rand.c + qsort.c + radixsort.c + rand.c random.c realpath.c strtod.c diff --git a/src/system/libroot/posix/stdlib/env.c b/src/system/libroot/posix/stdlib/env.cpp similarity index 92% rename from src/system/libroot/posix/stdlib/env.c rename to src/system/libroot/posix/stdlib/env.cpp index d38044f25e..ac6f4bdc80 100644 --- a/src/system/libroot/posix/stdlib/env.c +++ b/src/system/libroot/posix/stdlib/env.cpp @@ -4,15 +4,16 @@ */ -#include - -#include -#include - +#include #include #include #include -#include + +#include + +#include +#include +#include #define RETURN_AND_SET_ERRNO(err) \ @@ -23,8 +24,7 @@ return err; -// TODO: Use benaphore! -static sem_id sEnvLock; +static benaphore sEnvLock; static char **sManagedEnviron; char **environ = NULL; @@ -33,15 +33,14 @@ char **environ = NULL; static inline void lock_variables(void) { - while (acquire_sem(sEnvLock) == B_INTERRUPTED) - ; + benaphore_lock(&sEnvLock); } static inline void unlock_variables(void) { - release_sem(sEnvLock); + benaphore_unlock(&sEnvLock); } @@ -81,7 +80,7 @@ static int32 add_variable(void) { 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) 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_variables(); - sManagedEnviron = malloc((count_variables() + 1) * sizeof(char *)); + sManagedEnviron = (char**)malloc((count_variables() + 1) * sizeof(char *)); if (sManagedEnviron == NULL) return B_NO_MEMORY; @@ -177,7 +176,7 @@ update_variable(const char *name, int32 length, const char *value, } if (update) { - environ[index] = malloc(length + 2 + strlen(value)); + environ[index] = (char*)malloc(length + 2 + strlen(value)); if (environ[index] == NULL) return B_NO_MEMORY; @@ -193,7 +192,7 @@ update_variable(const char *name, int32 length, const char *value, static 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 // functions thread-safe - but we do it anyway as much as possible to // protect our implementation - sEnvLock = create_sem(1, "env lock"); + benaphore_init(&sEnvLock, "env lock"); environ = args->env; sManagedEnviron = NULL;