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

Author: Philippe Gerum <r...@xenomai.org>
Date:   Sat Sep 12 00:56:50 2009 +0200

native: introduce rt_queue_flush() service

---

 include/native/queue.h        |    2 +
 include/native/syscall.h      |    1 +
 ksrc/skins/native/API.CHANGES |    8 +++++
 ksrc/skins/native/queue.c     |   67 +++++++++++++++++++++++++++++++++++++++++
 ksrc/skins/native/syscall.c   |   22 +++++++++++++
 src/skins/native/queue.c      |    5 +++
 6 files changed, 105 insertions(+), 0 deletions(-)

diff --git a/include/native/queue.h b/include/native/queue.h
index c68137f..77925c2 100644
--- a/include/native/queue.h
+++ b/include/native/queue.h
@@ -218,6 +218,8 @@ ssize_t rt_queue_read_until(RT_QUEUE *q,
                            size_t size,
                            RTIME timeout);
 
+int rt_queue_flush(RT_QUEUE *q);
+
 int rt_queue_inquire(RT_QUEUE *q,
                     RT_QUEUE_INFO *info);
 
diff --git a/include/native/syscall.h b/include/native/syscall.h
index 5d8c79e..cd9e64a 100644
--- a/include/native/syscall.h
+++ b/include/native/syscall.h
@@ -126,6 +126,7 @@
 #define __native_buffer_write       100
 #define __native_buffer_clear       101
 #define __native_buffer_inquire     102
+#define __native_queue_flush        103
 
 struct rt_arg_bulk {
 
diff --git a/ksrc/skins/native/API.CHANGES b/ksrc/skins/native/API.CHANGES
index c6508e8..5f73cbf 100644
--- a/ksrc/skins/native/API.CHANGES
+++ b/ksrc/skins/native/API.CHANGES
@@ -272,3 +272,11 @@ 
___________________________________________________________________
        * rt_task_set_mode() does not support the T_RRB bit
          anymore. Round-robin scheduling should be controlled using
          the rt_task_slice() service instead.
+
+___________________________________________________________________
+
+
+2.5-rc3 -> 2.5-rc4
+
+       * New rt_queue_flush() service to discard all unread messages
+       from a queue.
diff --git a/ksrc/skins/native/queue.c b/ksrc/skins/native/queue.c
index 8e2bb6f..4bb44aa 100644
--- a/ksrc/skins/native/queue.c
+++ b/ksrc/skins/native/queue.c
@@ -1113,6 +1113,72 @@ ssize_t rt_queue_read_until(RT_QUEUE *q, void *buf, 
size_t size, RTIME timeout)
 }
 
 /**
+ * @fn int rt_queue_flush(RT_QUEUE *q)
+ *
+ * @brief Flush a message queue.
+ *
+ * This service discards all unread messages from a message queue.
+ *
+ * @param q The descriptor address of the affected queue.
+ *
+ * @return The number of messages flushed is returned upon
+ * success. Otherwise:
+ *
+ * - -EINVAL is returned if @a q is not a message queue descriptor.
+ *
+ * - -EIDRM is returned if @a q is a deleted queue descriptor.
+ *
+ * Environments:
+ *
+ * This service can be called from:
+ *
+ * - Kernel module initialization/cleanup code
+ * - Interrupt service routine
+ * - Kernel-based task
+ * - User-space task
+ *
+ * Rescheduling: never.
+ */
+
+int rt_queue_flush(RT_QUEUE *q)
+{
+       struct rt_queue_msg *msg;
+       struct xnqueue tmpq;
+       struct xnholder *h;
+       int ret, count;
+       spl_t s;
+
+       xnlock_get_irqsave(&nklock, s);
+
+       q = xeno_h2obj_validate(q, XENO_QUEUE_MAGIC, RT_QUEUE);
+       if (q == NULL) {
+               ret = xeno_handle_error(q, XENO_QUEUE_MAGIC, RT_QUEUE);
+               xnlock_put_irqrestore(&nklock, s);
+               return ret;
+       }
+
+       /*
+        * Transfer the contents to a private queue by moving queue
+        * heads, so that we may free any number of messages without
+        * holding the nklock.
+        */ 
+       initq(&tmpq);
+       moveq(&tmpq, &q->pendq);
+
+       xnlock_put_irqrestore(&nklock, s);
+
+       count = countq(&tmpq);
+
+       while ((h = getq(&tmpq)) != NULL) {
+               msg = link2rtmsg(h);
+               /* no need to check anything - msg must be valid */
+               xnheap_test_and_free(&q->bufpool, msg, NULL);
+       }
+
+       return count;
+}
+
+/**
  * @fn int rt_queue_inquire(RT_QUEUE *q, RT_QUEUE_INFO *info)
  *
  * @brief Inquire about a message queue.
@@ -1285,4 +1351,5 @@ EXPORT_SYMBOL(rt_queue_receive);
 EXPORT_SYMBOL(rt_queue_receive_until);
 EXPORT_SYMBOL(rt_queue_read);
 EXPORT_SYMBOL(rt_queue_read_until);
+EXPORT_SYMBOL(rt_queue_flush);
 EXPORT_SYMBOL(rt_queue_inquire);
diff --git a/ksrc/skins/native/syscall.c b/ksrc/skins/native/syscall.c
index 79ca84c..1e8ece9 100644
--- a/ksrc/skins/native/syscall.c
+++ b/ksrc/skins/native/syscall.c
@@ -2445,6 +2445,26 @@ static int __rt_queue_inquire(struct pt_regs *regs)
        return 0;
 }
 
+/*
+ * int __rt_queue_flush(RT_QUEUE_PLACEHOLDER *ph)
+ */
+
+static int __rt_queue_flush(struct pt_regs *regs)
+{
+       RT_QUEUE_PLACEHOLDER ph;
+       RT_QUEUE *q;
+
+       if (__xn_safe_copy_from_user(&ph, (void __user *)__xn_reg_arg1(regs),
+                                    sizeof(ph)))
+               return -EFAULT;
+
+       q = xnregistry_fetch(ph.opaque);
+       if (q == NULL)
+               return -ESRCH;
+
+       return rt_queue_flush(q);
+}
+
 #else /* !CONFIG_XENO_OPT_NATIVE_QUEUE */
 
 #define __rt_queue_create    __rt_call_not_available
