Skip to content

Commit 09921cf

Browse files
robarnoldEric Holk
authored and
Eric Holk
committed
Move channel cloning logic into a method on rust_chan.
This will allow us to more easily clone channels from native code.
1 parent 396c4de commit 09921cf

File tree

3 files changed

+22
-15
lines changed

3 files changed

+22
-15
lines changed

src/rt/rust_chan.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,25 @@ void rust_chan::send(void *sptr) {
9797

9898
return;
9999
}
100+
101+
rust_chan *rust_chan::clone(maybe_proxy<rust_task> *target) {
102+
size_t unit_sz = buffer.unit_sz;
103+
maybe_proxy<rust_port> *port = this->port;
104+
rust_task *target_task = NULL;
105+
if (target->is_proxy() == false) {
106+
port = this->port;
107+
target_task = target->referent();
108+
} else {
109+
rust_handle<rust_port> *handle =
110+
task->sched->kernel->get_port_handle(port->as_referent());
111+
maybe_proxy<rust_port> *proxy = new rust_proxy<rust_port> (handle);
112+
LOG(task, mem, "new proxy: " PTR, proxy);
113+
port = proxy;
114+
target_task = target->as_proxy()->handle()->referent();
115+
}
116+
return new (target_task) rust_chan(target_task, port, unit_sz);
117+
}
118+
100119
//
101120
// Local Variables:
102121
// mode: C++

src/rt/rust_chan.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ class rust_chan : public rc_base<rust_chan>,
1919
bool is_associated();
2020

2121
void send(void *sptr);
22+
23+
rust_chan *clone(maybe_proxy<rust_task> *target);
2224
};
2325

2426
//

src/rt/rust_upcall.cpp

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -166,21 +166,7 @@ upcall_clone_chan(rust_task *task, maybe_proxy<rust_task> *target,
166166
rust_chan *chan) {
167167
LOG_UPCALL_ENTRY(task);
168168
scoped_lock with(task->kernel->scheduler_lock);
169-
size_t unit_sz = chan->buffer.unit_sz;
170-
maybe_proxy<rust_port> *port = chan->port;
171-
rust_task *target_task = NULL;
172-
if (target->is_proxy() == false) {
173-
port = chan->port;
174-
target_task = target->referent();
175-
} else {
176-
rust_handle<rust_port> *handle =
177-
task->sched->kernel->get_port_handle(port->as_referent());
178-
maybe_proxy<rust_port> *proxy = new rust_proxy<rust_port> (handle);
179-
LOG(task, mem, "new proxy: " PTR, proxy);
180-
port = proxy;
181-
target_task = target->as_proxy()->handle()->referent();
182-
}
183-
return new (target_task) rust_chan(target_task, port, unit_sz);
169+
return chan->clone(target);
184170
}
185171

186172
extern "C" CDECL void

0 commit comments

Comments
 (0)