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
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
SubDir HAIKU_TOP src system runtime_loader ;
|
SubDir HAIKU_TOP src system runtime_loader ;
|
||||||
|
|
||||||
UsePrivateHeaders runtime_loader ;
|
UsePrivateHeaders runtime_loader shared ;
|
||||||
UsePrivateHeaders kernel ;
|
UsePrivateHeaders kernel ;
|
||||||
# for <util/KMessage.h>
|
# for <util/KMessage.h>
|
||||||
UsePrivateSystemHeaders ;
|
UsePrivateSystemHeaders ;
|
||||||
@@ -24,6 +24,7 @@ StaticLibrary libruntime_loader.a :
|
|||||||
kernel_cpp.cpp
|
kernel_cpp.cpp
|
||||||
KMessage.cpp
|
KMessage.cpp
|
||||||
:
|
:
|
||||||
|
<src!system!libroot!os>locks.o
|
||||||
<src!system!libroot!os>syscalls.o
|
<src!system!libroot!os>syscalls.o
|
||||||
<src!system!libroot!os>sem.o
|
<src!system!libroot!os>sem.o
|
||||||
|
|
||||||
@@ -90,6 +91,7 @@ Ld runtime_loader :
|
|||||||
$(TARGET_STATIC_LIBSUPC++)
|
$(TARGET_STATIC_LIBSUPC++)
|
||||||
$(TARGET_GCC_LIBGCC)
|
$(TARGET_GCC_LIBGCC)
|
||||||
: $(HAIKU_TOP)/src/system/ldscripts/$(TARGET_ARCH)/runtime_loader.ld
|
: $(HAIKU_TOP)/src/system/ldscripts/$(TARGET_ARCH)/runtime_loader.ld
|
||||||
|
: --no-undefined
|
||||||
;
|
;
|
||||||
|
|
||||||
HaikuSubInclude arch $(TARGET_ARCH) ;
|
HaikuSubInclude arch $(TARGET_ARCH) ;
|
||||||
|
|||||||
@@ -22,6 +22,8 @@
|
|||||||
#include <syscalls.h>
|
#include <syscalls.h>
|
||||||
#include <util/kernel_cpp.h>
|
#include <util/kernel_cpp.h>
|
||||||
|
|
||||||
|
#include <locks.h>
|
||||||
|
|
||||||
#include "add_ons.h"
|
#include "add_ons.h"
|
||||||
#include "elf_load_image.h"
|
#include "elf_load_image.h"
|
||||||
#include "elf_symbol_lookup.h"
|
#include "elf_symbol_lookup.h"
|
||||||
@@ -45,31 +47,20 @@ image_t* gProgramImage;
|
|||||||
static image_t** sPreloadedImages = NULL;
|
static image_t** sPreloadedImages = NULL;
|
||||||
static uint32 sPreloadedImageCount = 0;
|
static uint32 sPreloadedImageCount = 0;
|
||||||
|
|
||||||
// a recursive lock
|
static recursive_lock sLock;
|
||||||
static sem_id sSem;
|
|
||||||
static thread_id sSemOwner;
|
|
||||||
static int32 sSemCount;
|
|
||||||
|
|
||||||
|
|
||||||
static void
|
static inline void
|
||||||
rld_unlock()
|
rld_lock()
|
||||||
{
|
{
|
||||||
if (sSemCount-- == 1) {
|
recursive_lock_lock(&sLock);
|
||||||
sSemOwner = -1;
|
|
||||||
release_sem(sSem);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void
|
static inline void
|
||||||
rld_lock()
|
rld_unlock()
|
||||||
{
|
{
|
||||||
thread_id self = find_thread(NULL);
|
recursive_lock_unlock(&sLock);
|
||||||
if (self != sSemOwner) {
|
|
||||||
acquire_sem(sSem);
|
|
||||||
sSemOwner = self;
|
|
||||||
}
|
|
||||||
sSemCount++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -938,9 +929,7 @@ terminate_program(void)
|
|||||||
void
|
void
|
||||||
rldelf_init(void)
|
rldelf_init(void)
|
||||||
{
|
{
|
||||||
sSem = create_sem(1, "runtime loader");
|
recursive_lock_init(&sLock, "runtime loader");
|
||||||
sSemOwner = -1;
|
|
||||||
sSemCount = 0;
|
|
||||||
|
|
||||||
init_add_ons();
|
init_add_ons();
|
||||||
|
|
||||||
@@ -974,9 +963,9 @@ rldelf_init(void)
|
|||||||
status_t
|
status_t
|
||||||
elf_reinit_after_fork(void)
|
elf_reinit_after_fork(void)
|
||||||
{
|
{
|
||||||
sSem = create_sem(1, "runtime loader");
|
status_t error = recursive_lock_init(&sLock, "runtime loader");
|
||||||
if (sSem < 0)
|
if (error != B_OK)
|
||||||
return sSem;
|
return error;
|
||||||
|
|
||||||
// We also need to update the IDs of our images. We are the child and
|
// 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()
|
// and have cloned images with different IDs. Since in most cases (fork()
|
||||||
|
|||||||
Reference in New Issue
Block a user