Skip to content

Commit 5843c66

Browse files
author
Eric Holk
committed
---
yaml --- r: 4662 b: refs/heads/master c: 04af99e h: refs/heads/master v: v3
1 parent 5c760b9 commit 5843c66

File tree

6 files changed

+38
-4
lines changed

6 files changed

+38
-4
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: a21ebb2f5ec5f158c3a2bbbccb76980624b1815f
2+
refs/heads/master: 04af99ecb0dee1cb3df0032f7e7ba08ffc6c5bd4

trunk/src/rt/rust_internal.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ struct type_desc;
6565
struct frame_glue_fns;
6666

6767
typedef intptr_t rust_task_id;
68+
typedef intptr_t rust_port_id;
6869

6970
#ifndef __i386__
7071
#error "Target CPU not supported."

trunk/src/rt/rust_port.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ rust_port::rust_port(rust_task *task, size_t unit_sz)
88
LOG(task, comm,
99
"new rust_port(task=0x%" PRIxPTR ", unit_sz=%d) -> port=0x%"
1010
PRIxPTR, (uintptr_t)task, unit_sz, (uintptr_t)this);
11+
12+
id = task->register_port(this);
1113
}
1214

1315
rust_port::~rust_port() {
@@ -19,6 +21,8 @@ rust_port::~rust_port() {
1921
rust_chan *chan = chans.peek();
2022
chan->disassociate();
2123
}
24+
25+
task->release_port(id);
2226
}
2327

2428
bool rust_port::receive(void *dptr) {

trunk/src/rt/rust_port.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,13 @@
22
#define RUST_PORT_H
33

44
class rust_port : public kernel_owned<rust_port>, public rust_cond {
5-
65
public:
76
RUST_REFCOUNTED(rust_port);
87

8+
private:
9+
rust_port_id id;
10+
11+
public:
912
rust_kernel *kernel;
1013
rust_task *task;
1114
size_t unit_sz;

trunk/src/rt/rust_task.cpp

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ rust_task::rust_task(rust_scheduler *sched, rust_task_list *state,
7575
cond_name("none"),
7676
supervisor(spawner),
7777
list_index(-1),
78+
next_port_id(0),
7879
rendezvous_ptr(0),
7980
running_on(-1),
8081
pinned_on(-1),
@@ -105,8 +106,6 @@ rust_task::~rust_task()
105106
del_stk(this, stk);
106107
}
107108

108-
extern "C" void rust_new_exit_task_glue();
109-
110109
struct spawn_args {
111110
rust_task *task;
112111
uintptr_t a3;
@@ -495,6 +494,26 @@ void rust_task::on_wakeup(rust_task::wakeup_callback *callback) {
495494
_on_wakeup = callback;
496495
}
497496

497+
rust_port_id rust_task::register_port(rust_port *port) {
498+
scoped_lock with(lock);
499+
500+
rust_port_id id = next_port_id++;
501+
port_table.put(id, port);
502+
return id;
503+
}
504+
505+
void rust_task::release_port(rust_port_id id) {
506+
scoped_lock with(lock);
507+
port_table.remove(id);
508+
}
509+
510+
rust_port *rust_task::get_port_by_id(rust_port_id id) {
511+
scoped_lock with(lock);
512+
rust_port *port = NULL;
513+
port_table.get(id, &port);
514+
return port;
515+
}
516+
498517
//
499518
// Local Variables:
500519
// mode: C++

trunk/src/rt/rust_task.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ rust_task : public kernel_owned<rust_task>, rust_cond
5959
size_t gc_alloc_accum;
6060

6161
rust_task_id id;
62+
rust_port_id next_port_id;
6263

6364
// Keeps track of the last time this task yielded.
6465
timer yield_timer;
@@ -96,6 +97,8 @@ rust_task : public kernel_owned<rust_task>, rust_cond
9697

9798
lock_and_signal lock;
9899

100+
hash_map<rust_port_id, rust_port *> port_table;
101+
99102
// Only a pointer to 'name' is kept, so it must live as long as this task.
100103
rust_task(rust_scheduler *sched,
101104
rust_task_list *state,
@@ -161,6 +164,10 @@ rust_task : public kernel_owned<rust_task>, rust_cond
161164
void unpin();
162165

163166
void on_wakeup(wakeup_callback *callback);
167+
168+
rust_port_id register_port(rust_port *port);
169+
void release_port(rust_port_id id);
170+
rust_port *get_port_by_id(rust_port_id id);
164171
};
165172

166173
//

0 commit comments

Comments
 (0)