[Xenomai-git] Philippe Gerum : copperplate/notifier: sanitize and simplify - again

2014-04-30 Thread git repository hosting
Module: xenomai-forge
Branch: next
Commit: ea7bc8d0b55759744a72f1e1b80ad0eed0c5b113
URL:
http://git.xenomai.org/?p=xenomai-forge.git;a=commit;h=ea7bc8d0b55759744a72f1e1b80ad0eed0c5b113

Author: Philippe Gerum r...@xenomai.org
Date:   Sat Apr 26 15:07:41 2014 +0200

copperplate/notifier: sanitize and simplify - again

Those changes build on the fact that the notification support is there
exclusively for implementing the thread suspend/resume mechanism over
Mercury. Therefore we may drop any code which is not directly aimed at
supporting this feature.

Assuming this, locking may now be handled directly from the call
sites, all located in the threadobj implementation.

As a bonus, this change set also fixes the issue discussed there:
http://www.xenomai.org/pipermail/xenomai/2014-April/030804.html

---

 include/copperplate/notifier.h  |   16 ++--
 include/copperplate/threadobj.h |1 -
 lib/copperplate/notifier.c  |  169 ---
 lib/copperplate/threadobj.c |   69 +++-
 4 files changed, 86 insertions(+), 169 deletions(-)

diff --git a/include/copperplate/notifier.h b/include/copperplate/notifier.h
index 536782d..13bf588 100644
--- a/include/copperplate/notifier.h
+++ b/include/copperplate/notifier.h
@@ -19,16 +19,12 @@
 #ifndef _COPPERPLATE_NOTIFIER_H
 #define _COPPERPLATE_NOTIFIER_H
 
-#include pthread.h
 #include boilerplate/list.h
 
 struct notifier {
-   pthread_mutex_t lock;
-   int notified;
pid_t owner;
int psfd[2];
int pwfd[2];
-   void (*callback)(const struct notifier *nf);
struct pvholder link;
 };
 
