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.

Signed-off-by: Laxmi Devi <Laxmi.Devi@in.bosch.com>
pull/462/head
Laxmi Devi 6 years ago
parent
commit
fc9046998b
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> #include <pthread.h>
#endif #endif


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

#include "types.h" #include "types.h"
#include <string.h> #include <string.h>
#include <errno.h> #include <errno.h>
@@ -677,16 +682,56 @@ jackctl_setup_signals(
SERVER_EXPORT void SERVER_EXPORT void
jackctl_wait_signals(jackctl_sigmask_t * sigmask) jackctl_wait_signals(jackctl_sigmask_t * sigmask)
{ {
int sig;
int sig = 0;
bool waiting = true; 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) { while (waiting) {
#if defined(sun) && !defined(__sun__) // SUN compiler only, to check #if defined(sun) && !defined(__sun__) // SUN compiler only, to check
sigwait(&sigmask->signals); 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 #else
sigwait(&sigmask->signals, &sig); sigwait(&sigmask->signals, &sig);
#endif
fprintf(stderr, "Jack main caught signal %d\n", sig); fprintf(stderr, "Jack main caught signal %d\n", sig);
#endif


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

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

} }
#endif #endif




Loading…
Cancel
Save