Skip to content

Commit 93552e5

Browse files
rv32imakinke
authored andcommitted
Fix Issue 15939 -- Move SIGUSR1/SIGUSR2 to SIGRT for GC
1 parent 94bd5bc commit 93552e5

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

src/core/memory.d

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
*
3939
* Notes_to_implementors:
4040
* $(UL
41-
* $(LI On POSIX systems, the signals SIGUSR1 and SIGUSR2 are reserved
41+
* $(LI On POSIX systems, the signals `SIGRTMIN` and `SIGRTMIN + 1` are reserved
4242
* by this module for use in the garbage collector implementation.
4343
* Typically, they will be used to stop and resume other threads
4444
* when performing a collection, but an implementation may choose

src/core/thread/osthread.d

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1185,7 +1185,7 @@ version (CoreDdoc)
11851185
{
11861186
/**
11871187
* Instruct the thread module, when initialized, to use a different set of
1188-
* signals besides SIGUSR1 and SIGUSR2 for suspension and resumption of threads.
1188+
* signals besides SIGRTMIN and SIGRTMIN + 1 for suspension and resumption of threads.
11891189
* This function should be called at most once, prior to thread_init().
11901190
* This function is Posix-only.
11911191
*/
@@ -1215,8 +1215,8 @@ else version (Posix)
12151215

12161216
version (Posix)
12171217
{
1218-
private __gshared int suspendSignalNumber = SIGUSR1;
1219-
private __gshared int resumeSignalNumber = SIGUSR2;
1218+
private __gshared int suspendSignalNumber;
1219+
private __gshared int resumeSignalNumber;
12201220
}
12211221

12221222
private extern (D) ThreadBase attachThread(ThreadBase _thisThread) @nogc nothrow
@@ -1940,7 +1940,8 @@ extern (C) void thread_init() @nogc
19401940
// The Android VM runtime intercepts SIGUSR1 and apparently doesn't allow
19411941
// its signal handler to run, so swap the two signals on Android, since
19421942
// thread_resumeHandler does nothing.
1943-
version (Android) thread_setGCSignals(SIGUSR2, SIGUSR1);
1943+
// This hack is no longer needed, as the GC signals now use SIGRTMIN / SIGRTMIN + 1
1944+
// version (Android) thread_setGCSignals(SIGUSR2, SIGUSR1);
19441945

19451946
version (Darwin)
19461947
{
@@ -1957,6 +1958,16 @@ extern (C) void thread_init() @nogc
19571958
}
19581959
else version (Posix)
19591960
{
1961+
if ( suspendSignalNumber == 0 )
1962+
{
1963+
suspendSignalNumber = SIGRTMIN;
1964+
}
1965+
1966+
if ( resumeSignalNumber == 0 )
1967+
{
1968+
resumeSignalNumber = SIGRTMIN + 1;
1969+
assert(resumeSignalNumber <= SIGRTMAX);
1970+
}
19601971
int status;
19611972
sigaction_t suspend = void;
19621973
sigaction_t resume = void;

0 commit comments

Comments
 (0)