Ensure thread_preSuspend and thread_postSuspend can be called in detached threads.

This commit is contained in:
Amaury Séchet 2024-09-25 14:54:03 +00:00 committed by The Dlang Bot
parent ff0d824b80
commit 88a287036d

View file

@ -2197,27 +2197,37 @@ else version (Posix)
__gshared sem_t suspendCount;
extern (C) void thread_preSuspend( void* sp ) nothrow {
extern (C) bool thread_preSuspend( void* sp ) nothrow {
// NOTE: Since registers are being pushed and popped from the
// stack, any other stack data used by this function should
// be gone before the stack cleanup code is called below.
Thread obj = Thread.getThis();
assert(obj !is null);
if (obj is null)
{
return false;
}
if ( !obj.m_lock )
{
obj.m_curr.tstack = sp;
}
return true;
}
extern (C) void thread_postSuspend() nothrow {
extern (C) bool thread_postSuspend() nothrow {
Thread obj = Thread.getThis();
assert(obj !is null);
if (obj is null)
{
return false;
}
if ( !obj.m_lock )
{
obj.m_curr.tstack = obj.m_curr.bstack;
}
return true;
}
extern (C) void thread_suspendHandler( int sig ) nothrow
@ -2229,8 +2239,14 @@ else version (Posix)
{
void op(void* sp) nothrow
{
thread_preSuspend(getStackTop());
scope(exit) thread_postSuspend();
bool supported = thread_preSuspend(getStackTop());
assert(supported, "Tried to suspend a detached tread!");
scope(exit)
{
supported = thread_postSuspend();
assert(supported, "Tried to suspend a detached tread!");
}
sigset_t sigres = void;
int status;