Module: xenomai-forge
Branch: master
Commit: 2bb7b5f114fbbd248a259a5799dcdae17fc5f107
URL:    
http://git.xenomai.org/?p=xenomai-forge.git;a=commit;h=2bb7b5f114fbbd248a259a5799dcdae17fc5f107

Author: Philippe Gerum <r...@xenomai.org>
Date:   Tue Sep 24 12:57:30 2013 +0200

cobalt/posix/monitor: allow for selecting the timeout clock

---

 kernel/cobalt/posix/monitor.c |   13 +++++++++----
 kernel/cobalt/posix/monitor.h |    2 ++
 lib/cobalt/internal.c         |    6 +++---
 lib/cobalt/internal.h         |    4 +++-
 4 files changed, 17 insertions(+), 8 deletions(-)

diff --git a/kernel/cobalt/posix/monitor.c b/kernel/cobalt/posix/monitor.c
index 67ac978..2c99eb0 100644
--- a/kernel/cobalt/posix/monitor.c
+++ b/kernel/cobalt/posix/monitor.c
@@ -55,7 +55,7 @@
 #include "monitor.h"
 
 int cobalt_monitor_init(struct cobalt_monitor_shadow __user *u_monsh,
-                       int flags)
+                       clockid_t clk_id, int flags)
 {
        struct cobalt_monitor_shadow monsh;
        struct cobalt_monitor_data *datp;
@@ -63,12 +63,16 @@ int cobalt_monitor_init(struct cobalt_monitor_shadow __user 
*u_monsh,
        struct cobalt_kqueues *kq;
        unsigned long datoff;
        struct xnheap *heap;
-       int pshared;
+       int pshared, tmode;
        spl_t s;
 
        if (__xn_safe_copy_from_user(&monsh, u_monsh, sizeof(monsh)))
                return -EFAULT;
 
+       tmode = clock_flag(TIMER_ABSTIME, clk_id);
+       if (tmode < 0)
+               return -EINVAL;
+
        mon = xnmalloc(sizeof(*mon));
        if (mon == NULL)
                return -ENOMEM;
@@ -85,6 +89,7 @@ int cobalt_monitor_init(struct cobalt_monitor_shadow __user 
*u_monsh,
        xnsynch_init(&mon->gate, XNSYNCH_PIP, &datp->owner);
        xnsynch_init(&mon->drain, XNSYNCH_PRIO, NULL);
        mon->flags = flags;
+       mon->tmode = tmode;
        mon->magic = COBALT_MONITOR_MAGIC;
        INIT_LIST_HEAD(&mon->waiters);
        kq = cobalt_kqueues(pshared);
@@ -225,10 +230,10 @@ int cobalt_monitor_wait(struct cobalt_monitor_shadow 
__user *u_monsh,
        struct cobalt_monitor *mon = NULL;
        struct cobalt_monitor_data *datp;
        xnticks_t timeout = XN_INFINITE;
-       xntmode_t tmode = XN_RELATIVE;
        int ret = 0, opret = 0, info;
        struct xnsynch *synch;
        struct timespec ts;
+       xntmode_t tmode;
        spl_t s;
 
        __xn_get_user(mon, &u_monsh->monitor);
@@ -237,7 +242,6 @@ int cobalt_monitor_wait(struct cobalt_monitor_shadow __user 
*u_monsh,
                if (__xn_safe_copy_from_user(&ts, u_ts, sizeof(ts)))
                        return -EFAULT;
                timeout = ts2ns(&ts) + 1;
-               tmode = XN_ABSOLUTE;
        }
 
        xnlock_get_irqsave(&nklock, s);
@@ -270,6 +274,7 @@ int cobalt_monitor_wait(struct cobalt_monitor_shadow __user 
*u_monsh,
        }
        datp->flags |= COBALT_MONITOR_PENDED;
 
+       tmode = u_ts ? mon->tmode : XN_RELATIVE;
        info = xnsynch_sleep_on(synch, timeout, tmode);
        if (info) {
                if ((info & XNRMID) != 0 ||
diff --git a/kernel/cobalt/posix/monitor.h b/kernel/cobalt/posix/monitor.h
index a4af392..e8ca7ef 100644
--- a/kernel/cobalt/posix/monitor.h
+++ b/kernel/cobalt/posix/monitor.h
@@ -33,9 +33,11 @@ struct cobalt_monitor {
        struct list_head link;
        struct list_head waiters;
        int flags;
+       xntmode_t tmode;
 };
 
 int cobalt_monitor_init(struct cobalt_monitor_shadow __user *u_monsh,
+                       clockid_t clk_id,
                        int flags);
 
 int cobalt_monitor_enter(struct cobalt_monitor_shadow __user *u_monsh);
diff --git a/lib/cobalt/internal.c b/lib/cobalt/internal.c
index 603791b..64f7acc 100644
--- a/lib/cobalt/internal.c
+++ b/lib/cobalt/internal.c
@@ -105,14 +105,14 @@ struct cobalt_monitor_data 
*get_monitor_data(cobalt_monitor_t *mon)
                mon->u.data;
 }
 
-int cobalt_monitor_init(cobalt_monitor_t *mon, int flags)
+int cobalt_monitor_init(cobalt_monitor_t *mon, clockid_t clk_id, int flags)
 {
        struct cobalt_monitor_data *datp;
        int ret;
 
-       ret = XENOMAI_SKINCALL2(__cobalt_muxid,
+       ret = XENOMAI_SKINCALL3(__cobalt_muxid,
                                sc_cobalt_monitor_init,
-                               mon, flags);
+                               mon, clk_id, flags);
        if (ret)
                return ret;
 
diff --git a/lib/cobalt/internal.h b/lib/cobalt/internal.h
index 6a32f3f..1816c20 100644
--- a/lib/cobalt/internal.h
+++ b/lib/cobalt/internal.h
@@ -21,6 +21,7 @@
 #include <signal.h>
 #include <pthread.h>
 #include <errno.h>
+#include <time.h>
 #include <nocore/atomic.h>
 #include <cobalt/uapi/kernel/synch.h>
 #include <cobalt/uapi/kernel/vdso.h>
@@ -67,7 +68,8 @@ int __cobalt_thread_stat(pid_t pid,
 
 int __cobalt_serial_debug(const char *fmt, ...);
 
-int cobalt_monitor_init(cobalt_monitor_t *mon, int flags);
+int cobalt_monitor_init(cobalt_monitor_t *mon,
+                       clockid_t clk_id, int flags);
 
 int cobalt_monitor_destroy(cobalt_monitor_t *mon);
 


_______________________________________________
Xenomai-git mailing list
Xenomai-git@xenomai.org
http://www.xenomai.org/mailman/listinfo/xenomai-git

Reply via email to