Skip to content

Fibers: adds internal version=ucontext_Posix #21368

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 30 additions & 28 deletions druntime/src/core/thread/fiber/package.d
Original file line number Diff line number Diff line change
Expand Up @@ -153,15 +153,17 @@ package
version (AsmX86_64_Posix) {} else
version (AsmExternal) {} else
{
// NOTE: The ucontext implementation requires architecture specific
// data definitions to operate so testing for it must be done
// by checking for the existence of ucontext_t rather than by
// a version identifier. Please note that this is considered
// an obsolescent feature according to the POSIX spec, so a
// custom solution is still preferred.
import core.sys.posix.ucontext : getcontext, makecontext, MINSIGSTKSZ, swapcontext, ucontext_t;
version = ucontext_Posix;
}
}

version (ucontext_Posix)
{
// NOTE: Please note that ucontext is considered an obsolescent
// feature according to the POSIX spec, so a custom
// solution is still preferred.
import core.sys.posix.ucontext : getcontext, makecontext, MINSIGSTKSZ, swapcontext, ucontext_t;
}
}

///////////////////////////////////////////////////////////////////////////////
Expand All @@ -188,7 +190,16 @@ package
// default stack created by Fiber.initStack or the initial
// switch into a new context will fail.

version (AsmX86_Windows)
version (ucontext_Posix)
{
Fiber cfib = Fiber.getThis();
void* ucur = cfib.m_ucur;

*oldp = &ucur;
swapcontext( **(cast(ucontext_t***) oldp),
*(cast(ucontext_t**) newp) );
}
else version (AsmX86_Windows)
{
asm pure nothrow @nogc
{
Expand Down Expand Up @@ -363,15 +374,6 @@ package
jmp RCX;
}
}
else static if ( __traits( compiles, ucontext_t ) )
{
Fiber cfib = Fiber.getThis();
void* ucur = cfib.m_ucur;

*oldp = &ucur;
swapcontext( **(cast(ucontext_t***) oldp),
*(cast(ucontext_t**) newp) );
}
else
static assert(0, "Not implemented");
}
Expand Down Expand Up @@ -866,7 +868,17 @@ protected:
}
}

version (AsmX86_Windows)
version (ucontext_Posix)
{
getcontext( &m_utxt );
m_utxt.uc_stack.ss_sp = m_pmem;
m_utxt.uc_stack.ss_size = m_size;
makecontext( &m_utxt, &fiber_entryPoint, 0 );
// NOTE: If ucontext is being used then the top of the stack will
// be a pointer to the ucontext_t struct for that fiber.
push( cast(size_t) &m_utxt );
}
else version (AsmX86_Windows)
{
version (StackGrowsDown) {} else static assert( false );

Expand Down Expand Up @@ -1232,16 +1244,6 @@ protected:
*/
pstack += int.sizeof * 1;
}
else static if ( __traits( compiles, ucontext_t ) )
{
getcontext( &m_utxt );
m_utxt.uc_stack.ss_sp = m_pmem;
m_utxt.uc_stack.ss_size = m_size;
makecontext( &m_utxt, &fiber_entryPoint, 0 );
// NOTE: If ucontext is being used then the top of the stack will
// be a pointer to the ucontext_t struct for that fiber.
push( cast(size_t) &m_utxt );
}
else
static assert(0, "Not implemented");
}
Expand Down
Loading