Skip to content

Commit 3d87497

Browse files
denizzzkathewilsonator
authored andcommitted
osthread: thread_suspendAll() code split over *_impl modules
1 parent eac10d2 commit 3d87497

3 files changed

Lines changed: 32 additions & 30 deletions

File tree

druntime/src/core/thread/osthread.d

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -954,36 +954,7 @@ extern (C) void thread_suspendAll() nothrow
954954
t = tn;
955955
}
956956

957-
version (Darwin)
958-
{}
959-
else version (Solaris)
960-
{}
961-
else version (WASI)
962-
{}
963-
else version (Posix)
964-
{
965-
// Subtract own thread if we called suspend() on ourselves.
966-
// For example, suspendedSelf would be false if the current
967-
// thread ran thread_detachThis().
968-
assert(cnt >= 1);
969-
if (suspendedSelf)
970-
--cnt;
971-
// wait for semaphore notifications
972-
for (; cnt; --cnt)
973-
{
974-
while (sem_wait(&suspendCount) != 0)
975-
{
976-
if (errno != EINTR)
977-
onThreadError("Unable to wait for semaphore");
978-
errno = 0;
979-
}
980-
}
981-
}
982-
else version (Windows)
983-
{
984-
}
985-
else
986-
static assert(0, "unsupported os");
957+
afterStopTheWorld(suspendedSelf, cnt);
987958
}
988959
}
989960

druntime/src/core/thread/posix_impl.d

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -864,6 +864,35 @@ package bool resumeThreadImpl(Thread t) @nogc nothrow
864864
return pthread_kill(t.m_tdescr.tid, resumeSignalNumber) == 0;
865865
}
866866

867+
package void afterStopTheWorld(bool suspendedSelf, size_t cnt) @nogc nothrow
868+
{
869+
version (Darwin)
870+
{}
871+
else version (Solaris)
872+
{}
873+
else version (WASI)
874+
{}
875+
else version (Posix)
876+
{
877+
// Subtract own thread if we called suspend() on ourselves.
878+
// For example, suspendedSelf would be false if the current
879+
// thread ran thread_detachThis().
880+
assert(cnt >= 1);
881+
if (suspendedSelf)
882+
--cnt;
883+
// wait for semaphore notifications
884+
for (; cnt; --cnt)
885+
{
886+
while (sem_wait(&suspendCount) != 0)
887+
{
888+
if (errno != EINTR)
889+
onThreadError("Unable to wait for semaphore");
890+
errno = 0;
891+
}
892+
}
893+
}
894+
}
895+
867896
package void loadStackAndRegInfo(Thread t, const bool sameThread) nothrow @nogc
868897
{
869898
version (Darwin)

druntime/src/core/thread/windows_impl.d

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,8 @@ package bool resumeThreadImpl(Thread t) @nogc nothrow
462462
return ResumeThread(t.m_tdescr.hndl) != 0xFFFFFFFF;
463463
}
464464

465+
package void afterStopTheWorld(bool suspendedSelf, size_t cnt) @nogc nothrow { /* do nothing */ }
466+
465467
package void loadStackAndRegInfo(Thread t, const bool sameThread) nothrow @nogc
466468
{
467469
CONTEXT context = void;

0 commit comments

Comments
 (0)