mirror of
https://github.com/dlang/dmd.git
synced 2025-04-26 13:10:12 +03:00
Ensure thread_preSuspend and thread_postSuspend can be called in detached threads.
This commit is contained in:
parent
ff0d824b80
commit
88a287036d
1 changed files with 22 additions and 6 deletions
|
@ -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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue