Skip to content

Commit 2c3befa

Browse files
committed
Touch up style a bit in fibers implementation
1 parent 70cbe92 commit 2c3befa

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

src/lib.rs

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,9 @@ cfg_if! {
200200

201201
cfg_if! {
202202
if #[cfg(windows)] {
203+
use std::ptr;
204+
use std::io;
205+
203206
use winapi::shared::basetsd::*;
204207
use winapi::shared::minwindef::{LPVOID, BOOL};
205208
use winapi::shared::ntdef::*;
@@ -264,18 +267,22 @@ cfg_if! {
264267
// to the current stack. Threads coverted to fibers still act like
265268
// regular threads, but they have associated fiber data. We later
266269
// convert it back to a regular thread and free the fiber data.
267-
ConvertThreadToFiber(0i32 as _)
270+
ConvertThreadToFiber(ptr::null_mut())
268271
}
269272
},
270273
};
271-
if info.parent_fiber == 0i32 as _ {
274+
if info.parent_fiber.is_null() {
272275
// We don't have a handle to the fiber, so we can't switch back
273-
panic!("unable to convert thread to fiber");
276+
panic!("unable to convert thread to fiber: {}", io::Error::last_os_error());
274277
}
275278

276-
let fiber = CreateFiber(stack_size as _, Some(fiber_proc), &mut info as *mut FiberInfo as *mut _);
277-
if fiber == 0i32 as _ {
278-
panic!("unable to allocate fiber");
279+
let fiber = CreateFiber(
280+
stack_size as SIZE_T,
281+
Some(fiber_proc),
282+
&mut info as *mut FiberInfo as *mut _,
283+
);
284+
if fiber.is_null() {
285+
panic!("unable to allocate fiber: {}", io::Error::last_os_error());
279286
}
280287

281288
// Switch to the fiber we created. This changes stacks and starts executing
@@ -288,7 +295,9 @@ cfg_if! {
288295
// If we started out on a non-fiber thread, we converted that thread to a fiber.
289296
// Here we convert back.
290297
if !was_fiber {
291-
ConvertFiberToThread();
298+
if ConvertFiberToThread() == 0 {
299+
panic!("unable to convert back to thread: {}", io::Error::last_os_error());
300+
}
292301
}
293302

294303
if let Err(payload) = info.result.unwrap() {

0 commit comments

Comments
 (0)