Skip to content

Commit b1ff001

Browse files
committed
ucontext facility can be enforced by version=ucontext_Posix
Available only on Posix platforms. Useful for testing purposes.
1 parent d3ce2ff commit b1ff001

File tree

1 file changed

+33
-28
lines changed

1 file changed

+33
-28
lines changed

druntime/src/core/thread/fiber/package.d

Lines changed: 33 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -153,15 +153,20 @@ package
153153
version (AsmX86_64_Posix) {} else
154154
version (AsmExternal) {} else
155155
{
156-
// NOTE: The ucontext implementation requires architecture specific
157-
// data definitions to operate so testing for it must be done
158-
// by checking for the existence of ucontext_t rather than by
159-
// a version identifier. Please note that this is considered
160-
// an obsolescent feature according to the POSIX spec, so a
161-
// custom solution is still preferred.
162-
import core.sys.posix.ucontext : getcontext, makecontext, MINSIGSTKSZ, swapcontext, ucontext_t;
156+
version = ucontext_Posix;
163157
}
164158
}
159+
160+
version (ucontext_Posix)
161+
{
162+
// NOTE: The ucontext implementation requires architecture specific
163+
// data definitions to operate so testing for it must be done
164+
// by checking for the existence of ucontext_t.
165+
// Please note that ucontext is considered an obsolescent
166+
// feature according to the POSIX spec, so a custom
167+
// solution is still preferred.
168+
import core.sys.posix.ucontext : getcontext, makecontext, MINSIGSTKSZ, swapcontext, ucontext_t;
169+
}
165170
}
166171

167172
///////////////////////////////////////////////////////////////////////////////
@@ -188,7 +193,16 @@ package
188193
// default stack created by Fiber.initStack or the initial
189194
// switch into a new context will fail.
190195

191-
version (AsmX86_Windows)
196+
version (ucontext_Posix)
197+
{
198+
Fiber cfib = Fiber.getThis();
199+
void* ucur = cfib.m_ucur;
200+
201+
*oldp = &ucur;
202+
swapcontext( **(cast(ucontext_t***) oldp),
203+
*(cast(ucontext_t**) newp) );
204+
}
205+
else version (AsmX86_Windows)
192206
{
193207
asm pure nothrow @nogc
194208
{
@@ -363,15 +377,6 @@ package
363377
jmp RCX;
364378
}
365379
}
366-
else static if ( __traits( compiles, ucontext_t ) )
367-
{
368-
Fiber cfib = Fiber.getThis();
369-
void* ucur = cfib.m_ucur;
370-
371-
*oldp = &ucur;
372-
swapcontext( **(cast(ucontext_t***) oldp),
373-
*(cast(ucontext_t**) newp) );
374-
}
375380
else
376381
static assert(0, "Not implemented");
377382
}
@@ -866,7 +871,17 @@ protected:
866871
}
867872
}
868873

869-
version (AsmX86_Windows)
874+
version (ucontext_Posix)
875+
{
876+
getcontext( &m_utxt );
877+
m_utxt.uc_stack.ss_sp = m_pmem;
878+
m_utxt.uc_stack.ss_size = m_size;
879+
makecontext( &m_utxt, &fiber_entryPoint, 0 );
880+
// NOTE: If ucontext is being used then the top of the stack will
881+
// be a pointer to the ucontext_t struct for that fiber.
882+
push( cast(size_t) &m_utxt );
883+
}
884+
else version (AsmX86_Windows)
870885
{
871886
version (StackGrowsDown) {} else static assert( false );
872887

@@ -1232,16 +1247,6 @@ protected:
12321247
*/
12331248
pstack += int.sizeof * 1;
12341249
}
1235-
else static if ( __traits( compiles, ucontext_t ) )
1236-
{
1237-
getcontext( &m_utxt );
1238-
m_utxt.uc_stack.ss_sp = m_pmem;
1239-
m_utxt.uc_stack.ss_size = m_size;
1240-
makecontext( &m_utxt, &fiber_entryPoint, 0 );
1241-
// NOTE: If ucontext is being used then the top of the stack will
1242-
// be a pointer to the ucontext_t struct for that fiber.
1243-
push( cast(size_t) &m_utxt );
1244-
}
12451250
else
12461251
static assert(0, "Not implemented");
12471252
}

0 commit comments

Comments
 (0)