5
5
6
6
rust_port::rust_port (rust_task *task, size_t unit_sz)
7
7
: ref_count(1 ), kernel(task->kernel), task(task),
8
- unit_sz(unit_sz), writers(task), chans(task) {
8
+ unit_sz(unit_sz), writers(task) {
9
9
10
10
LOG (task, comm,
11
11
" new rust_port(task=0x%" PRIxPTR " , unit_sz=%d) -> port=0x%"
@@ -14,47 +14,37 @@ rust_port::rust_port(rust_task *task, size_t unit_sz)
14
14
id = task->register_port (this );
15
15
remote_chan = new (task->kernel , " rust_chan" )
16
16
rust_chan (task->kernel , this , unit_sz);
17
+ remote_chan->ref ();
18
+ remote_chan->port = this ;
17
19
}
18
20
19
21
rust_port::~rust_port () {
20
22
LOG (task, comm, " ~rust_port 0x%" PRIxPTR, (uintptr_t ) this );
21
23
22
- // Disassociate channels from this port.
23
- while (chans.is_empty () == false ) {
24
+ {
24
25
scoped_lock with (lock);
25
- rust_chan *chan = chans.peek ();
26
- chan->disassociate ();
26
+ remote_chan->port = NULL ;
27
+ remote_chan->deref ();
28
+ remote_chan = NULL ;
27
29
}
28
30
29
- remote_chan->deref ();
30
- remote_chan = NULL ;
31
-
32
31
task->release_port (id);
33
32
}
34
33
35
34
bool rust_port::receive (void *dptr) {
36
- for (uint32_t i = 0 ; i < chans.length (); i++) {
37
- rust_chan *chan = chans[i];
38
- if (chan->buffer .is_empty () == false ) {
39
- chan->buffer .dequeue (dptr);
40
- LOG (task, comm, " <=== read data ===" );
41
- return true ;
42
- }
35
+ if (remote_chan->buffer .is_empty () == false ) {
36
+ remote_chan->buffer .dequeue (dptr);
37
+ LOG (task, comm, " <=== read data ===" );
38
+ return true ;
43
39
}
44
40
return false ;
45
41
}
46
42
47
43
void rust_port::log_state () {
48
44
LOG (task, comm,
49
- " rust_port: 0x%" PRIxPTR " , associated channel(s): %d" ,
50
- this , chans.length ());
51
- for (uint32_t i = 0 ; i < chans.length (); i++) {
52
- rust_chan *chan = chans[i];
53
- LOG (task, comm,
54
- " \t chan: 0x%" PRIxPTR " , size: %d" ,
55
- chan,
56
- chan->buffer .size ());
57
- }
45
+ " \t chan: 0x%" PRIxPTR " , size: %d" ,
46
+ remote_chan,
47
+ remote_chan->buffer .size ());
58
48
}
59
49
60
50
//
0 commit comments