|
0
|
1 #ifndef CYGONCE_KERNEL_MBOXT_HXX |
|
|
2 #define CYGONCE_KERNEL_MBOXT_HXX |
|
|
3 |
|
|
4 //========================================================================== |
|
|
5 // |
|
2
|
6 // mboxt.hxx |
|
0
|
7 // |
|
2
|
8 // Mboxt (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 Mboxt class interfaces |
|
|
39 // Description: The classes defined here provide the APIs for mboxtes. |
|
|
40 // Usage: #include <cyg/kernel/mboxt.hxx> |
|
|
41 // #include <cyg/kernel/mboxt.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 |
|
|
52 // ------------------------------------------------------------------------- |
|
|
53 // Message/Mail Box. This template implements a queue of T's. |
|
|
54 // Implemented as a template for maximal flexibility; one would hope |
|
|
55 // that only one, with T==(void *) and the same number of them, |
|
|
56 // is ever used without very good reason. |
|
|
57 |
|
|
58 // Cyg_Mboxt has a fixed size array of T's; one size fits all. |
|
|
59 |
|
|
60 template <class T, cyg_count32 QUEUE_SIZE> |
|
|
61 class Cyg_Mboxt |
|
|
62 { |
|
|
63 private: |
|
|
64 cyg_count32 base; // index of first used slot |
|
|
65 cyg_count32 count; // count of used slots |
|
|
66 Cyg_ThreadQueue get_threadq; // Queue of waiting threads |
|
|
67 #ifdef CYGMFN_KERNEL_SYNCH_MBOXT_PUT_CAN_WAIT |
|
|
68 Cyg_ThreadQueue put_threadq; // Queue of waiting threads |
|
|
69 #endif |
|
|
70 static const |
|
2
|
71 cyg_count32 size = QUEUE_SIZE; |
|
|
72 T itemqueue[ QUEUE_SIZE ]; |
|
0
|
73 // queue of items |
|
|
74 // private utility functions |
|
|
75 // wake up a thread from some queue |
|
2
|
76 inline void wakeup_waiter( Cyg_ThreadQueue &q ); |
|
0
|
77 |
|
|
78 public: |
|
|
79 |
|
|
80 CYGDBG_DEFINE_CHECK_THIS |
|
|
81 |
|
|
82 Cyg_Mboxt(); // Constructor |
|
|
83 ~Cyg_Mboxt(); // Destructor |
|
|
84 |
|
2
|
85 cyg_bool get( T &ritem ); // get an item; wait if none |
|
0
|
86 #ifdef CYGFUN_KERNEL_THREADS_TIMER |
|
2
|
87 cyg_bool get( T &ritem, cyg_tick_count abs_timeout ); |
|
0
|
88 #endif |
|
2
|
89 cyg_bool tryget( T &ritem ); // just one attempt |
|
0
|
90 |
|
2
|
91 cyg_bool peek_item( T &ritem ); // get next item without |
|
0
|
92 // removing it |
|
|
93 |
|
|
94 #ifdef CYGMFN_KERNEL_SYNCH_MBOXT_PUT_CAN_WAIT |
|
2
|
95 cyg_bool put( const T item ); // put an item; wait if full |
|
0
|
96 #ifdef CYGFUN_KERNEL_THREADS_TIMER |
|
2
|
97 cyg_bool put( const T item, cyg_tick_count abs_timeout ); |
|
0
|
98 #endif |
|
|
99 #endif |
|
2
|
100 cyg_bool tryput( const T item ); // fails if Q full |
|
0
|
101 |
|
|
102 inline |
|
|
103 cyg_count32 peek() // Get current count value |
|
|
104 { |
|
|
105 return count; |
|
|
106 } |
|
|
107 |
|
|
108 inline |
|
2
|
109 cyg_bool waiting_to_get() // Any threads waiting? |
|
0
|
110 { |
|
|
111 return ! get_threadq.empty(); |
|
|
112 } |
|
|
113 |
|
|
114 inline |
|
2
|
115 cyg_bool waiting_to_put() // Any threads waiting? |
|
0
|
116 { |
|
|
117 #ifdef CYGMFN_KERNEL_SYNCH_MBOXT_PUT_CAN_WAIT |
|
|
118 return ! put_threadq.empty(); |
|
|
119 #else |
|
|
120 return false; |
|
|
121 #endif |
|
|
122 } |
|
|
123 }; |
|
|
124 |
|
|
125 // ------------------------------------------------------------------------- |
|
|
126 #endif // ifndef CYGONCE_KERNEL_MBOXT_HXX |
|
|
127 // EOF mboxt.hxx |