OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [kernel/] [current/] [include/] [mqueue.hxx] - Blame information for rev 786

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 786 skrzyp
#ifndef CYGONCE_KERNEL_MQUEUE_HXX
2
#define CYGONCE_KERNEL_MQUEUE_HXX
3
/*========================================================================
4
//
5
//      mqueue.hxx
6
//
7
//      Message queues
8
//
9
//========================================================================
10
// ####ECOSGPLCOPYRIGHTBEGIN####
11
// -------------------------------------------
12
// This file is part of eCos, the Embedded Configurable Operating System.
13
// Copyright (C) 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
14
//
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
18
// version.
19
//
20
// eCos is distributed in the hope that it will be useful, but WITHOUT
21
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
22
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
23
// for more details.
24
//
25
// You should have received a copy of the GNU General Public License
26
// along with eCos; if not, write to the Free Software Foundation, Inc.,
27
// 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
28
//
29
// As a special exception, if other files instantiate templates or use
30
// macros or inline functions from this file, or you compile this file
31
// and link it with other works to produce a work based on this file,
32
// this file does not by itself cause the resulting work to be covered by
33
// the GNU General Public License. However the source code for this file
34
// must still be made available in accordance with section (3) of the GNU
35
// General Public License v2.
36
//
37
// This exception does not invalidate any other reasons why a work based
38
// on this file might be covered by the GNU General Public License.
39
// -------------------------------------------
40
// ####ECOSGPLCOPYRIGHTEND####
41
//========================================================================
42
//#####DESCRIPTIONBEGIN####
43
//
44
// Author(s):     jlarmour
45
// Contributors:
46
// Date:          2000-05-09
47
// Purpose:       This file provides the interface for eCos message queues
48
// Description:   This differs from the message boxes also supported by
49
//                eCos primarily because the requirements of message
50
//                queues are driven by POSIX semantics. POSIX semantics are
51
//                more dynamic and therefore heavyweight than Mboxes,
52
//                including prioritization, and variable sized queues and
53
//                message lengths
54
// Usage:         #include 
55
//
56
//####DESCRIPTIONEND####
57
//
58
//======================================================================
59
*/
60
 
61
/* CONFIGURATION */
62
 
63
#include           /* Configuration header */
64
 
65
/* INCLUDES */
66
 
67
#include                   /* size_t */
68
#include       /* Types */
69
#include        /* CYGDBG_DEFINE_CHECK_THIS,
70
                                        CYGDBG_USE_ASSERTS */
71
#include        /* Kernel package types */
72
#include        /* Cyg_Counting_Semaphore */
73
 
74
/* CLASSES */
75
 
76
class Cyg_Mqueue {
77
public:
78
    typedef void (*callback_fn_t)(Cyg_Mqueue &q, CYG_ADDRWORD data);
79
    typedef void * (*qalloc_fn_t)(size_t len);
80
    typedef void (*qfree_fn_t)(void *ptr, size_t len);
81
 
82
    typedef enum {
83
        OK=0,
84
        NOMEM,
85
        WOULDBLOCK,
86
#ifdef CYGFUN_KERNEL_THREADS_TIMER
87
        TIMEOUT,
88
#endif
89
        INTR
90
    } qerr_t;
91
 
92
protected:
93
    struct qentry {
94
        struct qentry *next;
95
        unsigned int priority;
96
        size_t buflen;
97
        volatile bool busy;
98
        // data buffer follows here
99
        char *buf() const { return (char *)this + sizeof(*this); }
100
    };
101
 
102
    Cyg_Counting_Semaphore putsem, getsem;
103
 
104
    struct qentry *q;            // q entries in use
105
    struct qentry *freelist;     // q entries not in use
106
    void *queuespace;            // placeholder for the dynamically allocated
107
                                 // area
108
 
109
    size_t queuespacesize;
110
 
111
    qfree_fn_t free_fn;          // how to free queuespace when we destruct
112
 
113
    callback_fn_t callback;
114
    CYG_ADDRWORD callback_data;
115
 
116
    CYGDBG_DEFINE_CHECK_THIS
117
 
118
#ifdef CYGDBG_USE_ASSERTS
119
    long qlen;
120
    size_t msgsize;
121
#endif
122
 
123
public:
124
 
125
    Cyg_Mqueue( long maxmsgs, long maxmsgsize,
126
                qalloc_fn_t qalloc, qfree_fn_t qfree, qerr_t *err );
127
    ~Cyg_Mqueue();
128
    // put() copies len bytes of *buf into the queue at priority prio
129
    qerr_t put( const char *buf, size_t len, unsigned int prio, bool block=true
130
#ifdef CYGFUN_KERNEL_THREADS_TIMER
131
                ,cyg_tick_count timeout = 0
132
#endif
133
              );
134
 
135
    // get() returns the oldest highest priority message in the queue in *buf
136
    // and sets *prio to the priority (if prio is non-NULL) and *len to the
137
    // actual message size
138
    qerr_t get( char *buf, size_t *len, unsigned int *prio, bool block=true
139
#ifdef CYGFUN_KERNEL_THREADS_TIMER
140
                ,cyg_tick_count timeout = 0
141
#endif
142
              );
143
 
144
    // count() returns the number of messages in the queue
145
    long count();
146
 
147
    // Supply a callback function to call (with the supplied data argument)
148
    // when the queue goes from empty to non-empty (unless someone's already
149
    // doing a get()). This returns the old callback_fn, and if olddata is
150
    // non-NULL sets it to the old data (yes, really!)
151
    callback_fn_t setnotify( callback_fn_t callback_fn, CYG_ADDRWORD data,
152
                             CYG_ADDRWORD *olddata=NULL);
153
 
154
}; /* class Cyg_Mqueue */
155
 
156
#ifndef CYGIMP_KERNEL_SYNCH_MQUEUE_NOT_INLINE
157
# include 
158
#endif
159
 
160
#endif /* CYGONCE_KERNEL_MQUEUE_HXX multiple inclusion protection */
161
 
162
/* EOF mqueue.hxx */

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.