Skip to content

Commit 56a2a8a

Browse files
authored
Merge pull request #1912 from hermit-os/block_on-deadlock
fix(executor): avoid possible deadlock
2 parents 5f7d19f + fc0c5c3 commit 56a2a8a

File tree

1 file changed

+8
-15
lines changed

1 file changed

+8
-15
lines changed

src/executor/mod.rs

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,8 @@ where
169169
{
170170
if let Some(mut guard) = crate::executor::network::NIC.try_lock() {
171171
let delay = if let Ok(nic) = guard.as_nic_mut() {
172+
nic.set_polling_mode(false);
173+
172174
nic.poll_delay(Instant::from_micros_const(now.try_into().unwrap()))
173175
.map(|d| d.total_micros())
174176
} else {
@@ -178,10 +180,6 @@ where
178180
delay.map(|d| crate::arch::processor::get_timer_ticks() + d),
179181
);
180182
}
181-
182-
if let Ok(device) = crate::executor::network::NIC.lock().as_nic_mut() {
183-
device.set_polling_mode(false);
184-
}
185183
}
186184

187185
return t;
@@ -195,6 +193,8 @@ where
195193
{
196194
if let Some(mut guard) = crate::executor::network::NIC.try_lock() {
197195
let delay = if let Ok(nic) = guard.as_nic_mut() {
196+
nic.set_polling_mode(false);
197+
198198
nic.poll_delay(Instant::from_micros_const(now.try_into().unwrap()))
199199
.map(|d| d.total_micros())
200200
} else {
@@ -204,10 +204,6 @@ where
204204
delay.map(|d| crate::arch::processor::get_timer_ticks() + d),
205205
);
206206
}
207-
208-
if let Ok(device) = crate::executor::network::NIC.lock().as_nic_mut() {
209-
device.set_polling_mode(false);
210-
}
211207
}
212208

213209
return Err(Errno::Time);
@@ -217,6 +213,8 @@ where
217213
if backoff.is_completed() {
218214
let delay = if let Some(mut guard) = crate::executor::network::NIC.try_lock() {
219215
if let Ok(nic) = guard.as_nic_mut() {
216+
nic.set_polling_mode(false);
217+
220218
nic.poll_delay(Instant::from_micros_const(now.try_into().unwrap()))
221219
.map(|d| d.total_micros())
222220
} else {
@@ -233,17 +231,12 @@ where
233231
let wakeup_time =
234232
timeout.map(|duration| start + u64::try_from(duration.as_micros()).unwrap());
235233

236-
// allow network interrupts
237-
if let Ok(device) = crate::executor::network::NIC.lock().as_nic_mut() {
238-
device.set_polling_mode(false);
239-
}
240-
241234
// switch to another task
242235
task_notify.wait(wakeup_time);
243236

244237
// restore default values
245-
if let Ok(device) = crate::executor::network::NIC.lock().as_nic_mut() {
246-
device.set_polling_mode(true);
238+
if let Ok(nic) = crate::executor::network::NIC.lock().as_nic_mut() {
239+
nic.set_polling_mode(true);
247240
}
248241

249242
backoff.reset();

0 commit comments

Comments
 (0)