1
- /*
2
- Module: comm
3
-
4
- Communication between tasks
5
-
6
- Communication between tasks is facilitated by ports (in the receiving task),
7
- and channels (in the sending task). Any number of channels may feed into a
8
- single port.
9
-
10
- Ports and channels may only transmit values of unique types; that is,
11
- values that are statically guaranteed to be accessed by a single
12
- 'owner' at a time. Unique types include scalars, vectors, strings,
13
- and records, tags, tuples and unique boxes (~T) thereof. Most notably,
14
- shared boxes (@T) may not be transmitted across channels.
15
-
16
- Example:
17
-
18
- > let p = comm::port();
19
- > task::spawn(comm::chan(p), fn (c: chan<str>) {
20
- > comm::send(c, "Hello, World");
21
- > });
22
- >
23
- > io::println(comm::recv(p));
24
-
25
- */
1
+ #[ doc(
2
+ brief = "Communication between tasks" ,
3
+ desc = "Communication between tasks is facilitated by ports (in the \
4
+ receiving task), and channels (in the sending task). Any \
5
+ number of channels may feed into a single port. \
6
+ Ports and channels may only transmit values of unique \
7
+ types; that is, values that are statically guaranteed to \
8
+ be accessed by a single 'owner' at a time. Unique types \
9
+ include scalars, vectors, strings, and records, tags, \
10
+ tuples and unique boxes (~T) thereof. Most notably, \
11
+ shared boxes (@T) may not be transmitted across channels. \
12
+ Example: \
13
+ let p = comm::port(); \
14
+ task::spawn(comm::chan(p), fn (c: chan<str>) { \
15
+ comm::send(c, \" Hello, World\" ); \
16
+ }); \
17
+ io::println(comm::recv(p));"
18
+ ) ] ;
26
19
27
20
import sys;
28
21
import task;
@@ -59,22 +52,18 @@ type port_id = int;
59
52
60
53
// It's critical that this only have one variant, so it has a record
61
54
// layout, and will work in the rust_task structure in task.rs.
62
- /*
63
- Type: chan
64
-
65
- A communication endpoint that can send messages. Channels send
66
- messages to ports.
67
-
68
- Each channel is bound to a port when the channel is constructed, so
69
- the destination port for a channel must exist before the channel
70
- itself.
71
-
72
- Channels are weak: a channel does not keep the port it is bound to alive.
73
- If a channel attempts to send data to a dead port that data will be silently
74
- dropped.
75
-
76
- Channels may be duplicated and themselves transmitted over other channels.
77
- */
55
+ #[ doc(
56
+ brief = "A communication endpoint that can send messages. \
57
+ Channels send messages to ports.",
58
+ desc = "Each channel is bound to a port when the channel is \
59
+ constructed, so the destination port for a channel \
60
+ must exist before the channel itself. \
61
+ Channels are weak: a channel does not keep the port it \
62
+ is bound to alive. If a channel attempts to send data \
63
+ to a dead port that data will be silently dropped. \
64
+ Channels may be duplicated and themselves transmitted \
65
+ over other channels."
66
+ ) ]
78
67
tag chan<T : send> {
79
68
chan_t ( task:: task, port_id) ;
80
69
}
@@ -92,27 +81,21 @@ resource port_ptr<T: send>(po: *rustrt::rust_port) {
92
81
rustrt:: del_port ( po) ;
93
82
}
94
83
95
- /*
96
- Type: port
97
-
98
- A communication endpoint that can receive messages. Ports receive
99
- messages from channels.
100
-
101
- Each port has a unique per-task identity and may not be replicated or
102
- transmitted. If a port value is copied, both copies refer to the same port.
103
-
104
- Ports may be associated with multiple <chan>s.
105
- */
84
+ #[ doc(
85
+ brief = "A communication endpoint that can receive messages. \
86
+ Ports receive messages from channels.",
87
+ desc = "Each port has a unique per-task identity and may not \
88
+ be replicated or transmitted. If a port value is \
89
+ copied, both copies refer to the same port. \
90
+ Ports may be associated with multiple <chan>s."
91
+ ) ]
106
92
tag port<T : send> { port_t ( @port_ptr<T >) ; }
107
93
108
- /*
109
- Function: send
110
-
111
- Sends data over a channel.
112
-
113
- The sent data is moved into the channel, whereupon the caller loses access
114
- to it.
115
- */
94
+ #[ doc(
95
+ brief = "Sends data over a channel. The sent data is moved \
96
+ into the channel, whereupon the caller loses \
97
+ access to it."
98
+ ) ]
116
99
fn send< T : send > ( ch : chan < T > , -data : T ) {
117
100
let chan_t( t, p) = ch;
118
101
let res = rustrt:: chan_id_send ( sys:: get_type_desc :: < T > ( ) , t, p, data) ;
@@ -123,26 +106,23 @@ fn send<T: send>(ch: chan<T>, -data: T) {
123
106
task:: yield ( ) ;
124
107
}
125
108
126
- /*
127
- Function: port
128
-
129
- Constructs a port.
130
- */
109
+ #[ doc(
110
+ brief = "Constructs a port."
111
+ ) ]
131
112
fn port < T : send > ( ) -> port < T > {
132
113
port_t ( @port_ptr ( rustrt:: new_port ( sys:: size_of :: < T > ( ) ) ) )
133
114
}
134
115
135
- /*
136
- Function: recv
137
-
138
- Receive from a port.
139
-
140
- If no data is available on the port then the task will block until data
141
- becomes available.
142
- */
116
+ #[ doc(
117
+ brief = "Receive from a port. \
118
+ If no data is available on the port then the task will \
119
+ block until data becomes available."
120
+ ) ]
143
121
fn recv < T : send > ( p : port < T > ) -> T { recv_ ( * * * p) }
144
122
145
- // Receive on a raw port pointer
123
+ #[ doc(
124
+ brief = "Receive on a raw port pointer"
125
+ ) ]
146
126
fn recv_ < T : send > ( p : * rustrt:: rust_port ) -> T {
147
127
// FIXME: Due to issue 1185 we can't use a return pointer when
148
128
// calling C code, and since we can't create our own return
@@ -169,13 +149,10 @@ fn recv_<T: send>(p: *rustrt::rust_port) -> T {
169
149
ret res;
170
150
}
171
151
172
- /*
173
- Function: chan
174
-
175
- Constructs a channel.
176
-
177
- The channel is bound to the port used to construct it.
178
- */
152
+ #[ doc(
153
+ brief = "Constructs a channel. The channel is bound to the \
154
+ port used to construct it."
155
+ ) ]
179
156
fn chan < T : send > ( p : port < T > ) -> chan < T > {
180
157
chan_t ( task:: get_task ( ) , rustrt:: get_port_id ( * * * p) )
181
158
}
0 commit comments