[Xenomai-git] Philippe Gerum : copperplate/threadobj: do not leak the periodic timer

2018-04-18 Thread git repository hosting
Module: xenomai-3
Branch: stable-3.0.x
Commit: 7fffb2630c8358ed7b1654aaf4a200ea28981e93
URL:
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=7fffb2630c8358ed7b1654aaf4a200ea28981e93

Author: Philippe Gerum 
Date:   Wed Apr 18 20:10:31 2018 +0200

copperplate/threadobj: do not leak the periodic timer

---

 lib/copperplate/threadobj.c |   11 +--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/lib/copperplate/threadobj.c b/lib/copperplate/threadobj.c
index d9e9267..a1a805a 100644
--- a/lib/copperplate/threadobj.c
+++ b/lib/copperplate/threadobj.c
@@ -1631,6 +1631,14 @@ int threadobj_set_periodic(struct threadobj *thobj,
__threadobj_check_locked(thobj);
 
timer = thobj->periodic_timer;
+   if (!timespec_scalar(idate) && !timespec_scalar(period)) {
+   if (timer) {
+   thobj->periodic_timer = NULL;
+   __RT(timer_delete(timer));
+   }
+   return 0;
+   }
+   
if (timer == NULL) {
memset(, 0, sizeof(sev));
sev.sigev_signo = SIGPERIOD;
@@ -1640,8 +1648,7 @@ int threadobj_set_periodic(struct threadobj *thobj,
if (ret)
return __bt(-errno);
thobj->periodic_timer = timer;
-   } else if (!timespec_scalar(idate) && !timespec_scalar(period))
-   thobj->periodic_timer = NULL;
+   }
 
its.it_value = *idate;
its.it_interval = *period;


___
Xenomai-git mailing list
Xenomai-git@xenomai.org
https://xenomai.org/mailman/listinfo/xenomai-git


[Xenomai-git] Philippe Gerum : copperplate/threadobj: do not assume timer_id cannot be zero

2018-04-18 Thread git repository hosting
Module: xenomai-3
Branch: stable-3.0.x
Commit: fe91ab09b0af28bffc671eb69b5f4d93cac73f4f
URL:
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=fe91ab09b0af28bffc671eb69b5f4d93cac73f4f

Author: Philippe Gerum 
Date:   Wed Apr 18 21:18:56 2018 +0200

copperplate/threadobj: do not assume timer_id cannot be zero

Unlike glibc, libcobalt may return zero as a valid timer id. Use a
threadobj status flag to figure out whether a periodic timer was set
for the thread, instead of testing periodic_timer for NULLness.

This fixes set_periodic/wait_period services which have been broken
since commit #73de42cc8 was merged.

---

 include/copperplate/threadobj.h |1 +
 lib/copperplate/threadobj.c |   11 ++-
 2 files changed, 7 insertions(+), 5 deletions(-)

diff --git a/include/copperplate/threadobj.h b/include/copperplate/threadobj.h
index 6d29300..7e6904f 100644
--- a/include/copperplate/threadobj.h
+++ b/include/copperplate/threadobj.h
@@ -147,6 +147,7 @@ void threadobj_save_timeout(struct threadobj_corespec 
*corespec,
 #define __THREAD_S_ACTIVE  (1 << 4)/* Running user code. */
 #define __THREAD_S_SUSPENDED   (1 << 5)/* Suspended via 
threadobj_suspend(). */
 #define __THREAD_S_SAFE(1 << 6)/* TCB release 
deferred. */
+#define __THREAD_S_PERIODIC(1 << 7)/* Periodic timer set. */
 #define __THREAD_S_DEBUG   (1 << 31)   /* Debug mode enabled. */
 /*
  * threadobj->run_state, locklessly updated by "current", merged
diff --git a/lib/copperplate/threadobj.c b/lib/copperplate/threadobj.c
index a1a805a..f46d8fb 100644
--- a/lib/copperplate/threadobj.c
+++ b/lib/copperplate/threadobj.c
@@ -1193,7 +1193,7 @@ static void uninit_thread(struct threadobj *thobj)
 static void destroy_thread(struct threadobj *thobj)
 {
threadobj_cleanup_corespec(thobj);
-   if (thobj->periodic_timer)
+   if (thobj->status & __THREAD_S_PERIODIC)
__RT(timer_delete(thobj->periodic_timer));
uninit_thread(thobj);
 }
@@ -1632,14 +1632,14 @@ int threadobj_set_periodic(struct threadobj *thobj,
 
timer = thobj->periodic_timer;
if (!timespec_scalar(idate) && !timespec_scalar(period)) {
-   if (timer) {
-   thobj->periodic_timer = NULL;
+   if (thobj->status & __THREAD_S_PERIODIC) {
+   thobj->status &= ~__THREAD_S_PERIODIC;
__RT(timer_delete(timer));
}
return 0;
}

-   if (timer == NULL) {
+   if (!(thobj->status & __THREAD_S_PERIODIC)) {
memset(, 0, sizeof(sev));
sev.sigev_signo = SIGPERIOD;
sev.sigev_notify = SIGEV_SIGNAL|SIGEV_THREAD_ID;
@@ -1648,6 +1648,7 @@ int threadobj_set_periodic(struct threadobj *thobj,
if (ret)
return __bt(-errno);
thobj->periodic_timer = timer;
+   thobj->status |= __THREAD_S_PERIODIC;
}
 
its.it_value = *idate;
@@ -1666,7 +1667,7 @@ int threadobj_wait_period(unsigned long *overruns_r)
siginfo_t si;
int sig;
 
-   if (current->periodic_timer == NULL)
+   if (!(current->status & __THREAD_S_PERIODIC))
return -EWOULDBLOCK;
 
for (;;) {


___
Xenomai-git mailing list
Xenomai-git@xenomai.org
https://xenomai.org/mailman/listinfo/xenomai-git


[Xenomai-git] Philippe Gerum : testsuite/smokey: drop conflicting declaration

2018-04-18 Thread git repository hosting
Module: xenomai-3
Branch: stable-3.0.x
Commit: f71f6690c9f51866878c2232e87dff32058ece83
URL:
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=f71f6690c9f51866878c2232e87dff32058ece83

Author: Philippe Gerum 
Date:   Tue Apr 17 15:17:07 2018 +0200

testsuite/smokey: drop conflicting declaration

---

 testsuite/smokey/sched-tp/sched-tp.c |5 +
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/testsuite/smokey/sched-tp/sched-tp.c 
b/testsuite/smokey/sched-tp/sched-tp.c
index 8705eed..434ac3c 100644
--- a/testsuite/smokey/sched-tp/sched-tp.c
+++ b/testsuite/smokey/sched-tp/sched-tp.c
@@ -9,6 +9,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -26,10 +27,6 @@ smokey_test_plugin(sched_tp,
   "Check the SCHED_TP scheduling policy"
 );
 
-int clock_nanosleep(clockid_t __clock_id, int __flags,
-   __const struct timespec *__req,
-   struct timespec *__rem);
-
 static pthread_t threadA, threadB, threadC;
 
 static sem_t barrier;


___
Xenomai-git mailing list
Xenomai-git@xenomai.org
https://xenomai.org/mailman/listinfo/xenomai-git