From f2bb2575e6aec54c1302c398bf47baebe0e042df Mon Sep 17 00:00:00 2001 From: Ingo Weinhold Date: Sun, 29 Nov 2009 09:57:26 +0000 Subject: [PATCH] Use the shared recursive lock implementation instead of the home-grown stuff. The shared implementation is benaphore style, saving unnecessary syscalls. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@34338 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/system/runtime_loader/Jamfile | 4 +++- src/system/runtime_loader/elf.cpp | 37 +++++++++++-------------------- 2 files changed, 16 insertions(+), 25 deletions(-) diff --git a/src/system/runtime_loader/Jamfile b/src/system/runtime_loader/Jamfile index aebc828137..bbe827cd18 100644 --- a/src/system/runtime_loader/Jamfile +++ b/src/system/runtime_loader/Jamfile @@ -1,6 +1,6 @@ SubDir HAIKU_TOP src system runtime_loader ; -UsePrivateHeaders runtime_loader ; +UsePrivateHeaders runtime_loader shared ; UsePrivateHeaders kernel ; # for UsePrivateSystemHeaders ; @@ -24,6 +24,7 @@ StaticLibrary libruntime_loader.a : kernel_cpp.cpp KMessage.cpp : + locks.o syscalls.o sem.o @@ -90,6 +91,7 @@ Ld runtime_loader : $(TARGET_STATIC_LIBSUPC++) $(TARGET_GCC_LIBGCC) : $(HAIKU_TOP)/src/system/ldscripts/$(TARGET_ARCH)/runtime_loader.ld + : --no-undefined ; HaikuSubInclude arch $(TARGET_ARCH) ; diff --git a/src/system/runtime_loader/elf.cpp b/src/system/runtime_loader/elf.cpp index d80bdbcf59..58e88edc16 100644 --- a/src/system/runtime_loader/elf.cpp +++ b/src/system/runtime_loader/elf.cpp @@ -22,6 +22,8 @@ #include #include +#include + #include "add_ons.h" #include "elf_load_image.h" #include "elf_symbol_lookup.h" @@ -45,31 +47,20 @@ image_t* gProgramImage; static image_t** sPreloadedImages = NULL; static uint32 sPreloadedImageCount = 0; -// a recursive lock -static sem_id sSem; -static thread_id sSemOwner; -static int32 sSemCount; +static recursive_lock sLock; -static void -rld_unlock() +static inline void +rld_lock() { - if (sSemCount-- == 1) { - sSemOwner = -1; - release_sem(sSem); - } + recursive_lock_lock(&sLock); } -static void -rld_lock() +static inline void +rld_unlock() { - thread_id self = find_thread(NULL); - if (self != sSemOwner) { - acquire_sem(sSem); - sSemOwner = self; - } - sSemCount++; + recursive_lock_unlock(&sLock); } @@ -938,9 +929,7 @@ terminate_program(void) void rldelf_init(void) { - sSem = create_sem(1, "runtime loader"); - sSemOwner = -1; - sSemCount = 0; + recursive_lock_init(&sLock, "runtime loader"); init_add_ons(); @@ -974,9 +963,9 @@ rldelf_init(void) status_t elf_reinit_after_fork(void) { - sSem = create_sem(1, "runtime loader"); - if (sSem < 0) - return sSem; + status_t error = recursive_lock_init(&sLock, "runtime loader"); + if (error != B_OK) + return error; // We also need to update the IDs of our images. We are the child and // and have cloned images with different IDs. Since in most cases (fork()