Skip to content
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

Remove mut from Poll #213

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
6 changes: 3 additions & 3 deletions doc/src/zmqsource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ where

fn register(
&mut self,
poll: &mut calloop::Poll,
poll: &calloop::Poll,
token_factory: &mut calloop::TokenFactory,
) -> calloop::Result<()> {
self.socket.register(poll, token_factory)?;
Expand All @@ -216,7 +216,7 @@ where

fn reregister(
&mut self,
poll: &mut calloop::Poll,
poll: &calloop::Poll,
token_factory: &mut calloop::TokenFactory,
) -> calloop::Result<()> {
self.socket.reregister(poll, token_factory)?;
Expand All @@ -228,7 +228,7 @@ where
Ok(())
}

fn unregister(&mut self, poll: &mut calloop::Poll) -> calloop::Result<()> {
fn unregister(&mut self, poll: &calloop::Poll) -> calloop::Result<()> {
self.socket.unregister(poll)?;
self.mpsc_receiver.unregister(poll)?;
self.wake_ping_receiver.unregister(poll)?;
Expand Down
10 changes: 5 additions & 5 deletions src/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ trait IoLoopInner {
impl<'l, Data> IoLoopInner for LoopInner<'l, Data> {
unsafe fn register(&self, dispatcher: &RefCell<IoDispatcher>) -> crate::Result<()> {
let disp = dispatcher.borrow();
self.poll.borrow_mut().register(
self.poll.register(
unsafe { BorrowedFd::borrow_raw(disp.fd) },
Interest::EMPTY,
Mode::OneShot,
Expand All @@ -212,7 +212,7 @@ impl<'l, Data> IoLoopInner for LoopInner<'l, Data> {

fn reregister(&self, dispatcher: &RefCell<IoDispatcher>) -> crate::Result<()> {
let disp = dispatcher.borrow();
self.poll.borrow_mut().reregister(
self.poll.reregister(
unsafe { BorrowedFd::borrow_raw(disp.fd) },
disp.interest,
Mode::OneShot,
Expand Down Expand Up @@ -263,7 +263,7 @@ impl<Data> EventDispatcher<Data> for RefCell<IoDispatcher> {

fn register(
&self,
_: &mut Poll,
_: &Poll,
_: &mut AdditionalLifecycleEventsSet,
_: &mut TokenFactory,
) -> crate::Result<()> {
Expand All @@ -273,7 +273,7 @@ impl<Data> EventDispatcher<Data> for RefCell<IoDispatcher> {

fn reregister(
&self,
_: &mut Poll,
_: &Poll,
_: &mut AdditionalLifecycleEventsSet,
_: &mut TokenFactory,
) -> crate::Result<bool> {
Expand All @@ -283,7 +283,7 @@ impl<Data> EventDispatcher<Data> for RefCell<IoDispatcher> {

fn unregister(
&self,
poll: &mut Poll,
poll: &Poll,
_: &mut AdditionalLifecycleEventsSet,
_: RegistrationToken,
) -> crate::Result<bool> {
Expand Down
67 changes: 31 additions & 36 deletions src/loop_logic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ impl RegistrationToken {
}

pub(crate) struct LoopInner<'l, Data> {
pub(crate) poll: RefCell<Poll>,
pub(crate) poll: Poll,
// The `Option` is used to keep slots of the slab occipied, to prevent id reuse
// while in-flight events might still referr to a recently destroyed event source.
pub(crate) sources: RefCell<SourceList<'l, Data>>,
Expand All @@ -57,7 +57,7 @@ pub(crate) struct LoopInner<'l, Data> {
pending_action: Cell<PostAction>,
}

/// An handle to an event loop
/// A handle to an event loop
///
/// This handle allows you to insert new sources and idles in this event loop,
/// it can be cloned, and it is possible to insert new sources from within a source
Expand Down Expand Up @@ -121,15 +121,14 @@ impl<'l, Data> LoopHandle<'l, Data> {
S: EventSource + 'l,
{
let mut sources = self.inner.sources.borrow_mut();
let mut poll = self.inner.poll.borrow_mut();

// Find an empty slot if any
let slot = sources.vacant_entry();

slot.source = Some(dispatcher.clone_as_event_dispatcher());
trace!(source = slot.token.get_id(), "Inserting new source");
let ret = slot.source.as_ref().unwrap().register(
&mut poll,
&self.inner.poll,
&mut self
.inner
.sources_with_additional_lifecycle_events
Expand Down Expand Up @@ -173,7 +172,7 @@ impl<'l, Data> LoopHandle<'l, Data> {
{
trace!(source = entry_token.get_id(), "Registering source");
source.register(
&mut self.inner.poll.borrow_mut(),
&self.inner.poll,
&mut self
.inner
.sources_with_additional_lifecycle_events
Expand All @@ -200,7 +199,7 @@ impl<'l, Data> LoopHandle<'l, Data> {
"Updating registration of source"
);
if !source.reregister(
&mut self.inner.poll.borrow_mut(),
&self.inner.poll,
&mut self
.inner
.sources_with_additional_lifecycle_events
Expand Down Expand Up @@ -235,7 +234,7 @@ impl<'l, Data> LoopHandle<'l, Data> {
}
trace!(source = entry_token.get_id(), "Unregistering source");
if !source.unregister(
&mut self.inner.poll.borrow_mut(),
&self.inner.poll,
&mut self
.inner
.sources_with_additional_lifecycle_events
Expand Down Expand Up @@ -265,7 +264,7 @@ impl<'l, Data> LoopHandle<'l, Data> {
if let Some(source) = source.take() {
trace!(source = entry_token.get_id(), "Removing source");
if let Err(e) = source.unregister(
&mut self.inner.poll.borrow_mut(),
&self.inner.poll,
&mut self
.inner
.sources_with_additional_lifecycle_events
Expand Down Expand Up @@ -328,7 +327,7 @@ impl<'l, Data> EventLoop<'l, Data> {
let poller = poll.poller.clone();
let handle = LoopHandle {
inner: Rc::new(LoopInner {
poll: RefCell::new(poll),
poll,
sources: RefCell::new(SourceList::new()),
idles: RefCell::new(Vec::new()),
pending_action: Cell::new(PostAction::Continue),
Expand Down Expand Up @@ -382,11 +381,8 @@ impl<'l, Data> EventLoop<'l, Data> {
}
}
let events = {
let poll = self.handle.inner.poll.borrow();
loop {
let result = poll.poll(timeout);

match result {
match self.handle.inner.poll.poll(timeout) {
Ok(events) => break events,
Err(crate::Error::IoError(err)) if err.kind() == io::ErrorKind::Interrupted => {
// Interrupted by a signal. Update timeout and retry.
Expand Down Expand Up @@ -461,7 +457,7 @@ impl<'l, Data> EventLoop<'l, Data> {
"Postaction reregister for source"
);
disp.reregister(
&mut self.handle.inner.poll.borrow_mut(),
&self.handle.inner.poll,
&mut self
.handle
.inner
Expand All @@ -476,7 +472,7 @@ impl<'l, Data> EventLoop<'l, Data> {
"Postaction unregister for source"
);
disp.unregister(
&mut self.handle.inner.poll.borrow_mut(),
&self.handle.inner.poll,
&mut self
.handle
.inner
Expand Down Expand Up @@ -506,9 +502,8 @@ impl<'l, Data> EventLoop<'l, Data> {
.unwrap_or(true)
{
// the source has been removed from within its callback, unregister it
let mut poll = self.handle.inner.poll.borrow_mut();
if let Err(e) = disp.unregister(
&mut poll,
&self.handle.inner.poll,
&mut self
.handle
.inner
Expand Down Expand Up @@ -559,7 +554,7 @@ impl<'l, Data> EventLoop<'l, Data> {
pub fn get_signal(&self) -> LoopSignal {
LoopSignal {
signal: self.signals.clone(),
notifier: self.handle.inner.poll.borrow().notifier(),
notifier: self.handle.inner.poll.notifier(),
}
}

Expand Down Expand Up @@ -952,21 +947,21 @@ mod tests {

fn register(
&mut self,
poll: &mut Poll,
poll: &Poll,
token_factory: &mut TokenFactory,
) -> crate::Result<()> {
self.channel.register(poll, token_factory)
}

fn reregister(
&mut self,
poll: &mut Poll,
poll: &Poll,
token_factory: &mut TokenFactory,
) -> crate::Result<()> {
self.channel.reregister(poll, token_factory)
}

fn unregister(&mut self, poll: &mut Poll) -> crate::Result<()> {
fn unregister(&mut self, poll: &Poll) -> crate::Result<()> {
self.channel.unregister(poll)
}

Expand Down Expand Up @@ -1023,21 +1018,21 @@ mod tests {

fn register(
&mut self,
poll: &mut Poll,
poll: &Poll,
token_factory: &mut TokenFactory,
) -> crate::Result<()> {
self.channel.register(poll, token_factory)
}

fn reregister(
&mut self,
poll: &mut Poll,
poll: &Poll,
token_factory: &mut TokenFactory,
) -> crate::Result<()> {
self.channel.reregister(poll, token_factory)
}

fn unregister(&mut self, poll: &mut Poll) -> crate::Result<()> {
fn unregister(&mut self, poll: &Poll) -> crate::Result<()> {
self.channel.unregister(poll)
}

Expand Down Expand Up @@ -1114,18 +1109,18 @@ mod tests {

fn register(
&mut self,
_: &mut Poll,
_: &Poll,
token_factory: &mut TokenFactory,
) -> crate::Result<()> {
self.token = Some(token_factory.token());
Ok(())
}

fn reregister(&mut self, _: &mut Poll, _: &mut TokenFactory) -> crate::Result<()> {
fn reregister(&mut self, _: &Poll, _: &mut TokenFactory) -> crate::Result<()> {
unreachable!()
}

fn unregister(&mut self, _: &mut Poll) -> crate::Result<()> {
fn unregister(&mut self, _: &Poll) -> crate::Result<()> {
unreachable!()
}

Expand Down Expand Up @@ -1272,7 +1267,7 @@ mod tests {

fn register(
&mut self,
poll: &mut Poll,
poll: &Poll,
token_factory: &mut TokenFactory,
) -> crate::Result<()> {
self.ping1.register(poll, token_factory)?;
Expand All @@ -1282,15 +1277,15 @@ mod tests {

fn reregister(
&mut self,
poll: &mut Poll,
poll: &Poll,
token_factory: &mut TokenFactory,
) -> crate::Result<()> {
self.ping1.reregister(poll, token_factory)?;
self.ping2.reregister(poll, token_factory)?;
Ok(())
}

fn unregister(&mut self, poll: &mut Poll) -> crate::Result<()> {
fn unregister(&mut self, poll: &Poll) -> crate::Result<()> {
self.ping1.unregister(poll)?;
self.ping2.unregister(poll)?;
Ok(())
Expand Down Expand Up @@ -1607,19 +1602,19 @@ mod tests {
Ok(PostAction::Remove)
}

fn register(&mut self, _: &mut Poll, fact: &mut TokenFactory) -> crate::Result<()> {
fn register(&mut self, _: &Poll, fact: &mut TokenFactory) -> crate::Result<()> {
// produce a few tokens to emulate a subsource
fact.token();
fact.token();
self.token = Some(fact.token());
Ok(())
}

fn reregister(&mut self, _: &mut Poll, _: &mut TokenFactory) -> crate::Result<()> {
fn reregister(&mut self, _: &Poll, _: &mut TokenFactory) -> crate::Result<()> {
Ok(())
}

fn unregister(&mut self, _: &mut Poll) -> crate::Result<()> {
fn unregister(&mut self, _: &Poll) -> crate::Result<()> {
Ok(())
}

Expand Down Expand Up @@ -1675,15 +1670,15 @@ mod tests {
Ok(PostAction::Continue)
}

fn register(&mut self, _: &mut Poll, _: &mut TokenFactory) -> crate::Result<()> {
fn register(&mut self, _: &Poll, _: &mut TokenFactory) -> crate::Result<()> {
Ok(())
}

fn reregister(&mut self, _: &mut Poll, _: &mut TokenFactory) -> crate::Result<()> {
fn reregister(&mut self, _: &Poll, _: &mut TokenFactory) -> crate::Result<()> {
Ok(())
}

fn unregister(&mut self, _: &mut Poll) -> crate::Result<()> {
fn unregister(&mut self, _: &Poll) -> crate::Result<()> {
Ok(())
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,21 +140,21 @@ mod tests {

fn register(
&mut self,
poll: &mut crate::Poll,
poll: &crate::Poll,
token_factory: &mut crate::TokenFactory,
) -> crate::Result<()> {
crate::batch_register!(poll, token_factory, self.ping0, self.ping1, self.ping2)
}

fn reregister(
&mut self,
poll: &mut crate::Poll,
poll: &crate::Poll,
token_factory: &mut crate::TokenFactory,
) -> crate::Result<()> {
crate::batch_reregister!(poll, token_factory, self.ping0, self.ping1, self.ping2)
}

fn unregister(&mut self, poll: &mut crate::Poll) -> crate::Result<()> {
fn unregister(&mut self, poll: &crate::Poll) -> crate::Result<()> {
crate::batch_unregister!(poll, self.ping0, self.ping1, self.ping2)
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/sources/channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,19 +246,19 @@ impl<T> EventSource for Channel<T> {
}
}

fn register(&mut self, poll: &mut Poll, token_factory: &mut TokenFactory) -> crate::Result<()> {
fn register(&mut self, poll: &Poll, token_factory: &mut TokenFactory) -> crate::Result<()> {
self.source.register(poll, token_factory)
}

fn reregister(
&mut self,
poll: &mut Poll,
poll: &Poll,
token_factory: &mut TokenFactory,
) -> crate::Result<()> {
self.source.reregister(poll, token_factory)
}

fn unregister(&mut self, poll: &mut Poll) -> crate::Result<()> {
fn unregister(&mut self, poll: &Poll) -> crate::Result<()> {
self.source.unregister(poll)
}
}
Expand Down
Loading
Loading