@@ -245,59 +245,30 @@ type ExecutedTaskPayload = SubchanneledPayload<Box<ExecutedTask>, ()>;
245
245
// this switching can happen exactly once for each thread.
246
246
//
247
247
// Overall, this greatly simplifies the code, reduces CAS/syscall overhead per messaging to the
248
- // minimum at the cost of a single heap allocation per switching for the sake of Box-ing the Self
249
- // type to avoid infinite mem::size_of() due to the recursive type structure. Needless to say, such
250
- // an allocation can be amortized to be negligible.
248
+ // minimum at the cost of a single channel recreation per switching. Needless to say, such an
249
+ // allocation can be amortized to be negligible.
251
250
mod chained_channel {
252
251
use super :: * ;
253
252
254
253
// hide variants by putting this inside newtype
255
254
enum ChainedChannelPrivate < P , C > {
256
255
Payload ( P ) ,
257
- ContextAndChannel ( Box < dyn WithContextAndPayload < P , C > > ) ,
256
+ ContextAndChannel ( C , Receiver < ChainedChannel < P , C > > ) ,
258
257
}
259
258
260
259
pub ( super ) struct ChainedChannel < P , C > ( ChainedChannelPrivate < P , C > ) ;
261
260
262
- trait WithContextAndPayload < P , C > : Send + Sync {
263
- fn context_and_channel ( self : Box < Self > ) -> ContextAndChannelInner < P , C > ;
264
- }
265
-
266
- type ContextAndChannelInner < P , C > = ( C , Receiver < ChainedChannel < P , C > > ) ;
267
-
268
- struct ContextAndChannelWrapper < P , C > ( ContextAndChannelInner < P , C > ) ;
269
-
270
- impl < P , C > WithContextAndPayload < P , C > for ContextAndChannelWrapper < P , C >
271
- where
272
- P : Send + Sync ,
273
- C : Send + Sync ,
274
- {
275
- fn context_and_channel ( self : Box < Self > ) -> ContextAndChannelInner < P , C > {
276
- self . 0
277
- }
278
- }
279
-
280
- impl < P , C > ChainedChannel < P , C >
281
- where
282
- P : Send + Sync + ' static ,
283
- C : Send + Sync + ' static ,
284
- {
261
+ impl < P , C > ChainedChannel < P , C > {
285
262
fn chain_to_new_channel ( context : C , receiver : Receiver < Self > ) -> Self {
286
- Self ( ChainedChannelPrivate :: ContextAndChannel ( Box :: new (
287
- ContextAndChannelWrapper ( ( context, receiver) ) ,
288
- ) ) )
263
+ Self ( ChainedChannelPrivate :: ContextAndChannel ( context, receiver) )
289
264
}
290
265
}
291
266
292
267
pub ( super ) struct ChainedChannelSender < P , C > {
293
268
sender : Sender < ChainedChannel < P , C > > ,
294
269
}
295
270
296
- impl < P , C > ChainedChannelSender < P , C >
297
- where
298
- P : Send + Sync + ' static ,
299
- C : Send + Sync + ' static + Clone ,
300
- {
271
+ impl < P , C : Clone > ChainedChannelSender < P , C > {
301
272
fn new ( sender : Sender < ChainedChannel < P , C > > ) -> Self {
302
273
Self { sender }
303
274
}
@@ -355,21 +326,18 @@ mod chained_channel {
355
326
pub ( super ) fn after_select ( & mut self , message : ChainedChannel < P , C > ) -> Option < P > {
356
327
match message. 0 {
357
328
ChainedChannelPrivate :: Payload ( payload) => Some ( payload) ,
358
- ChainedChannelPrivate :: ContextAndChannel ( new_context_and_channel) => {
359
- ( self . context , self . receiver ) = new_context_and_channel. context_and_channel ( ) ;
329
+ ChainedChannelPrivate :: ContextAndChannel ( context, channel) => {
330
+ self . context = context;
331
+ self . receiver = channel;
360
332
None
361
333
}
362
334
}
363
335
}
364
336
}
365
337
366
- pub ( super ) fn unbounded < P , C > (
338
+ pub ( super ) fn unbounded < P , C : Clone > (
367
339
initial_context : C ,
368
- ) -> ( ChainedChannelSender < P , C > , ChainedChannelReceiver < P , C > )
369
- where
370
- P : Send + Sync + ' static ,
371
- C : Send + Sync + ' static + Clone ,
372
- {
340
+ ) -> ( ChainedChannelSender < P , C > , ChainedChannelReceiver < P , C > ) {
373
341
let ( sender, receiver) = crossbeam_channel:: unbounded ( ) ;
374
342
(
375
343
ChainedChannelSender :: new ( sender) ,
0 commit comments