comparison packages/kernel/current/include/mqueue.hxx @ 115:6ed91473a1cd ecos-sw-2000-08-21

Merge from eCos master repository on 2000-08-21-22:40:54-BST
author jlarmour
date Fri, 25 Aug 2000 17:32:38 +0000
parents
children 678094f34118
comparison
equal deleted inserted replaced
114:5ad2b71d525e 115:6ed91473a1cd
1 #ifndef CYGONCE_KERNEL_MQUEUE_HXX
2 #define CYGONCE_KERNEL_MQUEUE_HXX
3 /*========================================================================
4 //
5 // mqueue.hxx
6 //
7 // Message queues
8 //
9 //========================================================================
10 //####COPYRIGHTBEGIN####
11 //
12 // -------------------------------------------
13 // The contents of this file are subject to the Red Hat eCos Public License
14 // Version 1.1 (the "License"); you may not use this file except in
15 // compliance with the License. You may obtain a copy of the License at
16 // http://www.redhat.com/
17 //
18 // Software distributed under the License is distributed on an "AS IS"
19 // basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
20 // License for the specific language governing rights and limitations under
21 // the License.
22 //
23 // The Original Code is eCos - Embedded Configurable Operating System,
24 // released September 30, 1998.
25 //
26 // The Initial Developer of the Original Code is Red Hat.
27 // Portions created by Red Hat are
28 // Copyright (C) 1998, 1999, 2000 Red Hat, Inc.
29 // All Rights Reserved.
30 // -------------------------------------------
31 //
32 //####COPYRIGHTEND####
33 //========================================================================
34 //#####DESCRIPTIONBEGIN####
35 //
36 // Author(s): jlarmour
37 // Contributors:
38 // Date: 2000-05-09
39 // Purpose: This file provides the interface for eCos message queues
40 // Description: This differs from the message boxes also supported by
41 // eCos primarily because the requirements of message
42 // queues are driven by POSIX semantics. POSIX semantics are
43 // more dynamic and therefore heavyweight than Mboxes,
44 // including prioritization, and variable sized queues and
45 // message lengths
46 // Usage: #include <cyg/kernel/mqueue.hxx>
47 //
48 //####DESCRIPTIONEND####
49 //
50 //======================================================================
51 */
52
53 /* CONFIGURATION */
54
55 #include <pkgconf/kernel.h> /* Configuration header */
56
57 /* INCLUDES */
58
59 #include <stddef.h> /* size_t */
60 #include <cyg/infra/cyg_type.h> /* Types */
61 #include <cyg/infra/cyg_ass.h> /* CYGDBG_DEFINE_CHECK_THIS,
62 CYGDBG_USE_ASSERTS */
63 #include <cyg/kernel/sema.hxx> /* Cyg_Counting_Semaphore */
64
65 /* CLASSES */
66
67 class Cyg_Mqueue {
68 public:
69 typedef void (*callback_fn_t)(Cyg_Mqueue &q, CYG_ADDRWORD data);
70 typedef void * (*qalloc_fn_t)(size_t len);
71 typedef void (*qfree_fn_t)(void *ptr, size_t len);
72
73 typedef enum {
74 OK=0,
75 NOMEM,
76 WOULDBLOCK,
77 INTR
78 } qerr_t;
79
80 protected:
81 struct qentry {
82 struct qentry *next;
83 unsigned int priority;
84 size_t buflen;
85 volatile bool busy;
86 // data buffer follows here
87 char *buf() const { return (char *)this + sizeof(*this); }
88 };
89
90 Cyg_Counting_Semaphore putsem, getsem;
91
92 struct qentry *q; // q entries in use
93 struct qentry *freelist; // q entries not in use
94 void *queuespace; // placeholder for the dynamically allocated
95 // area
96
97 size_t queuespacesize;
98
99 qfree_fn_t free_fn; // how to free queuespace when we destruct
100
101 callback_fn_t callback;
102 CYG_ADDRWORD callback_data;
103
104 CYGDBG_DEFINE_CHECK_THIS
105
106 #ifdef CYGDBG_USE_ASSERTS
107 long qlen;
108 size_t msgsize;
109 #endif
110
111 public:
112
113 Cyg_Mqueue( long maxmsgs, long maxmsgsize,
114 qalloc_fn_t qalloc, qfree_fn_t qfree, qerr_t *err );
115 ~Cyg_Mqueue();
116
117 // put() copies len bytes of *buf into the queue at priority prio
118 qerr_t put( const char *buf, size_t len, unsigned int prio,
119 bool block=true);
120
121 // get() returns the oldest highest priority message in the queue in *buf
122 // and sets *prio to the priority (if prio is non-NULL) and *len to the
123 // actual message size
124 qerr_t get( char *buf, size_t *len, unsigned int *prio, bool block=true );
125
126 // count() returns the number of messages in the queue
127 long count();
128
129 // Supply a callback function to call (with the supplied data argument)
130 // when the queue goes from empty to non-empty (unless someone's already
131 // doing a get()). This returns the old callback_fn, and if olddata is
132 // non-NULL sets it to the old data (yes, really!)
133 callback_fn_t setnotify( callback_fn_t callback_fn, CYG_ADDRWORD data,
134 CYG_ADDRWORD *olddata=NULL);
135
136 }; /* class Cyg_Mqueue */
137
138 #include <cyg/kernel/mqueue.inl>
139
140 #endif /* CYGONCE_KERNEL_MQUEUE_HXX multiple inclusion protection */
141
142 /* EOF mqueue.hxx */