aboutsummaryrefslogtreecommitdiff
path: root/src/rt/rust_proxy.h
blob: bf12e1d5f0ed4dbd43d71f06d015bc6831d754f2 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#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.
 */

template <typename T> struct rust_proxy;
/**
 * The base class of all objects that may delegate.
 */
template <typename T> struct
maybe_proxy : public rc_base<T>, public rust_cond {
protected:
    T *_delegate;
public:
    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;
    }
};

/**
 * A proxy object that delegates to another.
 */
template <typename T> struct
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, 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();
        }
    }
};

//
// Local Variables:
// mode: C++
// fill-column: 78;
// indent-tabs-mode: nil
// c-basic-offset: 4
// buffer-file-coding-system: utf-8-unix
// compile-command: "make -k -C .. 2>&1 | sed -e 's/\\/x\\//x:\\//g'";
// End:
//

#endif /* RUST_PROXY_H */