From c4472a00b18debad374ab1c1a15b02af6385e9d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Wed, 23 Mar 2005 01:47:21 +0000 Subject: [PATCH] The heap is now initialized by libroot_init.c::initialize_before(), so that we no longer need an initialize_after(). Put the architecture dependent hoard functions into the BPrivate namespace as well. Minor cleanup. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@11956 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- headers/private/libroot/libroot_private.h | 1 + src/kernel/libroot/libroot_init.c | 9 +--- .../libroot/posix/malloc/arch-specific.cpp | 46 ++++++----------- .../libroot/posix/malloc/arch-specific.h | 50 +++++++++---------- 4 files changed, 43 insertions(+), 63 deletions(-) diff --git a/headers/private/libroot/libroot_private.h b/headers/private/libroot/libroot_private.h index 76581ea6e2..25412e476b 100644 --- a/headers/private/libroot/libroot_private.h +++ b/headers/private/libroot/libroot_private.h @@ -12,6 +12,7 @@ struct real_time_data; void __init_image(const struct uspace_program_args *args); void __init_dlfcn(const struct uspace_program_args *args); void __init_env(const struct uspace_program_args *args); +void __init_heap(void); void __init_time(void); void __arch_init_time(struct real_time_data *data); diff --git a/src/kernel/libroot/libroot_init.c b/src/kernel/libroot/libroot_init.c index fb22df1f69..1d3d4006c3 100644 --- a/src/kernel/libroot/libroot_init.c +++ b/src/kernel/libroot/libroot_init.c @@ -12,7 +12,6 @@ void initialize_before(image_id imageID, struct uspace_program_args const *args); -void initialize_after(image_id imageID, struct uspace_program_args const *args); char *__progname = NULL; int __libc_argc; @@ -45,13 +44,7 @@ initialize_before(image_id imageID, struct uspace_program_args const *args) __init_image(args); __init_dlfcn(args); __init_fork(); -} - - -void -initialize_after(image_id imageID, struct uspace_program_args const *args) -{ - // ToDo: can be moved to _before() once malloc() works before + __init_heap(); __init_env(args); } diff --git a/src/kernel/libroot/posix/malloc/arch-specific.cpp b/src/kernel/libroot/posix/malloc/arch-specific.cpp index 59172de7b3..b44a2d6e7a 100644 --- a/src/kernel/libroot/posix/malloc/arch-specific.cpp +++ b/src/kernel/libroot/posix/malloc/arch-specific.cpp @@ -17,57 +17,45 @@ // ////////////////////////////////////////////////////////////////////////////// -//#include - #include "arch-specific.h" #include "heap.h" -// How many iterations we spin waiting for a lock. -enum { SPIN_LIMIT = 100 }; - -// The values of a user-level lock. -enum { UNLOCKED = 0, LOCKED = 1 }; - -extern "C" { - #include +#include #include using namespace BPrivate; + static area_id heap_region = -1; static addr_t brk; -int -__heap_init() + +// ToDo: add real fork() support! + +extern "C" status_t +__init_heap(void) { // XXX do something better here if (heap_region < 0) { heap_region = create_area("heap", (void **)&brk, - B_ANY_ADDRESS, 4*1024*1024, B_NO_LOCK, B_READ_AREA | B_WRITE_AREA); + B_ANY_ADDRESS, 1024 * B_PAGE_SIZE, B_NO_LOCK, B_READ_AREA | B_WRITE_AREA); } return 0; } -class heap_init_hack_t { -public: - heap_init_hack_t(void) - { - __heap_init(); - } -} heap_init_hack; - +namespace BPrivate { void hoardCreateThread(hoardThreadType &thread, void *(*function)(void *), void *arg) { - thread = spawn_thread((int32 (*)(void*))function, "some thread", - B_NORMAL_PRIORITY, arg); - if (thread >= B_OK) - resume_thread(thread); - else + thread = spawn_thread((int32 (*)(void *))function, "hoard thread", + B_NORMAL_PRIORITY, arg); + if (thread < B_OK) debugger("spawn_thread() failed!"); + + resume_thread(thread); } @@ -139,13 +127,11 @@ hoardSbrk(long size) void *ret = (void *)brk; brk += size + hoardHeap::ALIGNMENT - 1; return ret; - -// return sbrk(size + hoardHeap::ALIGNMENT - 1); } void -hoardUnsbrk(void * ptr, long size) +hoardUnsbrk(void *ptr, long size) { // NOT CURRENTLY IMPLEMENTED! } @@ -168,4 +154,4 @@ hoardInterlockedExchange(unsigned long *oldval, return o; } -} +} // namespace BPrivate diff --git a/src/kernel/libroot/posix/malloc/arch-specific.h b/src/kernel/libroot/posix/malloc/arch-specific.h index 9933e725c7..c774879519 100644 --- a/src/kernel/libroot/posix/malloc/arch-specific.h +++ b/src/kernel/libroot/posix/malloc/arch-specific.h @@ -39,38 +39,38 @@ operator new(size_t, void *_P) typedef thread_id hoardThreadType; -extern "C" { - ///// Thread-related wrappers. +namespace BPrivate { +///// Thread-related wrappers. - void hoardCreateThread (hoardThreadType& t, - void *(*function) (void *), - void * arg); - void hoardJoinThread (hoardThreadType& t); - void hoardSetConcurrency (int n); +void hoardCreateThread(hoardThreadType &t, + void *(*function)(void *), void *arg); +void hoardJoinThread(hoardThreadType &t); +void hoardSetConcurrency(int n); - // Return a thread identifier appropriate for hashing: - // if the system doesn't produce consecutive thread id's, - // some hackery may be necessary. - int hoardGetThreadID (void); +// Return a thread identifier appropriate for hashing: +// if the system doesn't produce consecutive thread id's, +// some hackery may be necessary. +int hoardGetThreadID(void); - ///// Lock-related wrappers. +///// Lock-related wrappers. - void hoardLockInit(hoardLockType& lock, const char *name); - void hoardLock(hoardLockType& lock); - void hoardUnlock(hoardLockType& lock); +void hoardLockInit(hoardLockType &lock, const char *name); +void hoardLock(hoardLockType &lock); +void hoardUnlock(hoardLockType &lock); - ///// Memory-related wrapper. +///// Memory-related wrapper. - int hoardGetPageSize (void); - void * hoardSbrk (long size); - void hoardUnsbrk (void * ptr, long size); +int hoardGetPageSize(void); +void *hoardSbrk(long size); +void hoardUnsbrk(void *ptr, long size); - ///// Other. +///// Other. - void hoardYield (void); - int hoardGetNumProcessors (void); - unsigned long hoardInterlockedExchange (unsigned long * oldval, - unsigned long newval); -} +void hoardYield(void); +int hoardGetNumProcessors(void); +unsigned long hoardInterlockedExchange(unsigned long *oldval, + unsigned long newval); + +} // namespace BPrivate #endif // _ARCH_SPECIFIC_H_