Skip to content

Commit 81f760a

Browse files
author
Eric Holk
committed
---
yaml --- r: 3704 b: refs/heads/master c: dcd2563 h: refs/heads/master v: v3
1 parent 42affa0 commit 81f760a

File tree

8 files changed

+22
-99
lines changed

8 files changed

+22
-99
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: a0f45f4456de5e9811d80b20df243d7078c45918
2+
refs/heads/master: dcd2563a3a7662d03ab33b67c92652e6e24c5af1

trunk/src/rt/memory.h

Lines changed: 5 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -11,49 +11,23 @@ inline void *operator new(size_t size, rust_kernel *kernel) {
1111
}
1212

1313
inline void *operator new(size_t size, rust_task *task) {
14-
return task->malloc(size, memory_region::LOCAL);
14+
return task->malloc(size);
1515
}
1616

1717
inline void *operator new[](size_t size, rust_task *task) {
18-
return task->malloc(size, memory_region::LOCAL);
18+
return task->malloc(size);
1919
}
2020

2121
inline void *operator new(size_t size, rust_task &task) {
22-
return task.malloc(size, memory_region::LOCAL);
22+
return task.malloc(size);
2323
}
2424

2525
inline void *operator new[](size_t size, rust_task &task) {
26-
return task.malloc(size, memory_region::LOCAL);
27-
}
28-
29-
inline void *operator new(size_t size, rust_task *task,
30-
memory_region::memory_region_type type) {
31-
return task->malloc(size, type);
32-
}
33-
34-
inline void *operator new[](size_t size, rust_task *task,
35-
memory_region::memory_region_type type) {
36-
return task->malloc(size, type);
37-
}
38-
39-
inline void *operator new(size_t size, rust_task &task,
40-
memory_region::memory_region_type type) {
41-
return task.malloc(size, type);
42-
}
43-
44-
inline void *operator new[](size_t size, rust_task &task,
45-
memory_region::memory_region_type type) {
46-
return task.malloc(size, type);
26+
return task.malloc(size);
4727
}
4828

4929
inline void operator delete(void *mem, rust_task *task) {
50-
task->free(mem, memory_region::LOCAL);
51-
return;
52-
}
53-
54-
inline void operator delete(void *mem, rust_task *task,
55-
memory_region::memory_region_type type) {
56-
task->free(mem, type);
30+
task->free(mem);
5731
return;
5832
}
5933

