1 #ifndef CYGONCE_KERNEL_MQUEUE_HXX
2 #define CYGONCE_KERNEL_MQUEUE_HXX
3 /*========================================================================
9 //========================================================================
10 //####ECOSGPLCOPYRIGHTBEGIN####
11 // -------------------------------------------
12 // This file is part of eCos, the Embedded Configurable Operating System.
13 // Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
15 // eCos is free software; you can redistribute it and/or modify it under
16 // the terms of the GNU General Public License as published by the Free
17 // Software Foundation; either version 2 or (at your option) any later version.
19 // eCos is distributed in the hope that it will be useful, but WITHOUT ANY
20 // WARRANTY; without even the implied warranty of MERCHANTABILITY or
21 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
24 // You should have received a copy of the GNU General Public License along
25 // with eCos; if not, write to the Free Software Foundation, Inc.,
26 // 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
28 // As a special exception, if other files instantiate templates or use macros
29 // or inline functions from this file, or you compile this file and link it
30 // with other works to produce a work based on this file, this file does not
31 // by itself cause the resulting work to be covered by the GNU General Public
32 // License. However the source code for this file must still be made available
33 // in accordance with section (3) of the GNU General Public License.
35 // This exception does not invalidate any other reasons why a work based on
36 // this file might be covered by the GNU General Public License.
38 // Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
39 // at http://sources.redhat.com/ecos/ecos-license/
40 // -------------------------------------------
41 //####ECOSGPLCOPYRIGHTEND####
42 //========================================================================
43 //#####DESCRIPTIONBEGIN####
45 // Author(s): jlarmour
48 // Purpose: This file provides the interface for eCos message queues
49 // Description: This differs from the message boxes also supported by
50 // eCos primarily because the requirements of message
51 // queues are driven by POSIX semantics. POSIX semantics are
52 // more dynamic and therefore heavyweight than Mboxes,
53 // including prioritization, and variable sized queues and
55 // Usage: #include <cyg/kernel/mqueue.hxx>
57 //####DESCRIPTIONEND####
59 //======================================================================
64 #include <pkgconf/kernel.h> /* Configuration header */
68 #include <stddef.h> /* size_t */
69 #include <cyg/infra/cyg_type.h> /* Types */
70 #include <cyg/infra/cyg_ass.h> /* CYGDBG_DEFINE_CHECK_THIS,
72 #include <cyg/kernel/ktypes.h> /* Kernel package types */
73 #include <cyg/kernel/sema.hxx> /* Cyg_Counting_Semaphore */
79 typedef void (*callback_fn_t)(Cyg_Mqueue &q, CYG_ADDRWORD data);
80 typedef void * (*qalloc_fn_t)(size_t len);
81 typedef void (*qfree_fn_t)(void *ptr, size_t len);
87 #ifdef CYGFUN_KERNEL_THREADS_TIMER
96 unsigned int priority;
99 // data buffer follows here
100 char *buf() const { return (char *)this + sizeof(*this); }
103 Cyg_Counting_Semaphore putsem, getsem;
105 struct qentry *q; // q entries in use
106 struct qentry *freelist; // q entries not in use
107 void *queuespace; // placeholder for the dynamically allocated
110 size_t queuespacesize;
112 qfree_fn_t free_fn; // how to free queuespace when we destruct
114 callback_fn_t callback;
115 CYG_ADDRWORD callback_data;
117 CYGDBG_DEFINE_CHECK_THIS
119 #ifdef CYGDBG_USE_ASSERTS
126 Cyg_Mqueue( long maxmsgs, long maxmsgsize,
127 qalloc_fn_t qalloc, qfree_fn_t qfree, qerr_t *err );
129 // put() copies len bytes of *buf into the queue at priority prio
130 qerr_t put( const char *buf, size_t len, unsigned int prio, bool block=true
131 #ifdef CYGFUN_KERNEL_THREADS_TIMER
132 ,cyg_tick_count timeout = 0
136 // get() returns the oldest highest priority message in the queue in *buf
137 // and sets *prio to the priority (if prio is non-NULL) and *len to the
138 // actual message size
139 qerr_t get( char *buf, size_t *len, unsigned int *prio, bool block=true
140 #ifdef CYGFUN_KERNEL_THREADS_TIMER
141 ,cyg_tick_count timeout = 0
145 // count() returns the number of messages in the queue
148 // Supply a callback function to call (with the supplied data argument)
149 // when the queue goes from empty to non-empty (unless someone's already
150 // doing a get()). This returns the old callback_fn, and if olddata is
151 // non-NULL sets it to the old data (yes, really!)
152 callback_fn_t setnotify( callback_fn_t callback_fn, CYG_ADDRWORD data,
153 CYG_ADDRWORD *olddata=NULL);
155 }; /* class Cyg_Mqueue */
157 #ifndef CYGIMP_KERNEL_SYNCH_MQUEUE_NOT_INLINE
158 # include <cyg/kernel/mqueue.inl>
161 #endif /* CYGONCE_KERNEL_MQUEUE_HXX multiple inclusion protection */