Browse Source

JackControlAPI: Replacing sigwait with signalfd and poll

This would be required so that the polling concept can be used to wait
on signals as well as wait for events from the other threads.

(cherry picked from adit)

Change-Id: Ic7b8d4c816d601d4b5467ec9c2519f3c547ae59f
Signed-off-by: Laxmi Devi <Laxmi.Devi@in.bosch.com>
Signed-off-by: Timo Wischer <twischer@de.adit-jv.com>
pull/948/head
Laxmi Devi Adam Miartus 6 years ago
parent
commit
58ab7eea9a
1 changed files with 53 additions and 2 deletions
  1. +53
    -2
      common/JackControlAPI.cpp

+ 53
- 2
common/JackControlAPI.cpp View File

@@ -26,6 +26,11 @@
#include <pthread.h>
#endif

#ifdef __linux__
#include <poll.h>
#include <sys/signalfd.h>
#endif

#include "types.h"
#include <string.h>
#include <errno.h>
@@ -679,16 +684,56 @@ jackctl_setup_signals(
SERVER_EXPORT void
jackctl_wait_signals(jackctl_sigmask_t * sigmask)
{
int sig;
int sig = 0;
bool waiting = true;
#ifdef __linux__
int err;
struct pollfd pfd;
struct signalfd_siginfo si;

/* Block the signals in order for signalfd to receive them */
sigprocmask(SIG_BLOCK, &sigmask->signals, NULL);

pfd.fd = signalfd(-1, &sigmask->signals, 0);
if(pfd.fd == -1) {
fprintf(stderr, "Jack : signalfd() failed with errno %d\n", -errno);
return;
}
pfd.events = POLLIN;
#endif

while (waiting) {
#if defined(sun) && !defined(__sun__) // SUN compiler only, to check
sigwait(&sigmask->signals);
fprintf(stderr, "Jack main caught signal\n");
#elif defined(__linux__)
err = poll(&pfd, 1, -1);
if (err < 0) {
if (errno == EINTR) {
continue;
} else {
fprintf(stderr, "Jack : poll() failed with errno %d\n", -errno);
break;
}
} else {
if (pfd.revents & (POLLERR | POLLHUP | POLLNVAL)) {
fprintf(stderr, "Jack : poll() exited with errno %d\n", -errno);
break;
} else if ((pfd.revents & POLLIN) == 0) {
continue;
}
err = read (pfd.fd, &si, sizeof(si));
if (err < 0) {
fprintf(stderr, "Jack : read() on signalfd failed with errno %d\n", -errno);
goto fail;
}
sig = si.ssi_signo;
fprintf(stderr, "Jack main caught signal %d\n", sig);
}
#else
sigwait(&sigmask->signals, &sig);
#endif
fprintf(stderr, "Jack main caught signal %d\n", sig);
#endif

switch (sig) {
case SIGUSR1:
@@ -712,6 +757,12 @@ jackctl_wait_signals(jackctl_sigmask_t * sigmask)
// bugs that cause segfaults etc. during shutdown.
sigprocmask(SIG_UNBLOCK, &sigmask->signals, 0);
}

#ifdef __linux__
fail:
close(pfd.fd);
#endif

}
#endif



Loading…
Cancel
Save