Skip to content

Commit

Permalink
📝 fix windows cancel
Browse files Browse the repository at this point in the history
  • Loading branch information
Xudong-Huang committed Mar 4, 2024
1 parent ac996f7 commit 6dfc017
Showing 1 changed file with 7 additions and 12 deletions.
19 changes: 7 additions & 12 deletions src/io/sys/windows/cancel.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
use std::io;

use crate::cancel::CancelIo;
use crate::sync::Mutex;
// use scheduler::get_scheduler;
use super::EventData;
use crate::cancel::CancelIo;
use crate::sync::AtomicOption;

pub struct CancelIoData {
ev_data: *mut EventData,
Expand Down Expand Up @@ -38,28 +37,24 @@ impl CancelIoData {

// windows must use Mutex to protect it's data
// because it will not use the AtomicOption<CoroutineImpl> as a gate keeper
pub struct CancelIoImpl(Mutex<Option<CancelIoData>>);
pub struct CancelIoImpl(AtomicOption<CancelIoData>);

impl CancelIo for CancelIoImpl {
type Data = CancelIoData;

fn new() -> Self {
CancelIoImpl(Mutex::new(None))
CancelIoImpl(AtomicOption::none())
}

fn set(&self, data: CancelIoData) {
*self.0.lock().expect("failed to get CancelIo lock") = Some(data);
self.0.store(data);
}

fn clear(&self) {
*self.0.lock().expect("failed to get CancelIo lock") = None;
self.0.take();
}

unsafe fn cancel(&self) {
self.0
.lock()
.expect("failed to get CancelIo lock")
.take()
.map(|d| d.cancel());
self.0.take().map(|d| d.cancel());
}
}

0 comments on commit 6dfc017

Please sign in to comment.