Skip to content

Commit 2ac3be0

Browse files
committed
Build tests for no-default-features into C/I
1 parent 1ec136a commit 2ac3be0

File tree

3 files changed

+49
-15
lines changed

3 files changed

+49
-15
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ jobs:
3939
run: cargo check -Z features=dev_dep
4040
- run: cargo test --all
4141
- run: cargo test --no-default-features --tests
42+
- run: cargo build -p event-listener-strategy --no-default-features
4243
- name: Install cargo-hack
4344
uses: taiki-e/install-action@cargo-hack
4445
- run: rustup target add thumbv7m-none-eabi
@@ -56,6 +57,7 @@ jobs:
5657
- name: Install Rust
5758
run: rustup update ${{ matrix.rust }} && rustup default ${{ matrix.rust }}
5859
- run: cargo build --all
60+
- run: cargo build --all --no-default-features
5961

6062
clippy:
6163
runs-on: ubuntu-latest

src/lib.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ use core::pin::Pin;
8080
use core::ptr;
8181
use core::task::{Context, Poll, Waker};
8282

83+
#[cfg(feature = "std")]
84+
use parking::{Parker, Unparker};
8385
#[cfg(feature = "std")]
8486
use std::time::{Duration, Instant};
8587

@@ -661,7 +663,7 @@ impl<B: Borrow<Inner> + Unpin> Listener<B> {
661663

662664
std::thread_local! {
663665
/// Cached thread-local parker/unparker pair.
664-
static PARKER: RefCell<Option<(parking::Parker, Task)>> = RefCell::new(None);
666+
static PARKER: RefCell<Option<(Parker, Task)>> = RefCell::new(None);
665667
}
666668

667669
// Try to borrow the thread-local parker/unparker pair.
@@ -693,7 +695,7 @@ impl<B: Borrow<Inner> + Unpin> Listener<B> {
693695
fn wait_with_parker(
694696
self: Pin<&mut Self>,
695697
deadline: Option<Instant>,
696-
parker: &parking::Parker,
698+
parker: &Parker,
697699
unparker: TaskRef<'_>,
698700
) -> bool {
699701
let (inner, mut listener) = self.project();
@@ -818,7 +820,7 @@ enum Task {
818820

819821
/// An unparker that wakes up a thread.
820822
#[cfg(feature = "std")]
821-
Unparker(parking::Unparker),
823+
Unparker(Unparker),
822824
}
823825

824826
impl Task {
@@ -855,7 +857,7 @@ enum TaskRef<'a> {
855857

856858
/// An unparker that wakes up a thread.
857859
#[cfg(feature = "std")]
858-
Unparker(&'a parking::Unparker),
860+
Unparker(&'a Unparker),
859861
}
860862

861863
impl TaskRef<'_> {

src/std.rs

Lines changed: 41 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -63,19 +63,24 @@ impl crate::Inner {
6363
let entry = unsafe {
6464
// SAFETY: We never move out the `link` field.
6565
let listener = match listener.get_unchecked_mut() {
66-
listener @ None => listener.insert(Listener {
67-
link: UnsafeCell::new(Link {
68-
state: Cell::new(State::Created),
69-
prev: Cell::new(inner.tail),
70-
next: Cell::new(None),
71-
}),
72-
_pin: PhantomPinned,
73-
}),
66+
listener @ None => {
67+
// TODO: Use Option::insert once the MSRV is high enough.
68+
*listener = Some(Listener {
69+
link: UnsafeCell::new(Link {
70+
state: Cell::new(State::Created),
71+
prev: Cell::new(inner.tail),
72+
next: Cell::new(None),
73+
}),
74+
_pin: PhantomPinned,
75+
});
76+
77+
listener.as_mut().unwrap()
78+
}
7479
Some(_) => return,
7580
};
7681

7782
// Get the inner pointer.
78-
&mut *listener.link.get()
83+
&*listener.link.get()
7984
};
8085

8186
// Replace the tail with the new entry.
@@ -123,7 +128,7 @@ impl crate::Inner {
123128
let entry = unsafe {
124129
// SAFETY: We never move out the `link` field.
125130
let listener = listener.as_mut().get_unchecked_mut().as_mut()?;
126-
&mut *listener.link.get()
131+
&*listener.link.get()
127132
};
128133

129134
// Take out the state and check it.
@@ -183,7 +188,7 @@ impl Inner {
183188
match next {
184189
None => self.tail = prev,
185190
Some(n) => unsafe {
186-
n.as_ref().next.set(prev);
191+
n.as_ref().prev.set(prev);
187192
},
188193
}
189194

@@ -340,5 +345,30 @@ mod tests {
340345
// Remove one.
341346
assert_eq!(inner.remove(listen2, false), Some(State::Created));
342347
assert_eq!(inner.lock().len, 2);
348+
349+
// Remove another.
350+
assert_eq!(inner.remove(listen1, false), Some(State::Created));
351+
assert_eq!(inner.lock().len, 1);
352+
}
353+
354+
#[test]
355+
fn drop_non_notified() {
356+
let inner = crate::Inner::new();
357+
make_listeners!(listen1, listen2, listen3);
358+
359+
// Register the listeners.
360+
inner.insert(listen1.as_mut());
361+
inner.insert(listen2.as_mut());
362+
inner.insert(listen3.as_mut());
363+
364+
// Notify one.
365+
inner.notify(1, false);
366+
367+
// Remove one.
368+
inner.remove(listen3, true);
369+
370+
// Remove the rest.
371+
inner.remove(listen1, true);
372+
inner.remove(listen2, true);
343373
}
344374
}

0 commit comments

Comments
 (0)