|
0
|
1 #ifndef CYGONCE_KERNEL_MBOX_HXX |
|
|
2 #define CYGONCE_KERNEL_MBOX_HXX |
|
|
3 |
|
|
4 //========================================================================== |
|
|
5 // |
|
|
6 // mbox.hxx |
|
|
7 // |
|
|
8 // Plain (void *) Mbox (Message Box/Mailbox) class declarations |
|
|
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 |
|
|
28 // by Cygnus are Copyright (C) 1998 Cygnus Solutions. All Rights Reserved. |
|
|
29 // ------------------------------------------- |
|
|
30 // |
|
|
31 //####COPYRIGHTEND#### |
|
|
32 //========================================================================== |
|
|
33 //#####DESCRIPTIONBEGIN#### |
|
|
34 // |
|
|
35 // Author(s): hmt |
|
|
36 // Contributors: hmt |
|
|
37 // Date: 1998-02-10 |
|
|
38 // Purpose: Define Mbox class interfaces |
|
|
39 // Description: The classes defined here provide the APIs for mboxes. |
|
|
40 // Usage: #include <cyg/kernel/mbox.hxx> |
|
|
41 // |
|
|
42 // |
|
|
43 //####DESCRIPTIONEND#### |
|
|
44 // |
|
|
45 //========================================================================== |
|
|
46 |
|
|
47 #include <cyg/kernel/ktypes.h> |
|
|
48 #include <cyg/infra/cyg_ass.h> // assertion macros |
|
|
49 #include <cyg/kernel/thread.hxx> |
|
|
50 |
|
|
51 #ifdef CYGIMP_MBOX_USE_MBOXT_PLAIN |
|
|
52 #include <cyg/kernel/mboxt.hxx> |
|
|
53 #else |
|
|
54 #include <cyg/kernel/mboxt2.hxx> |
|
|
55 #endif |
|
|
56 |
|
|
57 // ------------------------------------------------------------------------- |
|
|
58 // Message/Mail Box. This class implements a queue of void * items using |
|
|
59 // the Cyg_Mbox<Type, QSize> template class. |
|
|
60 |
|
|
61 #ifndef CYGNUM_KERNEL_SYNCH_MBOX_QUEUE_SIZE |
|
|
62 // default is 10 elements |
|
|
63 #define CYGNUM_KERNEL_SYNCH_MBOX_QUEUE_SIZE (10) |
|
|
64 #endif |
|
|
65 |
|
|
66 // Cyg_Mbox has a fixed size array of (void *)s; one size fits all. |
|
|
67 // Because of this, we can simplify the API by returning a NULL for |
|
|
68 // "failed" conditions. Ergo a NULL message is illegal. BFD. |
|
|
69 |
|
|
70 class Cyg_Mbox |
|
|
71 { |
|
|
72 private: |
|
|
73 #ifdef CYGIMP_MBOX_USE_MBOXT_PLAIN |
|
|
74 Cyg_Mboxt<void *, CYGNUM_KERNEL_SYNCH_MBOX_QUEUE_SIZE> m; |
|
|
75 #else |
|
|
76 Cyg_Mboxt2<void *, CYGNUM_KERNEL_SYNCH_MBOX_QUEUE_SIZE> m; |
|
|
77 #endif |
|
|
78 |
|
|
79 public: |
|
|
80 |
|
|
81 CYGDBG_DEFINE_CHECK_THIS |
|
|
82 |
|
|
83 Cyg_Mbox(); // Constructor |
|
|
84 ~Cyg_Mbox(); // Destructor |
|
|
85 |
|
|
86 void * get(); // get an item; wait if none |
|
|
87 #ifdef CYGFUN_KERNEL_THREADS_TIMER |
|
|
88 void * get( cyg_tick_count timeout ); |
|
|
89 #endif |
|
|
90 void * tryget(); // just one attempt |
|
|
91 |
|
|
92 void * peek_item(); // Get next item to be returned |
|
|
93 // without removing it |
|
|
94 |
|
|
95 #ifdef CYGMFN_KERNEL_SYNCH_MBOXT_PUT_CAN_WAIT // then we support it too |
|
|
96 cyg_bool put( void *item ); // put an item; wait if full |
|
|
97 #ifdef CYGFUN_KERNEL_THREADS_TIMER |
|
|
98 cyg_bool put( void *item, cyg_tick_count timeout ); |
|
|
99 #endif |
|
|
100 #endif |
|
|
101 cyg_bool tryput( void *item ); // fails if Q full |
|
|
102 |
|
|
103 inline |
|
|
104 cyg_count32 peek() // Get current count value |
|
|
105 { |
|
|
106 return m.peek(); |
|
|
107 } |
|
|
108 |
|
|
109 inline |
|
|
110 cyg_bool waiting_to_get() // Any threads waiting to get? |
|
|
111 { |
|
|
112 return m.waiting_to_get(); |
|
|
113 } |
|
|
114 inline |
|
|
115 cyg_bool waiting_to_put() // Any threads waiting to put? |
|
|
116 { |
|
|
117 return m.waiting_to_put(); |
|
|
118 } |
|
|
119 }; |
|
|
120 |
|
|
121 |
|
|
122 |
|
|
123 // ------------------------------------------------------------------------- |
|
|
124 #endif // ifndef CYGONCE_KERNEL_MBOX_HXX |
|
|
125 // End of mbox.hxx |