Rename rust_proxy_delegate to maybe_proxy, flesh out logic in it. Add strong-ref distinction on rust_proxy.
This commit is contained in:
parent
30b3f8a117
commit
defd8a66ea
4 changed files with 48 additions and 23 deletions
|
@ -1,30 +1,55 @@
|
|||
#ifndef RUST_PROXY_H
|
||||
#define RUST_PROXY_H
|
||||
|
||||
/**
|
||||
* A proxy object is a wrapper around other Rust objects. One use of the proxy
|
||||
* object is to mitigate access between tasks in different thread domains.
|
||||
*/
|
||||
|
||||
#ifndef RUST_PROXY_H
|
||||
#define RUST_PROXY_H
|
||||
|
||||
template <typename T> struct rust_proxy;
|
||||
/**
|
||||
* The base class of all objects that may delegate.
|
||||
*/
|
||||
template <typename T> struct
|
||||
rust_proxy_delegate : public rc_base<T> {
|
||||
maybe_proxy : public rc_base<T>, public rust_cond {
|
||||
protected:
|
||||
T *_delegate;
|
||||
public:
|
||||
rust_proxy_delegate(T * delegate) : _delegate(delegate) {
|
||||
maybe_proxy(T * delegate) : _delegate(delegate) {
|
||||
|
||||
}
|
||||
T *delegate() {
|
||||
return _delegate;
|
||||
}
|
||||
bool is_proxy() {
|
||||
return _delegate != this;
|
||||
}
|
||||
rust_proxy<T> *as_proxy() {
|
||||
return (rust_proxy<T> *) this;
|
||||
}
|
||||
T *as_delegate() {
|
||||
I(_delegate->get_dom(), !is_proxy());
|
||||
return (T *) this;
|
||||
}
|
||||
T *delegate() { return _delegate; }
|
||||
};
|
||||
|
||||
/**
|
||||
* A proxy object that delegates to another.
|
||||
*/
|
||||
template <typename T> struct
|
||||
rust_proxy : public rust_proxy_delegate<T>,
|
||||
rust_proxy : public maybe_proxy<T>,
|
||||
public dom_owned<rust_proxy<T> > {
|
||||
private:
|
||||
bool _strong;
|
||||
public:
|
||||
rust_dom *dom;
|
||||
rust_proxy(rust_dom *dom, T *delegate) :
|
||||
rust_proxy_delegate<T> (delegate),
|
||||
dom(dom) {
|
||||
delegate->ref();
|
||||
rust_proxy(rust_dom *dom, T *delegate, bool strong) :
|
||||
maybe_proxy<T> (delegate), _strong(strong), dom(dom) {
|
||||
this->dom->log(rust_log::COMM,
|
||||
"new proxy: 0x%" PRIxPTR " => 0x%" PRIxPTR, this, delegate);
|
||||
if (strong) {
|
||||
delegate->ref();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -53,7 +53,7 @@ align_down(uintptr_t sp)
|
|||
|
||||
|
||||
rust_task::rust_task(rust_dom *dom, rust_task *spawner) :
|
||||
rust_proxy_delegate<rust_task>(this),
|
||||
maybe_proxy<rust_task>(this),
|
||||
stk(new_stk(dom, 0)),
|
||||
runtime_sp(0),
|
||||
rust_sp(stk->limit),
|
||||
|
|
|
@ -5,9 +5,8 @@
|
|||
#ifndef RUST_TASK_H
|
||||
#define RUST_TASK_H
|
||||
struct
|
||||
rust_task : public rust_proxy_delegate<rust_task>,
|
||||
public dom_owned<rust_task>,
|
||||
public rust_cond
|
||||
rust_task : public maybe_proxy<rust_task>,
|
||||
public dom_owned<rust_task>
|
||||
{
|
||||
// Fields known to the compiler.
|
||||
stk_seg *stk;
|
||||
|
|
|
@ -105,7 +105,7 @@ extern "C" CDECL void upcall_del_chan(rust_task *task, rust_chan *chan) {
|
|||
*/
|
||||
extern "C" CDECL rust_chan *
|
||||
upcall_clone_chan(rust_task *task,
|
||||
rust_proxy_delegate<rust_task> *spawnee_proxy,
|
||||
maybe_proxy<rust_task> *spawnee_proxy,
|
||||
rust_chan *chan) {
|
||||
LOG_UPCALL_ENTRY(task);
|
||||
rust_task *spawnee = spawnee_proxy->delegate();
|
||||
|
@ -121,8 +121,8 @@ extern "C" CDECL void upcall_yield(rust_task *task) {
|
|||
task->yield(1);
|
||||
}
|
||||
|
||||
extern "C" CDECL void upcall_join(rust_task *task,
|
||||
rust_proxy_delegate<rust_task> *proxy) {
|
||||
extern "C" CDECL void
|
||||
upcall_join(rust_task *task, maybe_proxy<rust_task> *proxy) {
|
||||
LOG_UPCALL_ENTRY(task);
|
||||
task->log(rust_log::UPCALL | rust_log::COMM,
|
||||
"join proxy 0x%" PRIxPTR " -> task = 0x%" PRIxPTR,
|
||||
|
@ -194,7 +194,7 @@ extern "C" CDECL void upcall_fail(rust_task *task, char const *expr,
|
|||
* Called whenever a task's ref count drops to zero.
|
||||
*/
|
||||
extern "C" CDECL void
|
||||
upcall_kill(rust_task *task, rust_proxy_delegate<rust_task> *target_proxy) {
|
||||
upcall_kill(rust_task *task, maybe_proxy<rust_task> *target_proxy) {
|
||||
LOG_UPCALL_ENTRY(task);
|
||||
rust_task *target_task = target_proxy->delegate();
|
||||
if (target_proxy != target_task) {
|
||||
|
@ -504,7 +504,7 @@ upcall_start_task(rust_task *spawner, rust_task *task,
|
|||
return task;
|
||||
}
|
||||
|
||||
extern "C" CDECL rust_proxy_delegate<rust_task> *
|
||||
extern "C" CDECL maybe_proxy<rust_task> *
|
||||
upcall_new_thread(rust_task *task) {
|
||||
LOG_UPCALL_ENTRY(task);
|
||||
|
||||
|
@ -516,16 +516,17 @@ upcall_new_thread(rust_task *task) {
|
|||
"upcall new_thread() = dom 0x%" PRIxPTR " task 0x%" PRIxPTR,
|
||||
new_dom, new_dom->root_task);
|
||||
rust_proxy<rust_task> *proxy =
|
||||
new (old_dom) rust_proxy<rust_task>(old_dom, new_dom->root_task);
|
||||
new (old_dom) rust_proxy<rust_task>(old_dom,
|
||||
new_dom->root_task, true);
|
||||
task->log(rust_log::UPCALL | rust_log::MEM,
|
||||
"new proxy = 0x%" PRIxPTR " -> task = 0x%" PRIxPTR,
|
||||
proxy, proxy->delegate());
|
||||
return proxy;
|
||||
}
|
||||
|
||||
extern "C" CDECL rust_proxy_delegate<rust_task> *
|
||||
extern "C" CDECL maybe_proxy<rust_task> *
|
||||
upcall_start_thread(rust_task *spawner,
|
||||
rust_proxy_delegate<rust_task> *root_task_proxy,
|
||||
maybe_proxy<rust_task> *root_task_proxy,
|
||||
uintptr_t exit_task_glue, uintptr_t spawnee_fn, size_t callsz) {
|
||||
LOG_UPCALL_ENTRY(spawner);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue