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
This commit is contained in:
Axel Dörfler 2005-03-23 01:47:21 +00:00
parent 162d278cbd
commit c4472a00b1
4 changed files with 43 additions and 63 deletions

View File

@ -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);

View File

@ -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);
}

View File

@ -17,57 +17,45 @@
//
//////////////////////////////////////////////////////////////////////////////
//#include <assert.h>
#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 <OS.h>
#include <Debug.h>
#include <unistd.h>
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

View File

@ -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_