Skip to content

Commit 7678d47

Browse files
committed
---
yaml --- r: 11653 b: refs/heads/master c: 4c4a232 h: refs/heads/master i: 11651: e0ff0e9 v: v3
1 parent 8818626 commit 7678d47

File tree

8 files changed

+24
-21
lines changed

8 files changed

+24
-21
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: 0a5603cb58bdc66ad6b6a030e4e98ebeb3c13721
2+
refs/heads/master: 4c4a2320eb9620dbc68a264ce64ee1f233dd977d
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 4a81779abd786ff22d71434c6d9a5917ea4cdfff
55
refs/heads/try: 2898dcc5d97da9427ac367542382b6239d9c0bbf

trunk/src/rt/rust_builtin.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,7 @@ extern "C" CDECL void
492492
del_port(rust_port *port) {
493493
rust_task *task = rust_task_thread::get_task();
494494
LOG(task, comm, "del_port(0x%" PRIxPTR ")", (uintptr_t) port);
495-
A(task->thread, port->ref_count == 1, "Expected port ref_count == 1");
495+
A(task->thread, port->get_ref_count() == 1, "Expected port ref_count == 1");
496496
port->deref();
497497
}
498498

@@ -522,7 +522,6 @@ chan_id_send(type_desc *t, rust_task_id target_task_id,
522522
rust_port *port = target_task->get_port_by_id(target_port_id);
523523
if(port) {
524524
port->send(sptr);
525-
scoped_lock with(target_task->port_lock);
526525
port->deref();
527526
sent = true;
528527
} else {

trunk/src/rt/rust_internal.h

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -104,15 +104,20 @@ static size_t const BUF_BYTES = 2048;
104104
void ref() { ++ref_count; } \
105105
void deref() { if (--ref_count == 0) { dtor; } }
106106

107-
#define RUST_ATOMIC_REFCOUNT() \
108-
private: \
109-
intptr_t ref_count; \
110-
public: \
111-
void ref() { \
112-
intptr_t old = sync::increment(ref_count); \
113-
assert(old > 0); \
114-
} \
115-
void deref() { if(0 == sync::decrement(ref_count)) { delete_this(); } }
107+
#define RUST_ATOMIC_REFCOUNT() \
108+
private: \
109+
intptr_t ref_count; \
110+
public: \
111+
void ref() { \
112+
intptr_t old = sync::increment(ref_count); \
113+
assert(old > 0); \
114+
} \
115+
void deref() { if(0 == sync::decrement(ref_count)) { delete_this(); } } \
116+
intptr_t get_ref_count() { \
117+
sync::increment(ref_count); \
118+
intptr_t current = sync::decrement(ref_count); \
119+
return current; \
120+
}
116121

117122
template <typename T> struct task_owned {
118123
inline void *operator new(size_t size, rust_task *task, const char *tag);

trunk/src/rt/rust_port.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ void rust_port::detach() {
2525
// FIXME: Busy waiting until we're the only ref
2626
bool done = false;
2727
while (!done) {
28-
scoped_lock with(task->port_lock);
29-
done = ref_count == 1;
28+
done = get_ref_count() == 1;
3029
}
3130
}
3231

trunk/src/rt/rust_port.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
class rust_port : public kernel_owned<rust_port>, public rust_cond {
77
public:
8-
RUST_REFCOUNTED(rust_port)
8+
RUST_ATOMIC_REFCOUNT();
99

1010
rust_port_id id;
1111

@@ -18,6 +18,8 @@ class rust_port : public kernel_owned<rust_port>, public rust_cond {
1818

1919
rust_port(rust_task *task, size_t unit_sz);
2020
~rust_port();
21+
void delete_this() { delete this; }
22+
2123
void log_state();
2224
void send(void *sptr);
2325
void receive(void *dptr, uintptr_t *yield);

trunk/src/rt/rust_port_selector.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ void
6969
rust_port_selector::msg_sent_on(rust_port *port) {
7070
rust_task *task = port->task;
7171

72-
I(task->thread, !task->port_lock.lock_held_by_current_thread());
7372
I(task->thread, !port->lock.lock_held_by_current_thread());
7473
I(task->thread, !rendezvous_lock.lock_held_by_current_thread());
7574

trunk/src/rt/rust_task.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -516,7 +516,6 @@ rust_task::notify(bool success) {
516516
msg.result = !success ? tr_failure : tr_success;
517517

518518
target_port->send(&msg);
519-
scoped_lock with(target_task->port_lock);
520519
target_port->deref();
521520
}
522521
target_task->deref();

trunk/src/rt/rust_task.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,6 @@ rust_task : public kernel_owned<rust_task>, rust_cond
8989

9090
bool propagate_failure;
9191

92-
// Protects port_table
93-
lock_and_signal port_lock;
94-
hash_map<rust_port_id, rust_port *> port_table;
95-
9692
rust_obstack dynastack;
9793

9894
uint32_t cc_counter;
@@ -104,6 +100,10 @@ rust_task : public kernel_owned<rust_task>, rust_cond
104100

105101
private:
106102

103+
// Protects port_table
104+
lock_and_signal port_lock;
105+
hash_map<rust_port_id, rust_port *> port_table;
106+
107107
// Protects state, cond, cond_name
108108
lock_and_signal state_lock;
109109
rust_task_list *state;

0 commit comments

Comments
 (0)