Skip to content

Commit 400b621

Browse files
author
Eric Holk
committed
---
yaml --- r: 4679 b: refs/heads/master c: 5c67905 h: refs/heads/master i: 4677: 28b22be 4675: 610748c 4671: ccf2fd7 v: v3
1 parent 62e859c commit 400b621

File tree

5 files changed

+21
-4
lines changed

5 files changed

+21
-4
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: 55c9842e7d16c3313ae12fbcc2d3a80cc9464190
2+
refs/heads/master: 5c6790519b12afae688c87ae3f55ee5eec1a6dcc

trunk/src/rt/rust_internal.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,10 @@ static size_t const BUF_BYTES = 2048;
115115
private: \
116116
intptr_t ref_count; \
117117
public: \
118-
void ref() { sync::increment(ref_count); } \
118+
void ref() { \
119+
intptr_t old = sync::increment(ref_count); \
120+
assert(old > 0); \
121+
} \
119122
void deref() { if(0 == sync::decrement(ref_count)) { delete this; } }
120123

121124
template <typename T> struct rc_base {

trunk/src/rt/rust_kernel.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,17 @@ rust_kernel::get_task_by_id(rust_task_id id) {
160160
rust_task *task = NULL;
161161
// get leaves task unchanged if not found.
162162
task_table.get(id, &task);
163-
if(task) task->ref();
163+
if(task) {
164+
if(task->get_ref_count() == 0) {
165+
// this means the destructor is running, since the destructor
166+
// grabs the kernel lock to unregister the task. Pretend this
167+
// doesn't actually exist.
168+
return NULL;
169+
}
170+
else {
171+
task->ref();
172+
}
173+
}
164174
return task;
165175
}
166176

trunk/src/rt/rust_task.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,10 @@ rust_task : public kernel_owned<rust_task>, rust_cond
169169
rust_port_id register_port(rust_port *port);
170170
void release_port(rust_port_id id);
171171
rust_port *get_port_by_id(rust_port_id id);
172+
173+
// Use this function sparingly. Depending on the ref count is generally
174+
// not at all safe.
175+
intptr_t get_ref_count() const { return ref_count; }
172176
};
173177

174178
//

trunk/src/test/bench/task-perf-spawnalot.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,4 @@ fn main(args: vec[str]) {
2727
task::_spawn(bind f(n));
2828
i += 1u;
2929
}
30-
}
30+
}

0 commit comments

Comments
 (0)