about summary refs log tree commit diff
path: root/src/rt/rust_proxy.h
diff options
context:
space:
mode:
authorMichael Bebenita <mbebenita@mozilla.com>2010-07-28 15:17:30 -0700
committerGraydon Hoare <graydon@mozilla.com>2010-07-28 20:30:29 -0700
commitdefd8a66eade4cb11960cf6de2b45c2f42ec3388 (patch)
treed9c2c87a2df903ba4ae3b93536805a6b2ad17c39 /src/rt/rust_proxy.h
parent30b3f8a11713e32fdb0d0059141289152a46d501 (diff)
Rename rust_proxy_delegate to maybe_proxy, flesh out logic in it. Add strong-ref distinction on rust_proxy.
Diffstat (limited to 'src/rt/rust_proxy.h')
-rw-r--r--src/rt/rust_proxy.h47
1 files changed, 36 insertions, 11 deletions
diff --git a/src/rt/rust_proxy.h b/src/rt/rust_proxy.h
index e2fa5e00546..bf12e1d5f0e 100644
--- a/src/rt/rust_proxy.h
+++ b/src/rt/rust_proxy.h
@@ -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();
+        }
     }
 };