- while (!interrupted &&
- (numFound = select(maxfd+1, &rfd, &wfd, NULL, &tv)) < 0) {
- if (errno != EINTR) {
- /* fflush(stdout); */
- perror("select");
- barf("select failed");
- }
- ACQUIRE_LOCK(&sched_mutex);
-
- /* We got a signal; could be one of ours. If so, we need
- * to start up the signal handler straight away, otherwise
- * we could block for a long time before the signal is
- * serviced.
- */
- if (signals_pending()) {
- RELEASE_LOCK(&sched_mutex);
- start_signal_handlers();
- /* Don't wake up any other threads that were waiting on I/O */
- select_succeeded = rtsFalse;
- break;
- }
-
- if (interrupted) {
- RELEASE_LOCK(&sched_mutex);
- select_succeeded = rtsFalse;
- break;
- }
-
- /* If new runnable threads have arrived, stop waiting for
- * I/O and run them.
- */
- if (run_queue_hd != END_TSO_QUEUE) {
- RELEASE_LOCK(&sched_mutex);
- select_succeeded = rtsFalse;
- break;
- }
-
- RELEASE_LOCK(&sched_mutex);
- }
-
-#ifdef linux_TARGET_OS
- /* on Linux, tv is set to indicate the amount of time not
- * slept, so we don't need to gettimeofday() to find out.
- */
- delta += min - (tv.tv_sec * 1000000 + tv.tv_usec);
-#else
- gettimeofday(&tv_after, (struct timezone *) NULL);
- delta += (tv_after.tv_sec - tv_before.tv_sec) * 1000000 +
- tv_after.tv_usec - tv_before.tv_usec;
+ /* We got a signal; could be one of ours. If so, we need
+ * to start up the signal handler straight away, otherwise
+ * we could block for a long time before the signal is
+ * serviced.
+ */
+#if defined(RTS_USER_SIGNALS)
+ if (signals_pending()) {
+ RELEASE_LOCK(&sched_mutex); /* ToDo: kill */
+ startSignalHandlers();
+ ACQUIRE_LOCK(&sched_mutex);
+ return; /* still hold the lock */
+ }