Replace semaphores/benaphores in the env, fork, and user/group code by lazy

mutexes.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@34340 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Ingo Weinhold 2009-11-29 10:47:01 +00:00
parent 937b23cb21
commit 6e06922908
5 changed files with 25 additions and 35 deletions

View File

@ -4,7 +4,7 @@ UsePrivateHeaders app shared [ FDirName syslog_daemon ] ;
UsePrivateSystemHeaders ;
UsePrivateHeaders kernel ;
# For util/KMessage.h
UsePrivateHeaders libroot runtime_loader ;
UsePrivateHeaders libroot runtime_loader shared ;
if $(HAIKU_MULTIUSER_QUERY) = 1 {
PWD_BACKEND = pwd_query.c ;

View File

@ -1,6 +1,6 @@
SubDir HAIKU_TOP src system libroot posix stdlib ;
UsePrivateHeaders drivers libroot runtime_loader ;
UsePrivateHeaders drivers libroot runtime_loader shared ;
UsePrivateSystemHeaders ;
MergeObject posix_stdlib.o :

View File

@ -11,21 +11,14 @@
#include <OS.h>
#include <libroot_lock.h>
#include <libroot_private.h>
#include <locks.h>
#include <runtime_loader.h>
#include <syscall_utils.h>
#include <user_runtime.h>
#define RETURN_AND_SET_ERRNO(err) \
if (err < 0) { \
errno = err; \
return -1; \
} \
return err;
static benaphore sEnvLock;
static lazy_mutex sEnvLock;
static char **sManagedEnviron;
char **environ = NULL;
@ -34,14 +27,14 @@ char **environ = NULL;
static inline void
lock_variables(void)
{
benaphore_lock(&sEnvLock);
lazy_mutex_lock(&sEnvLock);
}
static inline void
unlock_variables(void)
{
benaphore_unlock(&sEnvLock);
lazy_mutex_unlock(&sEnvLock);
}
@ -193,7 +186,7 @@ update_variable(const char *name, int32 length, const char *value,
static void
environ_fork_hook(void)
{
benaphore_init(&sEnvLock, "env lock");
lazy_mutex_init(&sEnvLock, "env lock");
}
@ -206,7 +199,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
benaphore_init(&sEnvLock, "env lock");
lazy_mutex_init(&sEnvLock, "env lock");
environ = args->env;
sManagedEnviron = NULL;

View File

@ -10,6 +10,7 @@
#include <stdlib.h>
#include <errno.h>
#include <locks.h>
#include <libroot_private.h>
#include <runtime_loader.h>
#include <syscalls.h>
@ -22,7 +23,7 @@ typedef struct fork_hook {
static fork_hook *sPrepareHooks, *sParentHooks, *sChildHooks;
static fork_hook *sLastParentHook, *sLastChildHook;
static sem_id sForkLock;
static lazy_mutex sForkLock;
extern thread_id __main_thread_id;
@ -95,10 +96,7 @@ call_fork_hooks(fork_hook *hook)
status_t
__init_fork(void)
{
sForkLock = create_sem(1, "fork lock");
if (sForkLock < B_OK)
return sForkLock;
lazy_mutex_init(&sForkLock, "fork lock");
return B_OK;
}
@ -111,9 +109,7 @@ __init_fork(void)
status_t
__register_atfork(void (*prepare)(void), void (*parent)(void), void (*child)(void))
{
status_t status;
while ((status = acquire_sem(sForkLock)) == B_INTERRUPTED);
status_t status = lazy_mutex_lock(&sForkLock);
if (status != B_OK)
return status;
@ -126,7 +122,7 @@ __register_atfork(void (*prepare)(void), void (*parent)(void), void (*child)(voi
if (status == B_OK && child)
status = add_fork_hook(&sChildHooks, &sLastChildHook, child);
release_sem(sForkLock);
lazy_mutex_unlock(&sForkLock);
return status;
}
@ -137,7 +133,7 @@ fork(void)
thread_id thread;
status_t status;
while ((status = acquire_sem(sForkLock)) == B_INTERRUPTED);
status = lazy_mutex_lock(&sForkLock);
if (status != B_OK)
return status;
@ -147,7 +143,7 @@ fork(void)
thread = _kern_fork();
if (thread < 0) {
// something went wrong
release_sem(sForkLock);
lazy_mutex_unlock(&sForkLock);
errno = thread;
return -1;
}
@ -164,7 +160,7 @@ fork(void)
} else {
// we are the parent
call_fork_hooks(sParentHooks);
release_sem(sForkLock);
lazy_mutex_unlock(&sForkLock);
}
return thread;

View File

@ -14,8 +14,8 @@
#include <new>
#include <libroot_lock.h>
#include <libroot_private.h>
#include <locks.h>
#include <RegistrarDefs.h>
#include <util/KMessage.h>
@ -28,21 +28,22 @@ const char* BPrivate::kPasswdFile = "/etc/passwd";
const char* BPrivate::kGroupFile = "/etc/group";
const char* BPrivate::kShadowPwdFile = "/etc/shadow";
static benaphore sUserGroupLock;
static lazy_mutex sUserGroupLock;
static port_id sRegistrarPort = -1;
status_t
BPrivate::user_group_lock()
{
return benaphore_lock(&sUserGroupLock);
return lazy_mutex_lock(&sUserGroupLock);
}
status_t
BPrivate::user_group_unlock()
{
return benaphore_unlock(&sUserGroupLock);
lazy_mutex_unlock(&sUserGroupLock);
return B_OK;
}
@ -86,7 +87,7 @@ public:
if (fString != NULL) {
*fString = '\0';
fString++;
}
}
return token;
}
@ -384,12 +385,12 @@ BPrivate::parse_shadow_pwd_line(char* line, char*& name, char*& password,
void
__init_pwd_backend(void)
{
benaphore_init(&sUserGroupLock, "user group");
lazy_mutex_init(&sUserGroupLock, "user group");
}
void
__reinit_pwd_backend_after_fork(void)
{
benaphore_init(&sUserGroupLock, "user group");
lazy_mutex_init(&sUserGroupLock, "user group");
}