Skip to content

Commit 9db47d6

Browse files
committed
Sonarqube: make it clearer that the Thread that is sleeping isn't holding the lock on the scheduleAlarm method
1 parent e830199 commit 9db47d6

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/SignalModuleBuiltins.java

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -307,9 +307,14 @@ final class Signals {
307307
}
308308
}
309309

310-
@TruffleBoundary
311-
synchronized static void scheduleAlarm(long seconds) {
312-
new Thread(() -> {
310+
private static class Alarm implements Runnable {
311+
private final long seconds;
312+
313+
Alarm(long seconds) {
314+
this.seconds = seconds;
315+
}
316+
317+
public void run() {
313318
long t0 = System.currentTimeMillis();
314319
while ((System.currentTimeMillis() - t0) < seconds * 1000) {
315320
try {
@@ -319,7 +324,12 @@ synchronized static void scheduleAlarm(long seconds) {
319324
}
320325
}
321326
sun.misc.Signal.raise(new sun.misc.Signal("ALRM"));
322-
}).start();
327+
}
328+
}
329+
330+
@TruffleBoundary
331+
synchronized static void scheduleAlarm(long seconds) {
332+
new Thread(new Alarm(seconds)).start();
323333
}
324334

325335
private static class PythonSignalHandler implements sun.misc.SignalHandler {

0 commit comments

Comments
 (0)