@@ -36,17 +32,17 @@ struct notifier {
 extern C {
 #endif
 
-int notifier_init(struct notifier *nf,
- void (*callback)(const struct notifier *nf),
- int owned);
+int notifier_init(struct notifier *nf, pid_t pid);
 
 void notifier_destroy(struct notifier *nf);
 
-int notifier_signal(struct notifier *nf);
+void notifier_signal(struct notifier *nf);
 
-int notifier_wait(const struct notifier *nf);
+void notifier_wait(const struct notifier *nf);
 
-int notifier_release(struct notifier *nf);
+void notifier_disable(struct notifier *nf);
+
+void notifier_release(struct notifier *nf);
 
 void notifier_pkg_init(void);
 
diff --git a/include/copperplate/threadobj.h b/include/copperplate/threadobj.h
index 5438790..bc5be99 100644
--- a/include/copperplate/threadobj.h
+++ b/include/copperplate/threadobj.h
@@ -128,7 +128,6 @@ void threadobj_save_timeout(struct threadobj_corespec 
*corespec,
 #define __THREAD_S_ACTIVE  (1  5)/* Running user code. */
 #define __THREAD_S_SUSPENDED   (1  6)/* Suspended via 
threadobj_suspend(). */
 #define __THREAD_S_SAFE(1  7)/* TCB release 
deferred. */
-#define __THREAD_S_ZOMBIE  (1  8)/* Deletion process ongoing. */
 #define __THREAD_S_DEBUG   (1  31)   /* Debug mode enabled. */
 /*
  * threadobj-run_state, locklessly updated by current, merged
diff --git a/lib/copperplate/notifier.c b/lib/copperplate/notifier.c
index 7fa48f3..4b3988a 100644
--- a/lib/copperplate/notifier.c
+++ b/lib/copperplate/notifier.c
@@ -50,25 +50,20 @@ static void notifier_sighandler(int sig, siginfo_t 
*siginfo, void *uc)
pvlist_for_each_entry(nf, notifier_list, link) {
if (nf-psfd[0] != siginfo-si_fd)
continue;
+
+   matched = 1;
/*
-* Ignore misdirected notifications. We want those to
-* hit the thread owning the notification object, but
-* it may happen that the kernel picks another thread
-* for receiving a subsequent signal while we are
-* blocked in the callback code. In such a case, we
-* just dismiss the notification, and expect the
-* actual owner to detect the pending notification
-* once the callback returns to the read() loop.
+* Paranoid: misdirected notifications should never
+* happen with F_SETOWN_EX invoked for the
+* notification fildes.
 */
-   matched = 1;
-   if (nf-owner  nf-owner != tid)
+   if (nf-owner != tid)
continue;
 
for (;;) {
-   ret = __STD(read(nf-psfd[0], c, 1)); 
+   ret = read(nf-psfd[0], c, 1); 
if (ret  0)
-   /* Callee must run async-safe code only. */
-   nf-callback(nf);
+   notifier_wait(nf);
else if (ret == 0 || errno != EINTR)
break;
}
@@ -77,9 +72,9 @@ static void notifier_sighandler(int sig, siginfo_t *siginfo, 
void *uc)
}
 
/*
-* We may have received a valid notification on the wrong
-

[Xenomai-git] Philippe Gerum : copperplate/notifier: sanitize and simplify - again

2014-04-28 Thread git repository hosting
Module: xenomai-forge
Branch: next
Commit: ffe15e60517a84d33894d980f2e862b3c3e3765c
URL:
http://git.xenomai.org/?p=xenomai-forge.git;a=commit;h=ffe15e60517a84d33894d980f2e862b3c3e3765c

Author: Philippe Gerum r...@xenomai.org
Date:   Sat Apr 26 15:07:41 2014 +0200

copperplate/notifier: sanitize and simplify - again

Those changes build on the fact that the notification support is there
exclusively for implementing the thread suspend/resume mechanism over
Mercury. Therefore we may drop any code which is not directly aimed at
supporting this feature.

Assuming this, locking may now be handled directly from the call
sites, all located in the threadobj implementation.

As a bonus, this change set also fixes the issue discussed there:
http://www.xenomai.org/pipermail/xenomai/2014-April/030804.html

---

 include/copperplate/notifier.h  |   16 ++--
 include/copperplate/threadobj.h |1 -
 lib/copperplate/notifier.c  |  169 ---
 lib/copperplate/threadobj.c |   69 +++-
 4 files changed, 86 insertions(+), 169 deletions(-)

diff --git a/include/copperplate/notifier.h b/include/copperplate/notifier.h
index 536782d..13bf588 100644
--- a/include/copperplate/notifier.h
+++ b/include/copperplate/notifier.h
@@ -19,16 +19,12 @@
 #ifndef _COPPERPLATE_NOTIFIER_H
 #define _COPPERPLATE_NOTIFIER_H
 
-#include pthread.h
 #include boilerplate/list.h
 
 struct notifier {
-   pthread_mutex_t lock;
-   int notified;
pid_t owner;
int psfd[2];
int pwfd[2];
-   void (*callback)(const struct notifier *nf);
struct pvholder link;
 };
 
@@ -36,17 +32,17 @@ struct notifier {
 extern C {
 #endif
 
-int notifier_init(struct notifier *nf,
- void (*callback)(const struct notifier *nf),
- int owned);
+int notifier_init(struct notifier *nf, pid_t pid);
 
 void notifier_destroy(struct notifier *nf);
 
-int notifier_signal(struct notifier *nf);
+void notifier_signal(struct notifier *nf);
 
-int notifier_wait(const struct notifier *nf);
+void notifier_wait(const struct notifier *nf);
 
-int notifier_release(struct notifier *nf);
+void notifier_disable(struct notifier *nf);
+
+void notifier_release(struct notifier *nf);
 
 void notifier_pkg_init(void);
 
diff --git a/include/copperplate/threadobj.h b/include/copperplate/threadobj.h
index 5438790..bc5be99 100644
--- a/include/copperplate/threadobj.h
+++ b/include/copperplate/threadobj.h
@@ -128,7 +128,6 @@ void threadobj_save_timeout(struct threadobj_corespec 
*corespec,
 #define __THREAD_S_ACTIVE  (1  5)/* Running user code. */
 #define __THREAD_S_SUSPENDED   (1  6)/* Suspended via 
threadobj_suspend(). */
 #define __THREAD_S_SAFE(1  7)/* TCB release 
deferred. */
-#define __THREAD_S_ZOMBIE  (1  8)/* Deletion process ongoing. */
 #define __THREAD_S_DEBUG   (1  31)   /* Debug mode enabled. */
 /*
  * threadobj-run_state, locklessly updated by current, merged
diff --git a/lib/copperplate/notifier.c b/lib/copperplate/notifier.c
index 7fa48f3..4b3988a 100644
--- a/lib/copperplate/notifier.c
+++ b/lib/copperplate/notifier.c
@@ -50,25 +50,20 @@ static void notifier_sighandler(int sig, siginfo_t 
*siginfo, void *uc)
pvlist_for_each_entry(nf, notifier_list, link) {
if (nf-psfd[0] != siginfo-si_fd)
continue;
+
+   matched = 1;
/*
-* Ignore misdirected notifications. We want those to
-* hit the thread owning the notification object, but
-* it may happen that the kernel picks another thread
-* for receiving a subsequent signal while we are
-* blocked in the callback code. In such a case, we
-* just dismiss the notification, and expect the
-* actual owner to detect the pending notification
-* once the callback returns to the read() loop.
+* Paranoid: misdirected notifications should never
+* happen with F_SETOWN_EX invoked for the
+* notification fildes.
 */
-   matched = 1;
-   if (nf-owner  nf-owner != tid)
+   if (nf-owner != tid)
continue;
 
for (;;) {
-   ret = __STD(read(nf-psfd[0], c, 1)); 
+   ret = read(nf-psfd[0], c, 1); 
if (ret  0)
-   /* Callee must run async-safe code only. */
-   nf-callback(nf);
+   notifier_wait(nf);
else if (ret == 0 || errno != EINTR)
break;
}
@@ -77,9 +72,9 @@ static void notifier_sighandler(int sig, siginfo_t *siginfo, 
void *uc)
}
 
/*
-* We may have received a valid notification on the wrong
-

[Xenomai-git] Philippe Gerum : copperplate/notifier: sanitize and simplify - again

2014-04-26 Thread git repository hosting
Module: xenomai-forge
Branch: next
Commit: 4f3396bf96b9fcb750d68e843c60ec9f5d22f9cd
URL:
http://git.xenomai.org/?p=xenomai-forge.git;a=commit;h=4f3396bf96b9fcb750d68e843c60ec9f5d22f9cd

Author: Philippe Gerum r...@xenomai.org
Date:   Sat Apr 26 15:07:41 2014 +0200

copperplate/notifier: sanitize and simplify - again

Those changes build on the fact that the notification support is there
exclusively for implementing the thread suspend/resume mechanism over
Mercury. Therefore we may drop any code which is not directly aimed at
supporting this feature.

Assuming this, locking may now be handled directly from the call
sites, all located in the threadobj implementation.

As a bonus, this change set also fixes the issue discussed there:
http://www.xenomai.org/pipermail/xenomai/2014-April/030804.html

---

 include/copperplate/notifier.h  |   16 ++--
 include/copperplate/threadobj.h |1 -
 lib/copperplate/notifier.c  |  169 ---
 lib/copperplate/threadobj.c |   69 +++-
 4 files changed, 86 insertions(+), 169 deletions(-)

diff --git a/include/copperplate/notifier.h b/include/copperplate/notifier.h
index 536782d..13bf588 100644
--- a/include/copperplate/notifier.h
+++ b/include/copperplate/notifier.h
@@ -19,16 +19,12 @@
 #ifndef _COPPERPLATE_NOTIFIER_H
 #define _COPPERPLATE_NOTIFIER_H
 
-#include pthread.h
 #include boilerplate/list.h
 
 struct notifier {
-   pthread_mutex_t lock;
-   int notified;
pid_t owner;
int psfd[2];
int pwfd[2];
-   void (*callback)(const struct notifier *nf);
struct pvholder link;
 };
 
@@ -36,17 +32,17 @@ struct notifier {
 extern C {
 #endif
 
-int notifier_init(struct notifier *nf,
- void (*callback)(const struct notifier *nf),
- int owned);
+int notifier_init(struct notifier *nf, pid_t pid);
 
 void notifier_destroy(struct notifier *nf);
 
-int notifier_signal(struct notifier *nf);
+void notifier_signal(struct notifier *nf);
 
-int notifier_wait(const struct notifier *nf);
+void notifier_wait(const struct notifier *nf);
 
-int notifier_release(struct notifier *nf);
+void notifier_disable(struct notifier *nf);
+
+void notifier_release(struct notifier *nf);
 
 void notifier_pkg_init(void);
 
diff --git a/include/copperplate/threadobj.h b/include/copperplate/threadobj.h
index 5438790..bc5be99 100644
--- a/include/copperplate/threadobj.h
+++ b/include/copperplate/threadobj.h
@@ -128,7 +128,6 @@ void threadobj_save_timeout(struct threadobj_corespec 
*corespec,
 #define __THREAD_S_ACTIVE  (1  5)/* Running user code. */
 #define __THREAD_S_SUSPENDED   (1  6)/* Suspended via 
threadobj_suspend(). */
 #define __THREAD_S_SAFE(1  7)/* TCB release 
deferred. */
-#define __THREAD_S_ZOMBIE  (1  8)/* Deletion process ongoing. */
 #define __THREAD_S_DEBUG   (1  31)   /* Debug mode enabled. */
 /*
  * threadobj-run_state, locklessly updated by current, merged
diff --git a/lib/copperplate/notifier.c b/lib/copperplate/notifier.c
index 7fa48f3..4b3988a 100644
--- a/lib/copperplate/notifier.c
+++ b/lib/copperplate/notifier.c
@@ -50,25 +50,20 @@ static void notifier_sighandler(int sig, siginfo_t 
*siginfo, void *uc)
pvlist_for_each_entry(nf, notifier_list, link) {
if (nf-psfd[0] != siginfo-si_fd)
continue;
+
+   matched = 1;
/*
-* Ignore misdirected notifications. We want those to
-* hit the thread owning the notification object, but
-* it may happen that the kernel picks another thread
-* for receiving a subsequent signal while we are
-* blocked in the callback code. In such a case, we
-* just dismiss the notification, and expect the
-* actual owner to detect the pending notification
-* once the callback returns to the read() loop.
+* Paranoid: misdirected notifications should never
+* happen with F_SETOWN_EX invoked for the
+* notification fildes.
 */
-   matched = 1;
-   if (nf-owner  nf-owner != tid)
+   if (nf-owner != tid)
continue;
 
for (;;) {
-   ret = __STD(read(nf-psfd[0], c, 1)); 
+   ret = read(nf-psfd[0], c, 1); 
if (ret  0)
-   /* Callee must run async-safe code only. */
-   nf-callback(nf);
+   notifier_wait(nf);
else if (ret == 0 || errno != EINTR)
break;
}
@@ -77,9 +72,9 @@ static void notifier_sighandler(int sig, siginfo_t *siginfo, 
void *uc)
}
 
/*
-* We may have received a valid notification on the wrong
-