changeset 494:cffb2601409c

* include/mqueue.hxx: Allow get/put to return time out. * include mqueue.inl: Ditto.
author jlarmour
date Mon, 13 Jan 2003 05:50:23 +0000
parents 413246fac734
children 248ae32b58f8
files packages/kernel/current/ChangeLog packages/kernel/current/include/mqueue.hxx packages/kernel/current/include/mqueue.inl
diffstat 3 files changed, 48 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/packages/kernel/current/ChangeLog
+++ b/packages/kernel/current/ChangeLog
@@ -1,3 +1,9 @@
+2003-01-13  Dmitriy Korovkin  <dkorovkin@rambler.ru>
+2003-01-13  Jonathan Larmour  <jifl@eCosCentric.com>
+
+	* include/mqueue.hxx: Allow get/put to return time out.
+	* include mqueue.inl: Ditto.
+
 2003-01-02  Gary Thomas  <gary@mlbassoc.com>
 
 	* tests/kcache2.c: New subtest for raw data cache operations.
--- a/packages/kernel/current/include/mqueue.hxx
+++ b/packages/kernel/current/include/mqueue.hxx
@@ -69,6 +69,7 @@
 #include <cyg/infra/cyg_type.h>      /* Types */
 #include <cyg/infra/cyg_ass.h>       /* CYGDBG_DEFINE_CHECK_THIS,
                                         CYGDBG_USE_ASSERTS */
+#include <cyg/kernel/ktypes.h>       /* Kernel package types */
 #include <cyg/kernel/sema.hxx>       /* Cyg_Counting_Semaphore */
 
 /* CLASSES */
@@ -83,6 +84,9 @@ public:
         OK=0,
         NOMEM,
         WOULDBLOCK,
+#ifdef CYGFUN_KERNEL_THREADS_TIMER
+        TIMEOUT,
+#endif
         INTR
     } qerr_t;
 
@@ -122,15 +126,21 @@ public:
     Cyg_Mqueue( long maxmsgs, long maxmsgsize,
                 qalloc_fn_t qalloc, qfree_fn_t qfree, qerr_t *err );
     ~Cyg_Mqueue();
-
     // put() copies len bytes of *buf into the queue at priority prio
-    qerr_t put( const char *buf, size_t len, unsigned int prio,
-                bool block=true);
+    qerr_t put( const char *buf, size_t len, unsigned int prio, bool block=true
+#ifdef CYGFUN_KERNEL_THREADS_TIMER
+                ,cyg_tick_count timeout = 0
+#endif
+              );
 
     // get() returns the oldest highest priority message in the queue in *buf
     // and sets *prio to the priority (if prio is non-NULL) and *len to the
     // actual message size
-    qerr_t get( char *buf, size_t *len, unsigned int *prio, bool block=true ); 
+    qerr_t get( char *buf, size_t *len, unsigned int *prio, bool block=true
+#ifdef CYGFUN_KERNEL_THREADS_TIMER
+                ,cyg_tick_count timeout = 0
+#endif
+              ); 
 
     // count() returns the number of messages in the queue
     long count();
--- a/packages/kernel/current/include/mqueue.inl
+++ b/packages/kernel/current/include/mqueue.inl
@@ -272,7 +272,11 @@ Cyg_Mqueue::~Cyg_Mqueue()
 
 // put() copies len bytes of *buf into the queue at priority prio
 CYGPRI_KERNEL_SYNCH_MQUEUE_INLINE Cyg_Mqueue::qerr_t
-Cyg_Mqueue::put( const char *buf, size_t len, unsigned int prio, bool block )
+Cyg_Mqueue::put( const char *buf, size_t len, unsigned int prio, bool block
+#ifdef CYGFUN_KERNEL_THREADS_TIMER
+                 , cyg_tick_count timeout
+#endif
+               )
 {
     CYG_REPORT_FUNCTYPE( "err=%d");
     CYG_REPORT_FUNCARG4( "buf=%08x, len=%ld, prio=%ud, block=%d",
@@ -286,6 +290,15 @@ Cyg_Mqueue::put( const char *buf, size_t
 
     // wait till a freelist entry is available
     if ( true == block ) {
+#ifdef CYGFUN_KERNEL_THREADS_TIMER
+        if ( timeout != 0) {
+	    if ( false == putsem.wait(timeout) ) {
+                err = TIMEOUT;
+                goto exit;
+            }
+        }
+        else
+#endif
         if ( false == putsem.wait() ) {
             err = INTR;
             goto exit;
@@ -379,7 +392,11 @@ Cyg_Mqueue::put( const char *buf, size_t
 // actual message size
 
 CYGPRI_KERNEL_SYNCH_MQUEUE_INLINE Cyg_Mqueue::qerr_t
-Cyg_Mqueue::get( char *buf, size_t *len, unsigned int *prio, bool block )
+Cyg_Mqueue::get( char *buf, size_t *len, unsigned int *prio, bool block
+#ifdef CYGFUN_KERNEL_THREADS_TIMER
+                 , cyg_tick_count timeout
+#endif
+               )
 {
     CYG_REPORT_FUNCTYPE( "err=%d");
     CYG_REPORT_FUNCARG4( "buf=%08x, len=%08x, prio=%08x, block=%d",
@@ -395,6 +412,15 @@ Cyg_Mqueue::get( char *buf, size_t *len,
 
     // wait till a q entry is available
     if ( true == block ) {
+#ifdef CYGFUN_KERNEL_THREADS_TIMER
+        if ( timeout != 0) {
+            if ( false == getsem.wait(timeout) ) {
+                err = TIMEOUT;
+                goto exit;
+            }
+        }
+        else
+#endif
         if ( false == getsem.wait() ) {
             err = INTR;
             goto exit;