Skip to content

Commit 0d67572

Browse files
committed
Document some more things
1 parent 76eb767 commit 0d67572

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/lib.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,9 @@ cfg_if! {
239239
if info.parent_fiber == 0i32 as _ {
240240
panic!("unable to convert thread to fiber");
241241
}
242+
// remember the old stack limit
243+
let old_stack_limit = get_stack_limit();
244+
// bump the know stack size in the thread local
242245
set_stack_limit(stack_size);
243246
let fiber = kernel32::CreateFiber(stack_size as _, Some(fiber_proc), &mut info as *mut FiberInfo as *mut _);
244247
if fiber == 0i32 as _ {
@@ -249,6 +252,11 @@ cfg_if! {
249252
// fiber execution finished, we can safely delete it now
250253
kernel32::DeleteFiber(fiber);
251254

255+
// restore the old stack limit
256+
if let Some(old) = old_stack_limit {
257+
set_stack_limit(old);
258+
}
259+
252260
if !was_fiber {
253261
kernel32::ConvertFiberToThread();
254262
}
@@ -262,6 +270,7 @@ cfg_if! {
262270
cfg_if! {
263271
if #[cfg(any(target_arch = "x86_64", target_arch = "x86"))] {
264272
#[inline(always)]
273+
// We cannot know the initial stack size on x86
265274
unsafe fn guess_os_stack_limit() -> Option<usize> {
266275
None
267276
}
@@ -309,6 +318,9 @@ cfg_if! {
309318
libc::pthread_get_stacksize_np(libc::pthread_self()) as usize)
310319
}
311320
} else {
321+
// fallback for other platforms is to always increase the stack if we're on
322+
// the root stack. After we increased the stack once, we know the new stack
323+
// size and don't need this pessimization anymore
312324
unsafe fn guess_os_stack_limit() -> Option<usize> {
313325
None
314326
}

0 commit comments

Comments
 (0)