annotate packages/kernel/current/include/mboxt2.hxx @ 143:6b5f480c6929 ecos-sw-2000-12-08

Merge from eCos master repository on 2000-12-08-02:09:36-GMT
author jlarmour
date Fri, 08 Dec 2000 03:30:06 +0000
parents bf00f99aec69
children e0c0827131d1
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
1 #ifndef CYGONCE_KERNEL_MBOXT2_HXX
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
2 #define CYGONCE_KERNEL_MBOXT2_HXX
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
3
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
4 //==========================================================================
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
5 //
2
443894e2e912 Block commit of eCos version 1.2.1
jlarmour
parents: 0
diff changeset
6 // mboxt2.hxx
0
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
7 //
2
443894e2e912 Block commit of eCos version 1.2.1
jlarmour
parents: 0
diff changeset
8 // Mboxt2 (Message Box/Mailbox) class declarations
0
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
9 //
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
10 //==========================================================================
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
11 //####COPYRIGHTBEGIN####
64
c38311975d4f Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents: 2
diff changeset
12 //
c38311975d4f Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents: 2
diff changeset
13 // -------------------------------------------
c38311975d4f Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents: 2
diff changeset
14 // The contents of this file are subject to the Red Hat eCos Public License
66
bf00f99aec69 Merge from eCos master repository on 2000-02-02-19:16:44-GMT
jlarmour
parents: 64
diff changeset
15 // Version 1.1 (the "License"); you may not use this file except in
64
c38311975d4f Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents: 2
diff changeset
16 // compliance with the License. You may obtain a copy of the License at
66
bf00f99aec69 Merge from eCos master repository on 2000-02-02-19:16:44-GMT
jlarmour
parents: 64
diff changeset
17 // http://www.redhat.com/
64
c38311975d4f Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents: 2
diff changeset
18 //
66
bf00f99aec69 Merge from eCos master repository on 2000-02-02-19:16:44-GMT
jlarmour
parents: 64
diff changeset
19 // Software distributed under the License is distributed on an "AS IS"
64
c38311975d4f Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents: 2
diff changeset
20 // basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
c38311975d4f Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents: 2
diff changeset
21 // License for the specific language governing rights and limitations under
c38311975d4f Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents: 2
diff changeset
22 // the License.
c38311975d4f Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents: 2
diff changeset
23 //
c38311975d4f Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents: 2
diff changeset
24 // The Original Code is eCos - Embedded Configurable Operating System,
c38311975d4f Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents: 2
diff changeset
25 // released September 30, 1998.
c38311975d4f Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents: 2
diff changeset
26 //
c38311975d4f Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents: 2
diff changeset
27 // The Initial Developer of the Original Code is Red Hat.
c38311975d4f Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents: 2
diff changeset
28 // Portions created by Red Hat are
c38311975d4f Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents: 2
diff changeset
29 // Copyright (C) 1998, 1999, 2000 Red Hat, Inc.
c38311975d4f Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents: 2
diff changeset
30 // All Rights Reserved.
c38311975d4f Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents: 2
diff changeset
31 // -------------------------------------------
c38311975d4f Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents: 2
diff changeset
32 //
0
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
33 //####COPYRIGHTEND####
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
34 //==========================================================================
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
35 //#####DESCRIPTIONBEGIN####
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
36 //
2
443894e2e912 Block commit of eCos version 1.2.1
jlarmour
parents: 0
diff changeset
37 // Author(s): hmt
443894e2e912 Block commit of eCos version 1.2.1
jlarmour
parents: 0
diff changeset
38 // Contributors: hmt
443894e2e912 Block commit of eCos version 1.2.1
jlarmour
parents: 0
diff changeset
39 // Date: 1998-02-10
443894e2e912 Block commit of eCos version 1.2.1
jlarmour
parents: 0
diff changeset
40 // Purpose: Define Mboxt2 class interfaces
443894e2e912 Block commit of eCos version 1.2.1
jlarmour
parents: 0
diff changeset
41 // Description: The classes defined here provide the APIs for mboxt2es.
443894e2e912 Block commit of eCos version 1.2.1
jlarmour
parents: 0
diff changeset
42 // Usage: #include <cyg/kernel/mboxt2.hxx>
443894e2e912 Block commit of eCos version 1.2.1
jlarmour
parents: 0
diff changeset
43 // #include <cyg/kernel/mboxt2.inl>
443894e2e912 Block commit of eCos version 1.2.1
jlarmour
parents: 0
diff changeset
44 //
0
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
45 //
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
46 //####DESCRIPTIONEND####
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
47 //
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
48 //==========================================================================
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
49
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
50 #include <cyg/kernel/ktypes.h>
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
51 #include <cyg/infra/cyg_ass.h> // assertion macros
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
52 #include <cyg/kernel/thread.hxx>
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
53 #include <cyg/kernel/thread.inl>
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
54
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
55 // -------------------------------------------------------------------------
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
56 // Message/Mail Box. This template implements a queue of T's.
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
57 // Implemented as a template for maximal flexibility; one would hope
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
58 // that only one, with T==(void *) and the same number of them,
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
59 // is ever used without very good reason.
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
60
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
61 // Cyg_Mboxt2 has a fixed size array of T's; one size fits all.
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
62
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
63 template <class T, cyg_count32 QUEUE_SIZE>
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
64 class Cyg_Mboxt2
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
65 {
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
66 private:
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
67 cyg_count32 base; // index of first used slot
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
68 cyg_count32 count; // count of used slots
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
69 Cyg_ThreadQueue get_threadq; // Queue of waiting threads
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
70 #ifdef CYGMFN_KERNEL_SYNCH_MBOXT_PUT_CAN_WAIT
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
71 Cyg_ThreadQueue put_threadq; // Queue of waiting threads
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
72 #endif
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
73 static const
2
443894e2e912 Block commit of eCos version 1.2.1
jlarmour
parents: 0
diff changeset
74 cyg_count32 size = QUEUE_SIZE;
443894e2e912 Block commit of eCos version 1.2.1
jlarmour
parents: 0
diff changeset
75 T itemqueue[ QUEUE_SIZE ];
0
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
76 // queue of items
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
77 // private utility functions
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
78 // wake up a thread from some queue
2
443894e2e912 Block commit of eCos version 1.2.1
jlarmour
parents: 0
diff changeset
79 inline void wakeup_winner( const T &msg );
0
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
80 #ifdef CYGMFN_KERNEL_SYNCH_MBOXT_PUT_CAN_WAIT
2
443894e2e912 Block commit of eCos version 1.2.1
jlarmour
parents: 0
diff changeset
81 inline void wakeup_putter( void );
0
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
82 #endif
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
83
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
84 public:
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
85
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
86 CYGDBG_DEFINE_CHECK_THIS
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
87
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
88 Cyg_Mboxt2(); // Constructor
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
89 ~Cyg_Mboxt2(); // Destructor
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
90
2
443894e2e912 Block commit of eCos version 1.2.1
jlarmour
parents: 0
diff changeset
91 cyg_bool get( T &ritem ); // get an item; wait if none
0
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
92 #ifdef CYGFUN_KERNEL_THREADS_TIMER
2
443894e2e912 Block commit of eCos version 1.2.1
jlarmour
parents: 0
diff changeset
93 cyg_bool get( T &ritem, cyg_tick_count abs_timeout );
0
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
94 #endif
2
443894e2e912 Block commit of eCos version 1.2.1
jlarmour
parents: 0
diff changeset
95 cyg_bool tryget( T &ritem ); // just one attempt
0
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
96
2
443894e2e912 Block commit of eCos version 1.2.1
jlarmour
parents: 0
diff changeset
97 cyg_bool peek_item( T &ritem ); // get next item without
0
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
98 // removing it
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
99
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
100 #ifdef CYGMFN_KERNEL_SYNCH_MBOXT_PUT_CAN_WAIT
2
443894e2e912 Block commit of eCos version 1.2.1
jlarmour
parents: 0
diff changeset
101 cyg_bool put( const T item ); // put an item; wait if full
0
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
102 #ifdef CYGFUN_KERNEL_THREADS_TIMER
2
443894e2e912 Block commit of eCos version 1.2.1
jlarmour
parents: 0
diff changeset
103 cyg_bool put( const T item, cyg_tick_count abs_timeout );
0
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
104 #endif
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
105 #endif
2
443894e2e912 Block commit of eCos version 1.2.1
jlarmour
parents: 0
diff changeset
106 cyg_bool tryput( const T item ); // fails if Q full
0
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
107
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
108 inline
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
109 cyg_count32 peek() // Get current count value
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
110 {
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
111 return count;
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
112 }
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
113
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
114 inline
2
443894e2e912 Block commit of eCos version 1.2.1
jlarmour
parents: 0
diff changeset
115 cyg_bool waiting_to_get() // Any threads waiting?
0
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
116 {
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
117 return ! get_threadq.empty();
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
118 }
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
119
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
120 inline
2
443894e2e912 Block commit of eCos version 1.2.1
jlarmour
parents: 0
diff changeset
121 cyg_bool waiting_to_put() // Any threads waiting?
0
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
122 {
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
123 #ifdef CYGMFN_KERNEL_SYNCH_MBOXT_PUT_CAN_WAIT
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
124 return ! put_threadq.empty();
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
125 #else
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
126 return false;
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
127 #endif
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
128 }
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
129 };
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
130
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
131 // -------------------------------------------------------------------------
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
132 #endif // ifndef CYGONCE_KERNEL_MBOXT2_HXX
3111d98ba7b3 Initial commit of eCos version 1.1
jlarmour
parents:
diff changeset
133 // EOF mboxt2.hxx