Skip to content
This repository was archived by the owner on Jan 22, 2025. It is now read-only.

Commit cc5a1f0

Browse files
committed
Remove unneeded dyn trait for ChainedChannel
1 parent 4225cba commit cc5a1f0

File tree

1 file changed

+11
-43
lines changed
  • unified-scheduler-pool/src

1 file changed

+11
-43
lines changed

unified-scheduler-pool/src/lib.rs

Lines changed: 11 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -245,59 +245,30 @@ type ExecutedTaskPayload = SubchanneledPayload<Box<ExecutedTask>, ()>;
245245
// this switching can happen exactly once for each thread.
246246
//
247247
// 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.
251250
mod chained_channel {
252251
use super::*;
253252

254253
// hide variants by putting this inside newtype
255254
enum ChainedChannelPrivate<P, C> {
256255
Payload(P),
257-
ContextAndChannel(Box<dyn WithContextAndPayload<P, C>>),
256+
ContextAndChannel(C, Receiver<ChainedChannel<P, C>>),
258257
}
259258

260259
pub(super) struct ChainedChannel<P, C>(ChainedChannelPrivate<P, C>);
261260

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> {
285262
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))
289264
}
290265
}
291266

292267
pub(super) struct ChainedChannelSender<P, C> {
293268
sender: Sender<ChainedChannel<P, C>>,
294269
}
295270

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> {
301272
fn new(sender: Sender<ChainedChannel<P, C>>) -> Self {
302273
Self { sender }
303274
}
@@ -355,21 +326,18 @@ mod chained_channel {
355326
pub(super) fn after_select(&mut self, message: ChainedChannel<P, C>) -> Option<P> {
356327
match message.0 {
357328
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;
360332
None
361333
}
362334
}
363335
}
364336
}
365337

366-
pub(super) fn unbounded<P, C>(
338+
pub(super) fn unbounded<P, C: Clone>(
367339
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>) {
373341
let (sender, receiver) = crossbeam_channel::unbounded();
374342
(
375343
ChainedChannelSender::new(sender),

0 commit comments

Comments
 (0)