Skip to content

Commit

Permalink
On Orbital, implement Sync for EventLoopProxy
Browse files Browse the repository at this point in the history
  • Loading branch information
daxpedda committed Mar 26, 2023
1 parent 4ab8f9d commit 90631a5
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ And please only add new entries to the top of this list, right below the `# Unre
# Unreleased

- Bump MSRV from `1.60` to `1.64`.
- On Android, iOS, Linux, MacOS and Windows, implement `Sync` for `EventLoopProxy`.
- On all platforms except Web, implement `Sync` for `EventLoopProxy`.

# 0.28.3

Expand Down
8 changes: 5 additions & 3 deletions src/platform_impl/orbital/event_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -648,20 +648,22 @@ impl<T: 'static> EventLoop<T> {

pub fn create_proxy(&self) -> EventLoopProxy<T> {
EventLoopProxy {
user_events_sender: self.window_target.p.user_events_sender.clone(),
user_events_sender: Mutex::new(self.window_target.p.user_events_sender.clone()),
wake_socket: self.window_target.p.wake_socket.clone(),
}
}
}

pub struct EventLoopProxy<T: 'static> {
user_events_sender: mpsc::Sender<T>,
user_events_sender: Mutex<mpsc::Sender<T>>,
wake_socket: Arc<TimeSocket>,
}

impl<T> EventLoopProxy<T> {
pub fn send_event(&self, event: T) -> Result<(), event_loop::EventLoopClosed<T>> {
self.user_events_sender
.lock()
.unwrap()
.send(event)
.map_err(|mpsc::SendError(x)| event_loop::EventLoopClosed(x))?;

Expand All @@ -674,7 +676,7 @@ impl<T> EventLoopProxy<T> {
impl<T> Clone for EventLoopProxy<T> {
fn clone(&self) -> Self {
Self {
user_events_sender: self.user_events_sender.clone(),
user_events_sender: Mutex::new(self.user_events_sender.lock().unwrap().clone()),
wake_socket: self.wake_socket.clone(),
}
}
Expand Down

0 comments on commit 90631a5

Please sign in to comment.