aboutsummaryrefslogtreecommitdiff
path: root/src/rt/rust_chan.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/rt/rust_chan.cpp')
-rw-r--r--src/rt/rust_chan.cpp34
1 files changed, 34 insertions, 0 deletions
diff --git a/src/rt/rust_chan.cpp b/src/rt/rust_chan.cpp
new file mode 100644
index 00000000..38f93a7d
--- /dev/null
+++ b/src/rt/rust_chan.cpp
@@ -0,0 +1,34 @@
+
+#include "rust_internal.h"
+#include "rust_chan.h"
+
+rust_chan::rust_chan(rust_task *task, rust_port *port) :
+ task(task),
+ port(port),
+ buffer(task->dom, port->unit_sz),
+ token(this)
+{
+ if (port)
+ port->chans.push(this);
+}
+
+rust_chan::~rust_chan()
+{
+ if (port) {
+ if (token.pending())
+ token.withdraw();
+ port->chans.swapdel(this);
+ }
+}
+
+void
+rust_chan::disassociate()
+{
+ I(task->dom, port);
+
+ if (token.pending())
+ token.withdraw();
+
+ // Delete reference to the port/
+ port = NULL;
+}