aboutsummaryrefslogtreecommitdiff
path: root/src/rt/rust_message.h
blob: 6d986acf5d2d3cf59af5cb71269ae13c86157413 (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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#ifndef RUST_MESSAGE_H
#define RUST_MESSAGE_H

/**
 * Rust messages are used for inter-thread communication. They are enqueued
 * and allocated in the target domain.
 */

/**
 * Abstract base class for all message types.
 */
class rust_message : public lock_free_queue_node {
public:
    const char* label;
private:
    rust_dom *_dom;
    rust_task *_source;
protected:
    rust_task *_target;
public:
    rust_message(const char* label, rust_task *source, rust_task *target);
    virtual ~rust_message();

    /**
     * We can only access the source task through a proxy, so create one
     * on demand if we need it.
     */
    rust_proxy<rust_task> *get_source_proxy();

    /**
     * Processes the message in the target domain thread.
     */
    virtual void process();
};

/**
 * Notify messages are simple argument-less messages.
 */
class notify_message : public rust_message {
public:
    enum notification_type {
        KILL, JOIN, WAKEUP
    };

    const notification_type type;

    notify_message(notification_type type, const char* label,
                   rust_task *source, rust_task *target);

    void process();

    /**
     * This code executes in the sending domain's thread.
     */
    static void
    send(notification_type type, const char* label, rust_task *source,
         rust_proxy<rust_task> *target);
};

/**
 * Data messages carry a buffer.
 */
class data_message : public rust_message {
private:
    uint8_t *_buffer;
    size_t _buffer_sz;
    rust_port *_port;
public:

    data_message(uint8_t *buffer, size_t buffer_sz, const char* label,
                 rust_task *source, rust_task *target, rust_port *port);
    virtual ~data_message();
    void process();

    /**
     * This code executes in the sending domain's thread.
     */
    static void
    send(uint8_t *buffer, size_t buffer_sz, const char* label,
         rust_task *source, rust_proxy<rust_task> *target,
         rust_proxy<rust_port> *port);
};

//
// 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_MESSAGE_H */