Removing the synchronized memory region from tasks.

This commit is contained in:
Eric Holk 2011-07-06 16:42:02 -07:00
parent a0f45f4456
commit dcd2563a3a
7 changed files with 21 additions and 98 deletions

View File

@ -11,49 +11,23 @@ inline void *operator new(size_t size, rust_kernel *kernel) {
}
inline void *operator new(size_t size, rust_task *task) {
return task->malloc(size, memory_region::LOCAL);
return task->malloc(size);
}
inline void *operator new[](size_t size, rust_task *task) {
return task->malloc(size, memory_region::LOCAL);
return task->malloc(size);
}
inline void *operator new(size_t size, rust_task &task) {
return task.malloc(size, memory_region::LOCAL);
return task.malloc(size);
}
inline void *operator new[](size_t size, rust_task &task) {
return task.malloc(size, memory_region::LOCAL);
}
inline void *operator new(size_t size, rust_task *task,
memory_region::memory_region_type type) {
return task->malloc(size, type);
}
inline void *operator new[](size_t size, rust_task *task,
memory_region::memory_region_type type) {
return task->malloc(size, type);
}
inline void *operator new(size_t size, rust_task &task,
memory_region::memory_region_type type) {
return task.malloc(size, type);
}
inline void *operator new[](size_t size, rust_task &task,
memory_region::memory_region_type type) {
return task.malloc(size, type);
return task.malloc(size);
}
inline void operator delete(void *mem, rust_task *task) {
task->free(mem, memory_region::LOCAL);
return;
}
inline void operator delete(void *mem, rust_task *task,
memory_region::memory_region_type type) {
task->free(mem, type);
task->free(mem);
return;
}

View File

@ -23,9 +23,6 @@ private:
const bool _synchronized;
lock_and_signal _lock;
public:
enum memory_region_type {
LOCAL = 0x1, SYNCHRONIZED = 0x2
};
memory_region(rust_srv *srv, bool synchronized);
memory_region(memory_region *parent);
void *malloc(size_t size);

View File

