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:
@@ -12,6 +12,7 @@ struct real_time_data;
|
|||||||
void __init_image(const struct uspace_program_args *args);
|
void __init_image(const struct uspace_program_args *args);
|
||||||
void __init_dlfcn(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_env(const struct uspace_program_args *args);
|
||||||
|
void __init_heap(void);
|
||||||
|
|
||||||
void __init_time(void);
|
void __init_time(void);
|
||||||
void __arch_init_time(struct real_time_data *data);
|
void __arch_init_time(struct real_time_data *data);
|
||||||
|
|||||||
@@ -12,7 +12,6 @@
|
|||||||
|
|
||||||
|
|
||||||
void initialize_before(image_id imageID, struct uspace_program_args const *args);
|
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;
|
char *__progname = NULL;
|
||||||
int __libc_argc;
|
int __libc_argc;
|
||||||
@@ -45,13 +44,7 @@ initialize_before(image_id imageID, struct uspace_program_args const *args)
|
|||||||
__init_image(args);
|
__init_image(args);
|
||||||
__init_dlfcn(args);
|
__init_dlfcn(args);
|
||||||
__init_fork();
|
__init_fork();
|
||||||
}
|
__init_heap();
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
initialize_after(image_id imageID, struct uspace_program_args const *args)
|
|
||||||
{
|
|
||||||
// ToDo: can be moved to _before() once malloc() works before
|
|
||||||
__init_env(args);
|
__init_env(args);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -17,57 +17,45 @@
|
|||||||
//
|
//
|
||||||
//////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
//#include <assert.h>
|
|
||||||
|
|
||||||
#include "arch-specific.h"
|
#include "arch-specific.h"
|
||||||
#include "heap.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 <OS.h>
|
||||||
|
#include <Debug.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
using namespace BPrivate;
|
using namespace BPrivate;
|
||||||
|
|
||||||
|
|
||||||
static area_id heap_region = -1;
|
static area_id heap_region = -1;
|
||||||
static addr_t brk;
|
static addr_t brk;
|
||||||
|
|
||||||
int
|
|
||||||
__heap_init()
|
// ToDo: add real fork() support!
|
||||||
|
|
||||||
|
extern "C" status_t
|
||||||
|
__init_heap(void)
|
||||||
{
|
{
|
||||||
// XXX do something better here
|
// XXX do something better here
|
||||||
if (heap_region < 0) {
|
if (heap_region < 0) {
|
||||||
heap_region = create_area("heap", (void **)&brk,
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
class heap_init_hack_t {
|
namespace BPrivate {
|
||||||
public:
|
|
||||||
heap_init_hack_t(void)
|
|
||||||
{
|
|
||||||
__heap_init();
|
|
||||||
}
|
|
||||||
} heap_init_hack;
|
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
hoardCreateThread(hoardThreadType &thread,
|
hoardCreateThread(hoardThreadType &thread,
|
||||||
void *(*function)(void *), void *arg)
|
void *(*function)(void *), void *arg)
|
||||||
{
|
{
|
||||||
thread = spawn_thread((int32 (*)(void*))function, "some thread",
|
thread = spawn_thread((int32 (*)(void *))function, "hoard thread",
|
||||||
B_NORMAL_PRIORITY, arg);
|
B_NORMAL_PRIORITY, arg);
|
||||||
if (thread >= B_OK)
|
if (thread < B_OK)
|
||||||
resume_thread(thread);
|
|
||||||
else
|
|
||||||
debugger("spawn_thread() failed!");
|
debugger("spawn_thread() failed!");
|
||||||
|
|
||||||
|
resume_thread(thread);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -139,13 +127,11 @@ hoardSbrk(long size)
|
|||||||
void *ret = (void *)brk;
|
void *ret = (void *)brk;
|
||||||
brk += size + hoardHeap::ALIGNMENT - 1;
|
brk += size + hoardHeap::ALIGNMENT - 1;
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
// return sbrk(size + hoardHeap::ALIGNMENT - 1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
hoardUnsbrk(void * ptr, long size)
|
hoardUnsbrk(void *ptr, long size)
|
||||||
{
|
{
|
||||||
// NOT CURRENTLY IMPLEMENTED!
|
// NOT CURRENTLY IMPLEMENTED!
|
||||||
}
|
}
|
||||||
@@ -168,4 +154,4 @@ hoardInterlockedExchange(unsigned long *oldval,
|
|||||||
return o;
|
return o;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
} // namespace BPrivate
|
||||||
|
|||||||
@@ -39,38 +39,38 @@ operator new(size_t, void *_P)
|
|||||||
|
|
||||||
typedef thread_id hoardThreadType;
|
typedef thread_id hoardThreadType;
|
||||||
|
|
||||||
extern "C" {
|
namespace BPrivate {
|
||||||
///// Thread-related wrappers.
|
///// Thread-related wrappers.
|
||||||
|
|
||||||
void hoardCreateThread (hoardThreadType& t,
|
void hoardCreateThread(hoardThreadType &t,
|
||||||
void *(*function) (void *),
|
void *(*function)(void *), void *arg);
|
||||||
void * arg);
|
void hoardJoinThread(hoardThreadType &t);
|
||||||
void hoardJoinThread (hoardThreadType& t);
|
void hoardSetConcurrency(int n);
|
||||||
void hoardSetConcurrency (int n);
|
|
||||||
|
|
||||||
// Return a thread identifier appropriate for hashing:
|
// Return a thread identifier appropriate for hashing:
|
||||||
// if the system doesn't produce consecutive thread id's,
|
// if the system doesn't produce consecutive thread id's,
|
||||||
// some hackery may be necessary.
|
// some hackery may be necessary.
|
||||||
int hoardGetThreadID (void);
|
int hoardGetThreadID(void);
|
||||||
|
|
||||||
///// Lock-related wrappers.
|
///// Lock-related wrappers.
|
||||||
|
|
||||||
void hoardLockInit(hoardLockType& lock, const char *name);
|
void hoardLockInit(hoardLockType &lock, const char *name);
|
||||||
void hoardLock(hoardLockType& lock);
|
void hoardLock(hoardLockType &lock);
|
||||||
void hoardUnlock(hoardLockType& lock);
|
void hoardUnlock(hoardLockType &lock);
|
||||||
|
|
||||||
///// Memory-related wrapper.
|
///// Memory-related wrapper.
|
||||||
|
|
||||||
int hoardGetPageSize (void);
|
int hoardGetPageSize(void);
|
||||||
void * hoardSbrk (long size);
|
void *hoardSbrk(long size);
|
||||||
void hoardUnsbrk (void * ptr, long size);
|
void hoardUnsbrk(void *ptr, long size);
|
||||||
|
|
||||||
///// Other.
|
///// Other.
|
||||||
|
|
||||||
void hoardYield (void);
|
void hoardYield(void);
|
||||||
int hoardGetNumProcessors (void);
|
int hoardGetNumProcessors(void);
|
||||||
unsigned long hoardInterlockedExchange (unsigned long * oldval,
|
unsigned long hoardInterlockedExchange(unsigned long *oldval,
|
||||||
unsigned long newval);
|
unsigned long newval);
|
||||||
}
|
|
||||||
|
} // namespace BPrivate
|
||||||
|
|
||||||
#endif // _ARCH_SPECIFIC_H_
|
#endif // _ARCH_SPECIFIC_H_
|
||||||
|
|||||||
Reference in New Issue
Block a user