[Xenomai-git] Philippe Gerum : copperplate/notifier: signal suspended thread directly

2014-05-16 Thread git repository hosting
Module: xenomai-forge
Branch: master
Commit: 97e243b81194de9cc4cc6ef9d0232f61e5f609e0
URL:
http://git.xenomai.org/?p=xenomai-forge.git;a=commit;h=97e243b81194de9cc4cc6ef9d0232f61e5f609e0

Author: Philippe Gerum 
Date:   Wed May  7 16:07:27 2014 +0200

copperplate/notifier: signal suspended thread directly

The notifier will remain dedicated to supporting thread-directed
suspend/resume operations eventually, and there is no gain in issuing
a signaled message compared to solely signaling the target thread.

Therefore we drop the pipe formerly used to trigger a fasync
notification on the read side, replacing it by direct signaling of the
target thread.

This patch is a slightly updated version of Matthias Schneider's
proposal:
http://www.xenomai.org/pipermail/xenomai/2014-May/030822.html

---

 include/copperplate/notifier.h |3 +-
 lib/copperplate/notifier.c |  105 ++--
 2 files changed, 17 insertions(+), 91 deletions(-)

diff --git a/include/copperplate/notifier.h b/include/copperplate/notifier.h
index 13bf588..61e2ec4 100644
--- a/include/copperplate/notifier.h
+++ b/include/copperplate/notifier.h
@@ -23,8 +23,7 @@
 
 struct notifier {
pid_t owner;
-   int psfd[2];
-   int pwfd[2];
+   int waitfd[2];
struct pvholder link;
 };
 
