OpenCores
URL https://opencores.org/ocsvn/openrisc_2011-10-31/openrisc_2011-10-31/trunk

Subversion Repositories openrisc_2011-10-31

[/] [openrisc/] [trunk/] [rtos/] [ecos-2.0/] [packages/] [kernel/] [v2_0/] [include/] [mqueue.hxx] - Blame information for rev 27

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 27 unneback
#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 Red Hat, 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 version.
18
//
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
22
// for more details.
23
//
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.
27
//
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.
34
//
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.
37
//
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####
44
//
45
// Author(s):     jlarmour
46
// Contributors:
47
// Date:          2000-05-09
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
54
//                message lengths
55
// Usage:         #include 
56
//
57
//####DESCRIPTIONEND####
58
//
59
//======================================================================
60
*/
61
 
62
/* CONFIGURATION */
63
 
64
#include           /* Configuration header */
65
 
66
/* INCLUDES */
67
 
68
#include                   /* size_t */
69
#include       /* Types */
70
#include        /* CYGDBG_DEFINE_CHECK_THIS,
71
                                        CYGDBG_USE_ASSERTS */
72
#include        /* Kernel package types */
73
#include        /* Cyg_Counting_Semaphore */
74
 
75
/* CLASSES */
76
 
77
class Cyg_Mqueue {
78
public:
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);
82
 
83
    typedef enum {
84
        OK=0,
85
        NOMEM,
86
        WOULDBLOCK,
87
#ifdef CYGFUN_KERNEL_THREADS_TIMER
88
        TIMEOUT,
89
#endif
90
        INTR
91
    } qerr_t;
92
 
93
protected:
94
    struct qentry {
95
        struct qentry *next;
96
        unsigned int priority;
97
        size_t buflen;
98
        volatile bool busy;
99
        // data buffer follows here
100
        char *buf() const { return (char *)this + sizeof(*this); }
101
    };
102
 
103
    Cyg_Counting_Semaphore putsem, getsem;
104
 
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
108
                                 // area
109
 
110
    size_t queuespacesize;
111
 
112
    qfree_fn_t free_fn;          // how to free queuespace when we destruct
113
 
114
    callback_fn_t callback;
115
    CYG_ADDRWORD callback_data;
116
 
117
    CYGDBG_DEFINE_CHECK_THIS
118
 
119
#ifdef CYGDBG_USE_ASSERTS
120
    long qlen;
121
    size_t msgsize;
122
#endif
123
 
124
public:
125
 
126
    Cyg_Mqueue( long maxmsgs, long maxmsgsize,
127
                qalloc_fn_t qalloc, qfree_fn_t qfree, qerr_t *err );
128
    ~Cyg_Mqueue();
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
133
#endif
134
              );
135
 
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
142
#endif
143
              );
144
 
145
    // count() returns the number of messages in the queue
146
    long count();
147
 
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);
154
 
155
}; /* class Cyg_Mqueue */
156
 
157
#ifndef CYGIMP_KERNEL_SYNCH_MQUEUE_NOT_INLINE
158
# include 
159
#endif
160
 
161
#endif /* CYGONCE_KERNEL_MQUEUE_HXX multiple inclusion protection */
162
 
163
/* EOF mqueue.hxx */

powered by: WebSVN 2.1.0

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