Remove ntasks aliasing workaround

This commit is contained in:
Bert Belder 2018-10-07 04:14:33 +02:00
parent ad4c4c214a
commit d86e5d2605
No known key found for this signature in database
GPG key ID: 7A77887B2E2ED461

View file

@ -44,12 +44,7 @@ pub struct Isolate {
libdeno_isolate: *const libdeno::isolate,
dispatch: Dispatch,
rx: mpsc::Receiver<(i32, Buf)>,
// Although Isolate is only accessed on the main thread, we use an atomic
// variable here to workaround an issue probably caused by our poor usage
// of Box::leak in Isolate::from_c()
// https://github.com/denoland/deno/issues/919
// ntasks ought to be i32.
ntasks: atomic::AtomicIsize,
ntasks: i32,
pub timeout_due: Option<Instant>,
pub state: Arc<IsolateState>,
}
@ -91,7 +86,7 @@ impl Isolate {
libdeno_isolate: 0 as *const libdeno::isolate,
dispatch,
rx,
ntasks: atomic::AtomicIsize::new(0),
ntasks: 0,
timeout_due: None,
state: Arc::new(IsolateState {
dir: deno_dir::DenoDir::new(flags.reload, None).unwrap(),
@ -195,18 +190,17 @@ impl Isolate {
}
fn ntasks_increment(&mut self) {
let previous_ntasks = self.ntasks.fetch_add(1, atomic::Ordering::SeqCst);
assert!(previous_ntasks >= 0);
assert!(self.ntasks >= 0);
self.ntasks = self.ntasks + 1;
}
fn ntasks_decrement(&mut self) {
let previous_ntasks = self.ntasks.fetch_sub(1, atomic::Ordering::SeqCst);
assert!(previous_ntasks >= 1);
self.ntasks = self.ntasks - 1;
assert!(self.ntasks >= 0);
}
fn is_idle(&self) -> bool {
let n = self.ntasks.load(atomic::Ordering::SeqCst);
n == 0 && self.timeout_due.is_none()
self.ntasks == 0 && self.timeout_due.is_none()
}
}