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