File tree Expand file tree Collapse file tree 2 files changed +16
-0
lines changed Expand file tree Collapse file tree 2 files changed +16
-0
lines changed Original file line number Diff line number Diff line change @@ -152,14 +152,23 @@ impl From<u8> for State {
152
152
153
153
154
154
/// Do NOT implement this yourself! Use the macro `interchange!`.
155
+ ///
156
+ /// At compile time, the client capacity is set by using the appropriate call
157
+ /// to the `interchange!` macro. The application can then repeatedly call `claim`
158
+ /// to obtain these clients.
155
159
pub trait Interchange : Sized {
160
+ const CLIENT_CAPACITY : usize ;
156
161
type REQUEST : Clone ;
157
162
type RESPONSE : Clone ;
158
163
/// This is the constructor for a `(Requester, Responder)` pair.
159
164
///
160
165
/// Returns singleton static instances until all that were allocated are
161
166
/// used up, thereafter, `None` is returned.
162
167
fn claim ( ) -> Option < ( Requester < Self > , Responder < Self > ) > ;
168
+
169
+ /// Method for debugging: how many allocated clients have not been claimed.
170
+ fn available_clients ( ) -> usize ;
171
+
163
172
/// Method purely for testing - do not use in production
164
173
///
165
174
/// Rationale: In production, interchanges are supposed to be set up
Original file line number Diff line number Diff line change @@ -81,9 +81,12 @@ macro_rules! interchange {
81
81
static LAST_CLAIMED : AtomicUsize = AtomicUsize :: new( 0 ) ;
82
82
& LAST_CLAIMED
83
83
}
84
+
84
85
}
85
86
86
87
impl $crate:: Interchange for $Name {
88
+ const CLIENT_CAPACITY : usize = $N;
89
+
87
90
type REQUEST = $REQUEST;
88
91
type RESPONSE = $RESPONSE;
89
92
@@ -107,6 +110,10 @@ macro_rules! interchange {
107
110
}
108
111
}
109
112
113
+ fn available_clients( ) -> usize {
114
+ Self :: CLIENT_CAPACITY - Self :: last_claimed( ) . load( core:: sync:: atomic:: Ordering :: SeqCst )
115
+ }
116
+
110
117
unsafe fn rq( self ) -> Self :: REQUEST {
111
118
match self {
112
119
Self :: Request ( request) => {
You can’t perform that action at this time.
0 commit comments