@ -42,7 +42,7 @@ last_os_error(rust_task *task) {
#endif
size_t fill = strlen(buf) + 1;
size_t alloc = next_power_of_two(sizeof(rust_str) + fill);
void *mem = task->malloc(alloc, memory_region::LOCAL);
void *mem = task->malloc(alloc);
if (!mem) {
task->fail(1);
return NULL;
@ -74,7 +74,7 @@ rust_getcwd(rust_task *task) {
size_t fill = strlen(cbuf) + 1;
size_t alloc = next_power_of_two(sizeof(rust_str) + fill);
void *mem = task->malloc(alloc, memory_region::LOCAL);
void *mem = task->malloc(alloc);
if (!mem) {
task->fail(1);
return NULL;
@ -201,7 +201,7 @@ vec_alloc_with_data(rust_task *task,
{
rust_scheduler *sched = task->sched;
size_t alloc = next_power_of_two(sizeof(rust_vec) + (n_elts * elt_size));
void *mem = task->malloc(alloc, memory_region::LOCAL);
void *mem = task->malloc(alloc);
if (!mem) return NULL;
return new (mem) rust_vec(sched, alloc, fill * elt_size, (uint8_t*)d);
}
@ -635,8 +635,9 @@ ivec_reserve(rust_task *task, type_desc *ty, rust_ivec *v, size_t n_elems)
v->payload.ptr = heap_part;
} else {
// On heap; resize.
heap_part = (rust_ivec_heap *)task->realloc(v->payload.ptr,
new_alloc + sizeof(size_t));
heap_part = (rust_ivec_heap *)
task->realloc(v->payload.ptr,
new_alloc + sizeof(size_t));
v->payload.ptr = heap_part;
}

View File

@ -6,8 +6,7 @@
#include "rust_srv.h"
rust_srv::rust_srv() :
local_region(this, false),
synchronized_region(this, true) {
local_region(this, false) {
// Nop.
}

View File

@ -1,3 +1,4 @@
// -*- c++ -*-
#ifndef RUST_SRV_H
#define RUST_SRV_H
@ -6,7 +7,6 @@
class rust_srv {
public:
memory_region local_region;
memory_region synchronized_region;
virtual void log(char const *msg);
virtual void fatal(char const *expression,
char const *file,

View File

@ -73,7 +73,6 @@ rust_task::rust_task(rust_scheduler *sched, rust_task_list *state,
running_on(-1),
pinned_on(-1),
local_region(&sched->srv->local_region),
synchronized_region(&sched->srv->synchronized_region),
_on_wakeup(NULL)
{
LOGPTR(sched, "new task", (uintptr_t)this);
@ -326,7 +325,7 @@ rust_task::malloc(size_t sz, type_desc *td)
if (td) {
sz += sizeof(gc_alloc);
}
void *mem = malloc(sz, memory_region::LOCAL);
void *mem = local_region.malloc(sz);
if (!mem)
return mem;
if (td) {
@ -353,7 +352,7 @@ rust_task::realloc(void *data, size_t sz, bool is_gc)
gc_alloc *gcm = (gc_alloc*)(((char *)data) - sizeof(gc_alloc));
unlink_gc(gcm);
sz += sizeof(gc_alloc);
gcm = (gc_alloc*) realloc((void*)gcm, sz, memory_region::LOCAL);
gcm = (gc_alloc*) local_region.realloc((void*)gcm, sz);
DLOG(sched, task, "task %s @0x%" PRIxPTR
" reallocated %d GC bytes = 0x%" PRIxPTR,
name, (uintptr_t)this, sz, gcm);
@ -362,7 +361,7 @@ rust_task::realloc(void *data, size_t sz, bool is_gc)
link_gc(gcm);
data = (void*) &(gcm->data);
} else {
data = realloc(data, sz, memory_region::LOCAL);
data = local_region.realloc(data, sz);
}
return data;
}
@ -379,9 +378,11 @@ rust_task::free(void *p, bool is_gc)
DLOG(sched, mem,
"task %s @0x%" PRIxPTR " freeing GC memory = 0x%" PRIxPTR,
name, (uintptr_t)this, gcm);
free(gcm, memory_region::LOCAL);
DLOG(sched, mem, "rust_task::free(0x%" PRIxPTR ")", gcm);
local_region.free(gcm);
} else {
free(p, memory_region::LOCAL);
DLOG(sched, mem, "rust_task::free(0x%" PRIxPTR ")", p);
local_region.free(p);
}
}
@ -473,52 +474,9 @@ bool rust_task::can_schedule(int id)
(pinned_on == -1 || pinned_on == id);
}
void *
rust_task::malloc(size_t size, memory_region::memory_region_type type) {
if (type == memory_region::LOCAL) {
return local_region.malloc(size);
} else if (type == memory_region::SYNCHRONIZED) {
return synchronized_region.malloc(size);
}
I(sched, false);
return NULL;
}
void *
rust_task::calloc(size_t size) {
return calloc(size, memory_region::LOCAL);
}
void *
rust_task::calloc(size_t size, memory_region::memory_region_type type) {
if (type == memory_region::LOCAL) {
return local_region.calloc(size);
} else if (type == memory_region::SYNCHRONIZED) {
return synchronized_region.calloc(size);
}
return NULL;
}
void *
rust_task::realloc(void *mem, size_t size,
memory_region::memory_region_type type) {
if (type == memory_region::LOCAL) {
return local_region.realloc(mem, size);
} else if (type == memory_region::SYNCHRONIZED) {
return synchronized_region.realloc(mem, size);
}
return NULL;
}
void
rust_task::free(void *mem, memory_region::memory_region_type type) {
DLOG(sched, mem, "rust_task::free(0x%" PRIxPTR ")", mem);
if (type == memory_region::LOCAL) {
local_region.free(mem);
} else if (type == memory_region::SYNCHRONIZED) {
synchronized_region.free(mem);
}
return;
return local_region.calloc(size);
}
void rust_task::pin() {

View File

@ -81,7 +81,6 @@ rust_task : public maybe_proxy<rust_task>,
int pinned_on;
memory_region local_region;
memory_region synchronized_region;
class wakeup_callback {
public:
@ -153,12 +152,7 @@ rust_task : public maybe_proxy<rust_task>,
bool can_schedule(int worker);
void *malloc(size_t size, memory_region::memory_region_type type);
void *calloc(size_t size);
void *calloc(size_t size, memory_region::memory_region_type type);
void *realloc(void *mem, size_t size,
memory_region::memory_region_type type);
void free(void *mem, memory_region::memory_region_type type);
void pin();
void pin(int id);