@@ -153,15 +153,17 @@ 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: Please note that ucontext is considered an obsolescent
163+ // feature according to the POSIX spec, so a custom
164+ // solution is still preferred.
165+ import core.sys.posix.ucontext : getcontext, makecontext, MINSIGSTKSZ , swapcontext, ucontext_t;
166+ }
165167}
166168
167169// /////////////////////////////////////////////////////////////////////////////
@@ -188,7 +190,16 @@ package
188190 // default stack created by Fiber.initStack or the initial
189191 // switch into a new context will fail.
190192
191- version (AsmX86_Windows)
193+ version (ucontext_Posix)
194+ {
195+ Fiber cfib = Fiber .getThis();
196+ void * ucur = cfib.m_ucur;
197+
198+ * oldp = &ucur;
199+ swapcontext( ** (cast (ucontext_t*** ) oldp),
200+ * (cast (ucontext_t** ) newp) );
201+ }
202+ else version (AsmX86_Windows)
192203 {
193204 asm pure nothrow @nogc
194205 {
@@ -363,15 +374,6 @@ package
363374 jmp RCX ;
364375 }
365376 }
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- }
375377 else
376378 static assert (0 , " Not implemented" );
377379 }
@@ -876,7 +878,19 @@ protected:
876878 }
877879 }
878880
879- version (AsmX86_Windows)
881+ version (ucontext_Posix)
882+ {
883+ const status = getcontext( &m_utxt );
884+ assert ( status == 0 );
885+
886+ m_utxt.uc_stack.ss_sp = m_pmem;
887+ m_utxt.uc_stack.ss_size = m_size;
888+ makecontext( &m_utxt, &fiber_entryPoint, 0 );
889+ // NOTE: If ucontext is being used then the top of the stack will
890+ // be a pointer to the ucontext_t struct for that fiber.
891+ push( cast (size_t ) &m_utxt );
892+ }
893+ else version (AsmX86_Windows)
880894 {
881895 version (StackGrowsDown) {} else static assert ( false );
882896
@@ -1251,18 +1265,6 @@ protected:
12511265 */
12521266 pstack += int .sizeof * 1 ;
12531267 }
1254- else static if ( __traits( compiles, ucontext_t ) )
1255- {
1256- const status = getcontext( &m_utxt );
1257- assert ( status == 0 );
1258-
1259- m_utxt.uc_stack.ss_sp = m_pmem;
1260- m_utxt.uc_stack.ss_size = m_size;
1261- makecontext( &m_utxt, &fiber_entryPoint, 0 );
1262- // NOTE: If ucontext is being used then the top of the stack will
1263- // be a pointer to the ucontext_t struct for that fiber.
1264- push( cast (size_t ) &m_utxt );
1265- }
12661268 else
12671269 static assert (0 , " Not implemented" );
12681270 }
0 commit comments