From 09921cf86f156208741243a7e0ea55b88155ec72 Mon Sep 17 00:00:00 2001 From: Rob Arnold Date: Wed, 29 Jun 2011 20:54:03 -0700 Subject: [PATCH] Move channel cloning logic into a method on rust_chan. This will allow us to more easily clone channels from native code. --- src/rt/rust_chan.cpp | 19 +++++++++++++++++++ src/rt/rust_chan.h | 2 ++ src/rt/rust_upcall.cpp | 16 +--------------- 3 files changed, 22 insertions(+), 15 deletions(-) diff --git a/src/rt/rust_chan.cpp b/src/rt/rust_chan.cpp index a947a1c93e8..a1c71b049ea 100644 --- a/src/rt/rust_chan.cpp +++ b/src/rt/rust_chan.cpp @@ -97,6 +97,25 @@ void rust_chan::send(void *sptr) { return; } + +rust_chan *rust_chan::clone(maybe_proxy *target) { + size_t unit_sz = buffer.unit_sz; + maybe_proxy *port = this->port; + rust_task *target_task = NULL; + if (target->is_proxy() == false) { + port = this->port; + target_task = target->referent(); + } else { + rust_handle *handle = + task->sched->kernel->get_port_handle(port->as_referent()); + maybe_proxy *proxy = new rust_proxy (handle); + LOG(task, mem, "new proxy: " PTR, proxy); + port = proxy; + target_task = target->as_proxy()->handle()->referent(); + } + return new (target_task) rust_chan(target_task, port, unit_sz); +} + // // Local Variables: // mode: C++ diff --git a/src/rt/rust_chan.h b/src/rt/rust_chan.h index a6e4d3d6b43..603936d5b77 100644 --- a/src/rt/rust_chan.h +++ b/src/rt/rust_chan.h @@ -19,6 +19,8 @@ public: bool is_associated(); void send(void *sptr); + + rust_chan *clone(maybe_proxy *target); }; // diff --git a/src/rt/rust_upcall.cpp b/src/rt/rust_upcall.cpp index 4f7dccc4652..2d3f8c7e139 100644 --- a/src/rt/rust_upcall.cpp +++ b/src/rt/rust_upcall.cpp @@ -166,21 +166,7 @@ upcall_clone_chan(rust_task *task, maybe_proxy *target, rust_chan *chan) { LOG_UPCALL_ENTRY(task); scoped_lock with(task->kernel->scheduler_lock); - size_t unit_sz = chan->buffer.unit_sz; - maybe_proxy *port = chan->port; - rust_task *target_task = NULL; - if (target->is_proxy() == false) { - port = chan->port; - target_task = target->referent(); - } else { - rust_handle *handle = - task->sched->kernel->get_port_handle(port->as_referent()); - maybe_proxy *proxy = new rust_proxy (handle); - LOG(task, mem, "new proxy: " PTR, proxy); - port = proxy; - target_task = target->as_proxy()->handle()->referent(); - } - return new (target_task) rust_chan(target_task, port, unit_sz); + return chan->clone(target); } extern "C" CDECL void