Skip to content

Commit 8ff234c

Browse files
committed
---
yaml --- r: 651 b: refs/heads/master c: 388f8ce h: refs/heads/master i: 649: e118ffc 647: eec181f v: v3
1 parent 63c8cbd commit 8ff234c

File tree

4 files changed

+55
-54
lines changed

4 files changed

+55
-54
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: 37cc13960744ad8a7a828da1db6edd4ced454353
2+
refs/heads/master: 388f8ce520b16d73bf682cf6bf3f714bcc35b49d

trunk/src/rt/rust_kernel.cpp

Lines changed: 42 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -12,61 +12,78 @@ rust_kernel::rust_kernel(rust_srv *srv) :
1212

1313
rust_handle<rust_dom> *
1414
rust_kernel::create_domain(const rust_crate *crate, const char *name) {
15+
LOCK(_kernel_lock);
1516
rust_message_queue *message_queue =
1617
new (this) rust_message_queue(_srv, this);
1718
rust_srv *srv = _srv->clone();
1819
rust_dom *dom =
1920
new (this) rust_dom(this, message_queue, srv, crate, name);
20-
rust_handle<rust_dom> *handle = get_dom_handle(dom);
21+
rust_handle<rust_dom> *handle = internal_get_dom_handle(dom);
2122
message_queue->associate(handle);
2223
domains.append(dom);
2324
message_queues.append(message_queue);
25+
UNLOCK(_kernel_lock);
2426
return handle;
2527
}
2628

2729
void
2830
rust_kernel::destroy_domain(rust_dom *dom) {
31+
LOCK(_kernel_lock);
2932
log(rust_log::KERN, "deleting domain: " PTR ", index: %d, domains %d",
3033
dom, dom->list_index, domains.length());
3134
domains.remove(dom);
3235
dom->message_queue->disassociate();
3336
rust_srv *srv = dom->srv;
3437
delete dom;
3538
delete srv;
39+
UNLOCK(_kernel_lock);
3640
}
3741