trunk/src/rt/memory_region.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,6 @@ class memory_region {
2323
const bool _synchronized;
2424
lock_and_signal _lock;
2525
public:
26-
enum memory_region_type {
27-
LOCAL = 0x1, SYNCHRONIZED = 0x2
28-
};
2926
memory_region(rust_srv *srv, bool synchronized);
3027
memory_region(memory_region *parent);
3128
void *malloc(size_t size);

trunk/src/rt/rust_builtin.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ last_os_error(rust_task *task) {
4242
#endif
4343
size_t fill = strlen(buf) + 1;
4444
size_t alloc = next_power_of_two(sizeof(rust_str) + fill);
45-
void *mem = task->malloc(alloc, memory_region::LOCAL);
45+
void *mem = task->malloc(alloc);
4646
if (!mem) {
4747
task->fail(1);
4848
return NULL;
@@ -74,7 +74,7 @@ rust_getcwd(rust_task *task) {
7474

7575
size_t fill = strlen(cbuf) + 1;
7676
size_t alloc = next_power_of_two(sizeof(rust_str) + fill);
77-
void *mem = task->malloc(alloc, memory_region::LOCAL);
77+
void *mem = task->malloc(alloc);
7878
if (!mem) {
7979
task->fail(1);
8080
return NULL;
@@ -201,7 +201,7 @@ vec_alloc_with_data(rust_task *task,
201201
{
202202
rust_scheduler *sched = task->sched;
203203
size_t alloc = next_power_of_two(sizeof(rust_vec) + (n_elts * elt_size));
204-
void *mem = task->malloc(alloc, memory_region::LOCAL);
204+
void *mem = task->malloc(alloc);
205205
if (!mem) return NULL;
206206
return new (mem) rust_vec(sched, alloc, fill * elt_size, (uint8_t*)d);
207207
}
@@ -635,8 +635,9 @@ ivec_reserve(rust_task *task, type_desc *ty, rust_ivec *v, size_t n_elems)
635635
v->payload.ptr = heap_part;
636636
} else {
637637
// On heap; resize.
638-
heap_part = (rust_ivec_heap *)task->realloc(v->payload.ptr,
639-
new_alloc + sizeof(size_t));
638+
heap_part = (rust_ivec_heap *)
639+
task->realloc(v->payload.ptr,
640+
new_alloc + sizeof(size_t));
640641
v->payload.ptr = heap_part;
641642
}
642643

trunk/src/rt/rust_srv.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66
#include "rust_srv.h"
77

88
rust_srv::rust_srv() :
9-
local_region(this, false),
10-
synchronized_region(this, true) {
9+
local_region(this, false) {
1110
// Nop.
1211
}
1312

trunk/src/rt/rust_srv.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// -*- c++ -*-
12
#ifndef RUST_SRV_H
23
#define RUST_SRV_H
34

@@ -6,7 +7,6 @@
67
class rust_srv {
78
public:
89
memory_region local_region;
9-
memory_region synchronized_region;
1010
virtual void log(char const *msg);
1111
virtual void fatal(char const *expression,
1212
char const *file,

trunk/src/rt/rust_task.cpp

Lines changed: 8 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ rust_task::rust_task(rust_scheduler *sched, rust_task_list *state,
7373
running_on(-1),
7474
pinned_on(-1),
7575
local_region(&sched->srv->local_region),
76-
synchronized_region(&sched->srv->synchronized_region),
7776
_on_wakeup(NULL)
7877
{
7978
LOGPTR(sched, "new task", (uintptr_t)this);
@@ -326,7 +325,7 @@ rust_task::malloc(size_t sz, type_desc *td)
326325
if (td) {
327326
sz += sizeof(gc_alloc);
328327
}
329-
void *mem = malloc(sz, memory_region::LOCAL);
328+
void *mem = local_region.malloc(sz);
330329
if (!mem)
331330
return mem;
332331
if (td) {
@@ -353,7 +352,7 @@ rust_task::realloc(void *data, size_t sz, bool is_gc)
353352
gc_alloc *gcm = (gc_alloc*)(((char *)data) - sizeof(gc_alloc));
354353
unlink_gc(gcm);
355354
sz += sizeof(gc_alloc);
356-
gcm = (gc_alloc*) realloc((void*)gcm, sz, memory_region::LOCAL);
355+
gcm = (gc_alloc*) local_region.realloc((void*)gcm, sz);
357356
DLOG(sched, task, "task %s @0x%" PRIxPTR
358357
" reallocated %d GC bytes = 0x%" PRIxPTR,
359358
name, (uintptr_t)this, sz, gcm);
@@ -362,7 +361,7 @@ rust_task::realloc(void *data, size_t sz, bool is_gc)
362361
link_gc(gcm);
363362
data = (void*) &(gcm->data);
364363
} else {
365-
data = realloc(data, sz, memory_region::LOCAL);
364+
data = local_region.realloc(data, sz);
366365
}
367366
return data;
368367
}
@@ -379,9 +378,11 @@ rust_task::free(void *p, bool is_gc)
379378
DLOG(sched, mem,
380379
"task %s @0x%" PRIxPTR " freeing GC memory = 0x%" PRIxPTR,
381380
name, (uintptr_t)this, gcm);
382-
free(gcm, memory_region::LOCAL);
381+
DLOG(sched, mem, "rust_task::free(0x%" PRIxPTR ")", gcm);
382+
local_region.free(gcm);
383383
} else {
384-
free(p, memory_region::LOCAL);
384+
DLOG(sched, mem, "rust_task::free(0x%" PRIxPTR ")", p);
385+
local_region.free(p);
385386
}
386387
}
387388

@@ -473,52 +474,9 @@ bool rust_task::can_schedule(int id)
473474
(pinned_on == -1 || pinned_on == id);
474475
}
475476

476-
void *
477-
rust_task::malloc(size_t size, memory_region::memory_region_type type) {
478-
if (type == memory_region::LOCAL) {
479-
return local_region.malloc(size);
480-
} else if (type == memory_region::SYNCHRONIZED) {
481-
return synchronized_region.malloc(size);
482-
}
483-
I(sched, false);
484-
return NULL;
485-
}
486-
487477
void *
488478
rust_task::calloc(size_t size) {
489-
return calloc(size, memory_region::LOCAL);
490-
}
491-
492-
void *
493-
rust_task::calloc(size_t size, memory_region::memory_region_type type) {
494-
if (type == memory_region::LOCAL) {
495-
return local_region.calloc(size);
496-
} else if (type == memory_region::SYNCHRONIZED) {
497-
return synchronized_region.calloc(size);
498-
}
499-
return NULL;
500-
}
501-
502-
void *
503-
rust_task::realloc(void *mem, size_t size,
504-
memory_region::memory_region_type type) {
505-
if (type == memory_region::LOCAL) {
506-
return local_region.realloc(mem, size);
507-
} else if (type == memory_region::SYNCHRONIZED) {
508-
return synchronized_region.realloc(mem, size);
509-
}
510-
return NULL;
511-
}
512-
513-
void
514-
rust_task::free(void *mem, memory_region::memory_region_type type) {
515-
DLOG(sched, mem, "rust_task::free(0x%" PRIxPTR ")", mem);
516-
if (type == memory_region::LOCAL) {
517-
local_region.free(mem);
518-
} else if (type == memory_region::SYNCHRONIZED) {
519-
synchronized_region.free(mem);
520-
}
521-
return;
479+
return local_region.calloc(size);
522480
}
523481

524482
void rust_task::pin() {

trunk/src/rt/rust_task.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@ rust_task : public maybe_proxy<rust_task>,
8181
int pinned_on;
8282

8383
memory_region local_region;
84-
memory_region synchronized_region;
8584

8685
class wakeup_callback {
8786
public:
@@ -153,12 +152,7 @@ rust_task : public maybe_proxy<rust_task>,
153152

154153
bool can_schedule(int worker);
155154

156-
void *malloc(size_t size, memory_region::memory_region_type type);
157155
void *calloc(size_t size);
158-
void *calloc(size_t size, memory_region::memory_region_type type);
159-
void *realloc(void *mem, size_t size,
160-
memory_region::memory_region_type type);
161-
void free(void *mem, memory_region::memory_region_type type);
162156

163157
void pin();
164158
void pin(int id);

0 commit comments

Comments
 (0)