diff --git a/lib/copperplate/notifier.c b/lib/copperplate/notifier.c
index 4b3988a..0e8c832 100644
--- a/lib/copperplate/notifier.c
+++ b/lib/copperplate/notifier.c
@@ -36,65 +36,24 @@ static struct sigaction notifier_old_sa;
 
 static void notifier_sighandler(int sig, siginfo_t *siginfo, void *uc)
 {
-   int ret, matched = 0;
struct notifier *nf;
pid_t tid;
-   char c;
 
tid = copperplate_get_tid();
 
if (pvlist_empty(¬ifier_list))
-   goto hand_over;
+   goto ouch;
 
/* We may NOT alter the notifier list, but only scan it. */
pvlist_for_each_entry(nf, ¬ifier_list, link) {
-   if (nf->psfd[0] != siginfo->si_fd)
-   continue;
-
-   matched = 1;
-   /*
-* Paranoid: misdirected notifications should never
-* happen with F_SETOWN_EX invoked for the
-* notification fildes.
-*/
-   if (nf->owner != tid)
-   continue;
-
-   for (;;) {
-   ret = read(nf->psfd[0], &c, 1); 
-   if (ret > 0)
-   notifier_wait(nf);
-   else if (ret == 0 || errno != EINTR)
-   break;
+   if (nf->owner == tid) {
+   notifier_wait(nf);
+   return;
}
-
-   return;
-   }
-
-   /*
-* Paranoid: we may have received a valid notification on the
-* wrong thread: bail out silently, assuming the recipient
-* will find out eventually.
-*/
-   if (matched)
-   return;
-
-hand_over:
-   if (notifier_old_sa.sa_sigaction) {
-   /*
-* This is our best effort to relay any unprocessed
-* event to the user-defined handler for SIGNOTIFY we
-* might have overriden in notifier_pkg_init(). The
-* application code should set this handler prior to
-* calling copperplate_init(), so that we know about it. The
-* signal setup flags will be ours however
-* (i.e. SA_SIGINFO + BSD semantics).
-*/
-   notifier_old_sa.sa_sigaction(sig, siginfo, uc);
-   return;
}
-
-   panic("received spurious notification on thread[%d] [sig=%d, code=%d, 
fd=%d]",
+ouch:
+   panic("received spurious notification on thread[%d] "
+ "(sig=%d, code=%d, fd=%d)",
  tid, sig, siginfo->si_code, siginfo->si_fd);
 }
 
@@ -116,19 +75,11 @@ static void unlock_notifier_list(sigset_t *oset)
 
 int notifier_init(struct notifier *nf, pid_t pid)
 {
-   struct f_owner_ex owner;
sigset_t oset;
-   int fd, ret;
-
-   if (pipe(nf->psfd) < 0) {
-   ret = -errno;
-   goto fail;
-   }
+   int ret;
 
-   if (pipe(nf->pwfd) < 0) {
+   if (pipe(nf->waitfd) < 0) {
ret = -errno;
-   close(nf->psfd[0]);
-   close(nf->psfd[1]);
goto fail;
}
 
@@ -140,23 +91,6 @@ int notifier_init(struct notifier *nf, pid_t pid)
unlock_notifier_list(&oset);
pop_cleanup_lock(¬ifier_lock);
 
-   fd = nf->psfd[0];
-   fcntl(fd, F_SETSIG, SIGNOTIFY);
-   owner.type = F_OWNER_TID;
-   owner.pid = nf->owner;
-   fcntl(fd, F_SETOWN_EX, &owner);
-   fcntl(fd, F_SETFL, fcntl(fd, F_GETFL) | O_ASYNC | O_NONBLOCK);
-   fcntl(fd, F_SETFD, fcntl(fd, F_GETFD) | FD_CLOEXEC);
-   /*
-* 

[Xenomai-git] Philippe Gerum : copperplate/notifier: signal suspended thread directly

2014-05-13 Thread git repository hosting
Module: xenomai-forge
Branch: next
Commit: 97e243b81194de9cc4cc6ef9d0232f61e5f609e0
URL:
http://git.xenomai.org/?p=xenomai-forge.git;a=commit;h=97e243b81194de9cc4cc6ef9d0232f61e5f609e0

Author: Philippe Gerum 
Date:   Wed May  7 16:07:27 2014 +0200

copperplate/notifier: signal suspended thread directly

The notifier will remain dedicated to supporting thread-directed
suspend/resume operations eventually, and there is no gain in issuing
a signaled message compared to solely signaling the target thread.

Therefore we drop the pipe formerly used to trigger a fasync
notification on the read side, replacing it by direct signaling of the
target thread.

This patch is a slightly updated version of Matthias Schneider's
proposal:
http://www.xenomai.org/pipermail/xenomai/2014-May/030822.html

---

 include/copperplate/notifier.h |3 +-
 lib/copperplate/notifier.c |  105 ++--
 2 files changed, 17 insertions(+), 91 deletions(-)

diff --git a/include/copperplate/notifier.h b/include/copperplate/notifier.h
index 13bf588..61e2ec4 100644
--- a/include/copperplate/notifier.h
+++ b/include/copperplate/notifier.h
@@ -23,8 +23,7 @@
 
 struct notifier {
pid_t owner;
-   int psfd[2];
-   int pwfd[2];
+   int waitfd[2];
struct pvholder link;
 };
 
diff --git a/lib/copperplate/notifier.c b/lib/copperplate/notifier.c
index 4b3988a..0e8c832 100644
--- a/lib/copperplate/notifier.c
+++ b/lib/copperplate/notifier.c
@@ -36,65 +36,24 @@ static struct sigaction notifier_old_sa;
 
 static void notifier_sighandler(int sig, siginfo_t *siginfo, void *uc)
 {
-   int ret, matched = 0;
struct notifier *nf;
pid_t tid;
-   char c;
 
tid = copperplate_get_tid();
 
if (pvlist_empty(¬ifier_list))
-   goto hand_over;
+   goto ouch;
 
/* We may NOT alter the notifier list, but only scan it. */
pvlist_for_each_entry(nf, ¬ifier_list, link) {
-   if (nf->psfd[0] != siginfo->si_fd)
-   continue;
-
-   matched = 1;
-   /*
-* Paranoid: misdirected notifications should never
-* happen with F_SETOWN_EX invoked for the
-* notification fildes.
-*/
-   if (nf->owner != tid)
-   continue;
-
-   for (;;) {
-   ret = read(nf->psfd[0], &c, 1); 
-   if (ret > 0)
-   notifier_wait(nf);
-   else if (ret == 0 || errno != EINTR)
-   break;
+   if (nf->owner == tid) {
+   notifier_wait(nf);
+   return;
}
-
-   return;
-   }
-
-   /*
-* Paranoid: we may have received a valid notification on the
-* wrong thread: bail out silently, assuming the recipient
-* will find out eventually.
-*/
-   if (matched)
-   return;
-
-hand_over:
-   if (notifier_old_sa.sa_sigaction) {
-   /*
-* This is our best effort to relay any unprocessed
-* event to the user-defined handler for SIGNOTIFY we
-* might have overriden in notifier_pkg_init(). The
-* application code should set this handler prior to
-* calling copperplate_init(), so that we know about it. The
-* signal setup flags will be ours however
-* (i.e. SA_SIGINFO + BSD semantics).
-*/
-   notifier_old_sa.sa_sigaction(sig, siginfo, uc);
-   return;
}
-
-   panic("received spurious notification on thread[%d] [sig=%d, code=%d, 
fd=%d]",
+ouch:
+   panic("received spurious notification on thread[%d] "
+ "(sig=%d, code=%d, fd=%d)",
  tid, sig, siginfo->si_code, siginfo->si_fd);
 }
 
@@ -116,19 +75,11 @@ static void unlock_notifier_list(sigset_t *oset)
 
 int notifier_init(struct notifier *nf, pid_t pid)
 {
-   struct f_owner_ex owner;
sigset_t oset;
-   int fd, ret;
-
-   if (pipe(nf->psfd) < 0) {
-   ret = -errno;
-   goto fail;
-   }
+   int ret;
 
-   if (pipe(nf->pwfd) < 0) {
+   if (pipe(nf->waitfd) < 0) {
ret = -errno;
-   close(nf->psfd[0]);
-   close(nf->psfd[1]);
goto fail;
}
 
@@ -140,23 +91,6 @@ int notifier_init(struct notifier *nf, pid_t pid)
unlock_notifier_list(&oset);
pop_cleanup_lock(¬ifier_lock);
 
-   fd = nf->psfd[0];
-   fcntl(fd, F_SETSIG, SIGNOTIFY);
-   owner.type = F_OWNER_TID;
-   owner.pid = nf->owner;
-   fcntl(fd, F_SETOWN_EX, &owner);
-   fcntl(fd, F_SETFL, fcntl(fd, F_GETFL) | O_ASYNC | O_NONBLOCK);
-   fcntl(fd, F_SETFD, fcntl(fd, F_GETFD) | FD_CLOEXEC);
-   /*
-* So

[Xenomai-git] Philippe Gerum : copperplate/notifier: signal suspended thread directly

2014-05-07 Thread git repository hosting
Module: xenomai-forge
Branch: next
Commit: 5aa90554ad5882429b57caa4b44e5d900d4db1f7
URL:
http://git.xenomai.org/?p=xenomai-forge.git;a=commit;h=5aa90554ad5882429b57caa4b44e5d900d4db1f7

Author: Philippe Gerum 
Date:   Wed May  7 16:07:27 2014 +0200

copperplate/notifier: signal suspended thread directly

The notifier will remain dedicated to supporting thread-directed
suspend/resume operations eventually, and there is no gain in issuing
a signaled message compared to solely signaling the target thread.

Therefore we drop the pipe formerly used to trigger a fasync
notification on the read side, replacing it by direct signaling of the
target thread.

This patch is a slightly updated version of Matthias Schneider's
proposal:
http://www.xenomai.org/pipermail/xenomai/2014-May/030822.html

---

 include/copperplate/notifier.h |3 +-
 lib/copperplate/notifier.c |  105 ++--
 2 files changed, 17 insertions(+), 91 deletions(-)

diff --git a/include/copperplate/notifier.h b/include/copperplate/notifier.h
index 13bf588..61e2ec4 100644
--- a/include/copperplate/notifier.h
+++ b/include/copperplate/notifier.h
@@ -23,8 +23,7 @@
 
 struct notifier {
pid_t owner;
-   int psfd[2];
-   int pwfd[2];
+   int waitfd[2];
struct pvholder link;
 };
 
diff --git a/lib/copperplate/notifier.c b/lib/copperplate/notifier.c
index 4b3988a..0e8c832 100644
--- a/lib/copperplate/notifier.c
+++ b/lib/copperplate/notifier.c
@@ -36,65 +36,24 @@ static struct sigaction notifier_old_sa;
 
 static void notifier_sighandler(int sig, siginfo_t *siginfo, void *uc)
 {
-   int ret, matched = 0;
struct notifier *nf;
pid_t tid;
-   char c;
 
tid = copperplate_get_tid();
 
if (pvlist_empty(¬ifier_list))
-   goto hand_over;
+   goto ouch;
 
/* We may NOT alter the notifier list, but only scan it. */
pvlist_for_each_entry(nf, ¬ifier_list, link) {
-   if (nf->psfd[0] != siginfo->si_fd)
-   continue;
-
-   matched = 1;
-   /*
-* Paranoid: misdirected notifications should never
-* happen with F_SETOWN_EX invoked for the
-* notification fildes.
-*/
-   if (nf->owner != tid)
-   continue;
-
-   for (;;) {
-   ret = read(nf->psfd[0], &c, 1); 
-   if (ret > 0)
-   notifier_wait(nf);
-   else if (ret == 0 || errno != EINTR)
-   break;
+   if (nf->owner == tid) {
+   notifier_wait(nf);
+   return;
}
-
-   return;
-   }
-
-   /*
-* Paranoid: we may have received a valid notification on the
-* wrong thread: bail out silently, assuming the recipient
-* will find out eventually.
-*/
-   if (matched)
-   return;
-
-hand_over:
-   if (notifier_old_sa.sa_sigaction) {
-   /*
-* This is our best effort to relay any unprocessed
-* event to the user-defined handler for SIGNOTIFY we
-* might have overriden in notifier_pkg_init(). The
-* application code should set this handler prior to
-* calling copperplate_init(), so that we know about it. The
-* signal setup flags will be ours however
-* (i.e. SA_SIGINFO + BSD semantics).
-*/
-   notifier_old_sa.sa_sigaction(sig, siginfo, uc);
-   return;
}
-
-   panic("received spurious notification on thread[%d] [sig=%d, code=%d, 
fd=%d]",
+ouch:
+   panic("received spurious notification on thread[%d] "
+ "(sig=%d, code=%d, fd=%d)",
  tid, sig, siginfo->si_code, siginfo->si_fd);
 }
 
@@ -116,19 +75,11 @@ static void unlock_notifier_list(sigset_t *oset)
 
 int notifier_init(struct notifier *nf, pid_t pid)
 {
-   struct f_owner_ex owner;
sigset_t oset;
-   int fd, ret;
-
-   if (pipe(nf->psfd) < 0) {
-   ret = -errno;
-   goto fail;
-   }
+   int ret;
 
-   if (pipe(nf->pwfd) < 0) {
+   if (pipe(nf->waitfd) < 0) {
ret = -errno;
-   close(nf->psfd[0]);
-   close(nf->psfd[1]);
goto fail;
}
 
@@ -140,23 +91,6 @@ int notifier_init(struct notifier *nf, pid_t pid)
unlock_notifier_list(&oset);
pop_cleanup_lock(¬ifier_lock);
 
-   fd = nf->psfd[0];
-   fcntl(fd, F_SETSIG, SIGNOTIFY);
-   owner.type = F_OWNER_TID;
-   owner.pid = nf->owner;
-   fcntl(fd, F_SETOWN_EX, &owner);
-   fcntl(fd, F_SETFL, fcntl(fd, F_GETFL) | O_ASYNC | O_NONBLOCK);
-   fcntl(fd, F_SETFD, fcntl(fd, F_GETFD) | FD_CLOEXEC);
-   /*
-* So