Skip to content

Commit e466ef6

Browse files
committed
fixup
1 parent 6bf6010 commit e466ef6

5 files changed

Lines changed: 24 additions & 19 deletions

File tree

crates/stdlib/src/socket.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1106,8 +1106,7 @@ mod _socket {
11061106
if deadline.is_some() || matches!(select, SelectKind::Connect) {
11071107
let interval = deadline.as_ref().map(|d| d.time_until()).transpose()?;
11081108
let sock = self.sock()?;
1109-
let res =
1110-
vm.allow_threads(|| sock_select(&*sock, select, interval));
1109+
let res = vm.allow_threads(|| sock_select(&sock, select, interval));
11111110
match res {
11121111
Ok(true) => return Err(IoOrPyException::Timeout),
11131112
Err(e) if e.kind() == io::ErrorKind::Interrupted => {

crates/vm/src/stdlib/io.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5015,13 +5015,13 @@ mod _io {
50155015

50165016
if let Some(tio) = obj.downcast_ref::<TextIOWrapper>() {
50175017
unsafe { reinit_thread_mutex_after_fork(&tio.data) };
5018-
if let Some(guard) = tio.data.lock() {
5019-
if let Some(ref data) = *guard {
5020-
if let Some(ref decoder) = data.decoder {
5021-
reinit_io_locks(decoder);
5022-
}
5023-
reinit_io_locks(&data.buffer);
5018+
if let Some(guard) = tio.data.lock()
5019+
&& let Some(ref data) = *guard
5020+
{
5021+
if let Some(ref decoder) = data.decoder {
5022+
reinit_io_locks(decoder);
50245023
}
5024+
reinit_io_locks(&data.buffer);
50255025
}
50265026
return;
50275027
}
@@ -5044,7 +5044,6 @@ mod _io {
50445044
if let Some(brw) = obj.downcast_ref::<BufferedRWPair>() {
50455045
unsafe { reinit_thread_mutex_after_fork(&brw.read.data) };
50465046
unsafe { reinit_thread_mutex_after_fork(&brw.write.data) };
5047-
return;
50485047
}
50495048
}
50505049

crates/vm/src/stdlib/thread.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -637,7 +637,7 @@ pub(crate) mod _thread {
637637
let (lock, cvar) = &*done_event;
638638
let mut done = lock.lock();
639639
while !*done {
640-
cvar.wait(&mut done);
640+
vm.allow_threads(|| cvar.wait(&mut done));
641641
}
642642
}
643643
None => break, // No more threads to wait on
@@ -1178,14 +1178,14 @@ pub(crate) mod _thread {
11781178

11791179
while !*done {
11801180
if let Some(timeout) = timeout_duration {
1181-
let result = cvar.wait_for(&mut done, timeout);
1181+
let result = vm.allow_threads(|| cvar.wait_for(&mut done, timeout));
11821182
if result.timed_out() && !*done {
11831183
// Timeout occurred and done is still false
11841184
return Ok(());
11851185
}
11861186
} else {
11871187
// Infinite wait
1188-
cvar.wait(&mut done);
1188+
vm.allow_threads(|| cvar.wait(&mut done));
11891189
}
11901190
}
11911191
drop(done);
@@ -1206,7 +1206,7 @@ pub(crate) mod _thread {
12061206
let (lock, cvar) = &*self.done_event;
12071207
let mut done = lock.lock();
12081208
while !*done {
1209-
cvar.wait(&mut done);
1209+
vm.allow_threads(|| cvar.wait(&mut done));
12101210
}
12111211
return Ok(());
12121212
}
@@ -1221,7 +1221,7 @@ pub(crate) mod _thread {
12211221
// Perform the actual join outside the lock
12221222
if let Some(handle) = join_handle {
12231223
// Ignore the result - panics in spawned threads are already handled
1224-
let _ = handle.join();
1224+
let _ = vm.allow_threads(|| handle.join());
12251225
}
12261226

12271227
// Mark as joined and clear joining flag

crates/vm/src/vm/mod.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,13 @@ pub struct StopTheWorldStats {
176176
pub detach_wait_yields: u64,
177177
}
178178

179+
#[cfg(all(unix, feature = "threading"))]
180+
impl Default for StopTheWorldState {
181+
fn default() -> Self {
182+
Self::new()
183+
}
184+
}
185+
179186
#[cfg(all(unix, feature = "threading"))]
180187
impl StopTheWorldState {
181188
pub const fn new() -> Self {
@@ -273,7 +280,7 @@ impl StopTheWorldState {
273280
let guard = self.notify_mutex.lock().unwrap();
274281
let _ = self
275282
.notify_cv
276-
.wait_timeout(guard, std::time::Duration::from_millis(1));
283+
.wait_timeout(guard, core::time::Duration::from_millis(1));
277284
}
278285
if polls != 0 {
279286
self.stats_poll_loops.fetch_add(polls, Ordering::Relaxed);
@@ -459,9 +466,9 @@ pub(super) fn stw_trace(msg: core::fmt::Arguments<'_>) {
459466
buf: [0u8; 512],
460467
len: 0,
461468
};
462-
let _ = write!(
469+
let _ = writeln!(
463470
&mut out,
464-
"[rp-stw tid={}] {}\n",
471+
"[rp-stw tid={}] {}",
465472
crate::stdlib::thread::get_ident(),
466473
msg
467474
);

crates/vm/src/vm/thread.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ fn wait_while_suspended(slot: &ThreadSlot) -> u64 {
139139
let mut wait_yields = 0u64;
140140
while slot.state.load(Ordering::Acquire) == THREAD_SUSPENDED {
141141
wait_yields = wait_yields.saturating_add(1);
142-
std::thread::park_timeout(std::time::Duration::from_micros(50));
142+
std::thread::park_timeout(core::time::Duration::from_micros(50));
143143
}
144144
wait_yields
145145
}
@@ -265,7 +265,7 @@ pub fn allow_threads<R>(vm: &VirtualMachine, f: impl FnOnce() -> R) -> R {
265265
}
266266

267267
detach_thread(vm);
268-
let reattach_guard = scopeguard::guard(vm, |vm| attach_thread(vm));
268+
let reattach_guard = scopeguard::guard(vm, attach_thread);
269269
let result = f();
270270
drop(reattach_guard);
271271
result

0 commit comments

Comments
 (0)