Skip to content

Commit d434067

Browse files
committed
less runtime check
1 parent 8eb4ded commit d434067

File tree

2 files changed

+12
-24
lines changed

2 files changed

+12
-24
lines changed

core/src/coroutine/korosensei.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -419,8 +419,14 @@ where
419419
local: CoroutineLocal::default(),
420420
priority,
421421
};
422-
#[cfg(all(unix, feature = "preemptive"))]
423-
co.add_listener(crate::monitor::MonitorListener::<Param, Yield, Return>::new());
422+
cfg_if::cfg_if! {
423+
if #[cfg(all(unix, feature = "preemptive"))] {
424+
let type_id = std::any::TypeId::of::<()>();
425+
if std::any::TypeId::of::<Param>() == type_id && std::any::TypeId::of::<Yield>() == type_id {
426+
co.add_listener(crate::monitor::MonitorListener);
427+
}
428+
}
429+
}
424430
Ok(co)
425431
}
426432

core/src/monitor.rs

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,10 @@ use crate::scheduler::SchedulableSuspender;
77
use crate::{catch, error, impl_current_for, impl_display_by_debug, info};
88
use nix::sys::pthread::{pthread_kill, pthread_self, Pthread};
99
use nix::sys::signal::{sigaction, SaFlags, SigAction, SigHandler, SigSet, Signal};
10-
use std::any::TypeId;
1110
use std::cell::{Cell, UnsafeCell};
1211
use std::collections::HashSet;
1312
use std::fmt::Debug;
1413
use std::io::{Error, ErrorKind};
15-
use std::marker::PhantomData;
1614
use std::mem::MaybeUninit;
1715
use std::sync::Arc;
1816
use std::thread::JoinHandle;
@@ -176,35 +174,19 @@ impl Monitor {
176174
impl_current_for!(MONITOR, Monitor);
177175

178176
#[repr(C)]
179-
#[derive(educe::Educe)]
180-
#[educe(Debug(named_field = false))]
181-
pub(crate) struct MonitorListener<Param, Yield, Return>(
182-
PhantomData<Param>,
183-
PhantomData<Yield>,
184-
PhantomData<Return>,
185-
);
186-
187-
impl<Param, Yield, Return> MonitorListener<Param, Yield, Return> {
188-
pub(crate) fn new() -> Self {
189-
Self(PhantomData, PhantomData, PhantomData)
190-
}
191-
}
177+
#[derive(Debug)]
178+
pub(crate) struct MonitorListener;
192179

193180
const NOTIFY_NODE: &str = "MONITOR_NODE";
194181

195-
impl<Param: 'static, Yield: 'static, Return> Listener<Yield, Return>
196-
for MonitorListener<Param, Yield, Return>
197-
{
182+
impl<Yield, Return> Listener<Yield, Return> for MonitorListener {
198183
fn on_state_changed(
199184
&self,
200185
local: &CoroutineLocal,
201186
_: CoroutineState<Yield, Return>,
202187
new_state: CoroutineState<Yield, Return>,
203188
) {
204-
if TypeId::of::<Param>() != TypeId::of::<()>()
205-
|| TypeId::of::<Yield>() != TypeId::of::<()>()
206-
|| Monitor::current().is_some()
207-
{
189+
if Monitor::current().is_some() {
208190
return;
209191
}
210192
match new_state {

0 commit comments

Comments
 (0)