8000 Use a lock-free notifier queue by austinjones · Pull Request #6 · austinjones/postage-rs · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Use a lock-free notifier queue #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 18, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions src/sync/notifier.rs
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
use std::{collections::LinkedList, sync::Mutex, task::Waker};
use crossbeam_queue::SegQueue;
use std::task::Waker;

#[derive(Debug)]
pub struct Notifier {
wakers: Mutex<LinkedList<Waker>>,
wakers: SegQueue<Waker>,
}

impl Notifier {
pub fn new() -> Self {
Self {
wakers: Mutex::new(LinkedList::new()),
wakers: SegQueue::new(),
}
}

pub fn notify(&self) {
let mut wakers = self.wakers.lock().unwrap();
#[cfg(feature = "debug")]
let mut woken = 0usize;

while let Some(waker) = wakers.pop_back() {
while let Some(waker) = self.wakers.pop() {
#[cfg(feature = "debug")]
{
woken += 1;
Expand All @@ -33,7 +33,6 @@ impl Notifier {
}

pub fn subscribe(&self, waker: Waker) {
let mut wakers = self.wakers.lock().unwrap();
wakers.push_front(waker);
self.wakers.push(waker);
}
}
0