@@ -2457,6 +2477,7 @@ static int __rt_queue_inquire(struct pt_regs *regs)
 #define __rt_queue_inquire   __rt_call_not_available
 #define __rt_queue_read      __rt_call_not_available
 #define __rt_queue_write     __rt_call_not_available
+#define __rt_queue_flush     __rt_call_not_available
 
 #endif /* CONFIG_XENO_OPT_NATIVE_QUEUE */
 
@@ -4051,6 +4072,7 @@ static xnsysent_t __systab[] = {
        [__native_queue_receive] = {&__rt_queue_receive, __xn_exec_primary},
        [__native_queue_read] = {&__rt_queue_read, __xn_exec_primary},
        [__native_queue_inquire] = {&__rt_queue_inquire, __xn_exec_any},
+       [__native_queue_flush] = {&__rt_queue_flush, __xn_exec_any},
        [__native_heap_create] = {&__rt_heap_create, __xn_exec_lostage},
        [__native_heap_bind] = {&__rt_heap_bind, __xn_exec_conforming},
        [__native_heap_delete] = {&__rt_heap_delete, __xn_exec_lostage},
diff --git a/src/skins/native/queue.c b/src/skins/native/queue.c
index 0db9d90..829fca1 100644
--- a/src/skins/native/queue.c
+++ b/src/skins/native/queue.c
@@ -184,3 +184,8 @@ int rt_queue_inquire(RT_QUEUE *q, RT_QUEUE_INFO *info)
        return XENOMAI_SKINCALL2(__native_muxid, __native_queue_inquire, q,
                                 info);
 }
+
+int rt_queue_flush(RT_QUEUE *q)
+{
+       return XENOMAI_SKINCALL1(__native_muxid, __native_queue_flush, q);
+}


_______________________________________________
Xenomai-git mailing list
Xenomai-git@gna.org
https://mail.gna.org/listinfo/xenomai-git

Reply via email to