3842
rust_handle<rust_dom> *
39-
rust_kernel::get_dom_handle(rust_dom *dom) {
43+
rust_kernel::internal_get_dom_handle(rust_dom *dom) {
4044
rust_handle<rust_dom> *handle = NULL;
41-
if (_dom_handles.get(dom, &handle)) {
42-
return handle;
45+
if (_dom_handles.get(dom, &handle) == false) {
46+
handle =
47+
new (this) rust_handle<rust_dom>(this, dom->message_queue, dom);
48+
_dom_handles.put(dom, handle);
4349
}
44-
handle = new (this) rust_handle<rust_dom>(this, dom->message_queue, dom);
45-
_dom_handles.put(dom, handle);
50+
return handle;
51+
}
52+
53+
rust_handle<rust_dom> *
54+
rust_kernel::get_dom_handle(rust_dom *dom) {
55+
LOCK(_kernel_lock);
56+
rust_handle<rust_dom> *handle = internal_get_dom_handle(dom);
57+
UNLOCK(_kernel_lock);
4658
return handle;
4759
}
4860

4961
rust_handle<rust_task> *
5062
rust_kernel::get_task_handle(rust_task *task) {
63+
LOCK(_kernel_lock);
5164
rust_handle<rust_task> *handle = NULL;
52-
if (_task_handles.get(task, &handle)) {
53-
return handle;
65+
if (_task_handles.get(task, &handle) == false) {
66+
handle =
67+
new (this) rust_handle<rust_task>(this, task->dom->message_queue,
68+
task);
69+
_task_handles.put(task, handle);
5470
}
55-
handle = new (this) rust_handle<rust_task>(this, task->dom->message_queue,
56-
task);
57-
_task_handles.put(task, handle);
71+
UNLOCK(_kernel_lock);
5872
return handle;
5973
}
6074

6175
rust_handle<rust_port> *
6276
rust_kernel::get_port_handle(rust_port *port) {
77+
PLOCK(_kernel_lock);
6378
rust_handle<rust_port> *handle = NULL;
64-
if (_port_handles.get(port, &handle)) {
65-
return handle;
79+
if (_port_handles.get(port, &handle) == false) {
80+
handle =
81+
new (this) rust_handle<rust_port>(this,
82+
port->task->dom->message_queue,
83+
port);
84+
_port_handles.put(port, handle);
6685
}
67-
handle = new (this) rust_handle<rust_port>(this,
68-
port->task->dom->message_queue, port);
69-
_port_handles.put(port, handle);
86+
PUNLOCK(_kernel_lock);
7087
return handle;
7188
}
7289

@@ -76,6 +93,7 @@ rust_kernel::join_all_domains() {
7693
while (domains.length() > 0) {
7794
sync::yield();
7895
}
96+
log(rust_log::KERN, "joined domains");
7997
}
8098

8199
void
@@ -92,30 +110,8 @@ rust_kernel::log_all_domain_state() {
92110
bool
93111
rust_kernel::is_deadlocked() {
94112
return false;
95-
// _lock.lock();
96-
// if (domains.length() != 1) {
97-
// // We can only check for deadlocks when only one domain exists.
98-
// return false;
99-
// }
100-
//
101-
// if (domains[0]->running_tasks.length() != 0) {
102-
// // We are making progress and therefore we are not deadlocked.
103-
// return false;
104-
// }
105-
//
106-
// if (domains[0]->message_queue->is_empty() &&
107-
// domains[0]->blocked_tasks.length() > 0) {
108-
// // We have no messages to process, no running tasks to schedule
109-
// // and some blocked tasks therefore we are likely in a deadlock.
110-
// log_all_domain_state();
111-
// return true;
112-
// }
113-
//
114-
// _lock.unlock();
115-
// return false;
116113
}
117114

118-
119115
void
120116
rust_kernel::log(uint32_t type_bits, char const *fmt, ...) {
121117
char buf[256];
@@ -130,7 +126,7 @@ rust_kernel::log(uint32_t type_bits, char const *fmt, ...) {
130126

131127
void
132128
rust_kernel::pump_message_queues() {
133-
message_queues.global.lock();
129+
LOCK(_kernel_lock);
134130
for (size_t i = 0; i < message_queues.length(); i++) {
135131
rust_message_queue *queue = message_queues[i];
136132
if (queue->is_associated() == false) {
@@ -141,13 +137,14 @@ rust_kernel::pump_message_queues() {
141137
}
142138
}
143139
}
144-
message_queues.global.unlock();
140+
UNLOCK(_kernel_lock);
145141
}
146142

147143
void
148144
rust_kernel::start_kernel_loop() {
149145
while (_interrupt_kernel_loop == false) {
150146
pump_message_queues();
147+
sync::yield();
151148
}
152149
}
153150

@@ -160,6 +157,7 @@ rust_kernel::run() {
160157

161158
void
162159
rust_kernel::terminate_kernel_loop() {
160+
log(rust_log::KERN, "terminating kernel loop");
163161
_interrupt_kernel_loop = true;
164162
join();
165163
}
@@ -177,10 +175,14 @@ rust_kernel::~rust_kernel() {
177175
// messages.
178176
pump_message_queues();
179177

178+
log(rust_log::KERN, "freeing handles");
179+
180180
free_handles(_task_handles);
181181
free_handles(_port_handles);
182182
free_handles(_dom_handles);
183183

184+
log(rust_log::KERN, "freeing queues");
185+
184186
rust_message_queue *queue = NULL;
185187
while (message_queues.pop(&queue)) {
186188
K(_srv, queue->is_empty(), "Kernel message queue should be empty "

trunk/src/rt/rust_kernel.h

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@ rust_handle :
3232
}
3333
};
3434

35+
#define LOCK(x) x.lock();
36+
#define UNLOCK(x) x.unlock();
37+
38+
#define PLOCK(x) printf("LOCKING @ %d\n", __LINE__); x.lock();
39+
#define PUNLOCK(x) x.unlock(); printf("UNLOCKED @ %d\n", __LINE__);
40+
3541
/**
3642
* A global object shared by all thread domains. Most of the data structures
3743
* in this class are synchronized since they are accessed from multiple
@@ -55,20 +61,19 @@ class rust_kernel : public rust_thread {
5561
void start_kernel_loop();
5662
bool volatile _interrupt_kernel_loop;
5763

58-
/**
59-
* Lock for the message queue list, so we can safely
60-
*/
61-
spin_lock _message_queues_lock;
64+
spin_lock _kernel_lock;
6265

6366
void terminate_kernel_loop();
6467
void pump_message_queues();
6568

69+
rust_handle<rust_dom> *internal_get_dom_handle(rust_dom *dom);
70+
6671
public:
6772

6873
/**
6974
* List of domains that are currently executing.
7075
*/
71-
synchronized_indexed_list<rust_dom> domains;
76+
indexed_list<rust_dom> domains;
7277

7378
/**
7479
* Message queues are kernel objects and are associated with domains.
@@ -79,7 +84,7 @@ class rust_kernel : public rust_thread {
7984
* Although the message_queues list is synchronized, each individual
8085
* message queue is lock free.
8186
*/
82-
synchronized_indexed_list<rust_message_queue> message_queues;
87+
indexed_list<rust_message_queue> message_queues;
8388

8489
rust_handle<rust_dom> *get_dom_handle(rust_dom *dom);
8590
rust_handle<rust_task> *get_task_handle(rust_task *task);

trunk/src/rt/util/synchronized_indexed_list.h

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,8 @@
66
template<typename T> class synchronized_indexed_list :
77
public indexed_list<T> {
88
spin_lock _lock;
9-
public:
10-
/**
11-
* Clients can use this global lock that is associated with the list to
12-
* perform more coarse grained locking. Internally, the synchronized list
13-
* doesn'tactually make any use of this lock.
14-
*/
15-
spin_lock global;
169

10+
public:
1711
synchronized_indexed_list(memory_region *region) :
1812
indexed_list<T>(region) {
1913
// Nop.

0 commit comments

Comments
 (0)