Skip to content
Permalink
Browse files

core: Rename Behavior to Dispatch (denoland#2082)

And rename IsolateState to ThreadSafeState.

Also make ThreadSafeState directly implement Dispatch. This is simpler.
  • Loading branch information...
ry committed Apr 9, 2019
1 parent e43da28 commit d2579f45641b437974829c87d58c2a362ef66919
Showing with 206 additions and 214 deletions.
  1. +0 −28 cli/cli_behavior.rs
  2. +9 −16 cli/compiler.rs
  3. +8 −10 cli/main.rs
  4. +3 −3 cli/msg.rs
  5. +55 −58 cli/ops.rs
  6. +1 −1 cli/resources.rs
  7. +47 −9 cli/{isolate_state.rs → state.rs}
  8. +18 −22 cli/worker.rs
  9. +1 −1 core/README.md
  10. +1 −1 core/http_bench.rs
  11. +56 −58 core/isolate.rs
  12. +7 −7 core/modules.rs

This file was deleted.

Oops, something went wrong.
@@ -1,12 +1,11 @@
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
use crate::cli_behavior::CliBehavior;
use crate::isolate_state::*;
use crate::js_errors;
use crate::js_errors::JSErrorColor;
use crate::msg;
use crate::resources;
use crate::resources::ResourceId;
use crate::startup_data;
use crate::state::*;
use crate::tokio_util;
use crate::worker::Worker;
use deno::js_check;
@@ -21,7 +20,6 @@ use std::collections::HashMap;
use std::str;
use std::sync::atomic::AtomicUsize;
use std::sync::atomic::Ordering;
use std::sync::Arc;
use std::sync::Mutex;
use tokio::runtime::Runtime;

@@ -88,22 +86,21 @@ fn parse_cmd_id(res_json: &str) -> CmdId {
}
}

fn lazy_start(parent_state: Arc<IsolateState>) -> ResourceId {
fn lazy_start(parent_state: ThreadSafeState) -> ResourceId {
let mut cell = C_RID.lock().unwrap();
cell
.get_or_insert_with(|| {
let child_state = Arc::new(IsolateState::new(
let child_state = ThreadSafeState::new(
parent_state.flags.clone(),
parent_state.argv.clone(),
));
);
let rid = child_state.resource.rid;
let resource = child_state.resource.clone();
let behavior = CliBehavior::new(child_state);

let mut worker = Worker::new(
"TS".to_string(),
startup_data::compiler_isolate_init(),
behavior,
child_state,
);

js_check(worker.execute("denoMain()"));
@@ -160,7 +157,7 @@ fn req(specifier: &str, referrer: &str, cmd_id: u32) -> Buf {
}

pub fn compile_async(
parent_state: Arc<IsolateState>,
parent_state: ThreadSafeState,
specifier: &str,
referrer: &str,
module_meta_data: &ModuleMetaData,
@@ -248,7 +245,7 @@ pub fn compile_async(
}

pub fn compile_sync(
parent_state: Arc<IsolateState>,
parent_state: ThreadSafeState,
specifier: &str,
referrer: &str,
module_meta_data: &ModuleMetaData,
@@ -286,12 +283,8 @@ mod tests {
maybe_source_map: None,
};

out = compile_sync(
Arc::new(IsolateState::mock()),
specifier,
&referrer,
&out,
).unwrap();
out = compile_sync(ThreadSafeState::mock(), specifier, &referrer, &out)
.unwrap();
assert!(
out
.maybe_output_code
@@ -11,7 +11,6 @@ extern crate clap;
extern crate deno;

mod ansi;
pub mod cli_behavior;
pub mod compiler;
pub mod deno_dir;
pub mod errors;
@@ -20,7 +19,6 @@ mod fs;
mod global_timer;
mod http_body;
mod http_util;
pub mod isolate_state;
pub mod js_errors;
pub mod modules;
pub mod msg;
@@ -31,20 +29,19 @@ mod repl;
pub mod resolve_addr;
pub mod resources;
mod startup_data;
pub mod state;
mod tokio_util;
mod tokio_write;
pub mod version;
pub mod worker;

use crate::cli_behavior::CliBehavior;
use crate::errors::RustOrJsError;
use crate::isolate_state::IsolateState;
use crate::state::ThreadSafeState;
use crate::worker::Worker;
use futures::lazy;
use futures::Future;
use log::{LevelFilter, Metadata, Record};
use std::env;
use std::sync::Arc;

static LOGGER: Logger = Logger;

@@ -104,11 +101,12 @@ fn main() {
let should_prefetch = flags.prefetch || flags.info;
let should_display_info = flags.info;

let state = Arc::new(IsolateState::new(flags, rest_argv));
let state_ = state.clone();
let cli = CliBehavior::new(state_);
let mut main_worker =
Worker::new("main".to_string(), startup_data::deno_isolate_init(), cli);
let state = ThreadSafeState::new(flags, rest_argv);
let mut main_worker = Worker::new(
"main".to_string(),
startup_data::deno_isolate_init(),
state.clone(),
);

let main_future = lazy(move || {
// Setup runtime.
@@ -5,16 +5,16 @@
feature = "cargo-clippy",
allow(clippy::all, clippy::pedantic)
)]
use crate::isolate_state;
use crate::state;
use flatbuffers;
use std::sync::atomic::Ordering;

// GN_OUT_DIR is set either by build.rs (for the Cargo build), or by
// build_extra/rust/run.py (for the GN+Ninja build).
include!(concat!(env!("GN_OUT_DIR"), "/gen/cli/msg_generated.rs"));

impl<'a> From<&'a isolate_state::Metrics> for MetricsResArgs {
fn from(m: &'a isolate_state::Metrics) -> Self {
impl<'a> From<&'a state::Metrics> for MetricsResArgs {
fn from(m: &'a state::Metrics) -> Self {
MetricsResArgs {
ops_dispatched: m.ops_dispatched.load(Ordering::SeqCst) as u64,
ops_completed: m.ops_completed.load(Ordering::SeqCst) as u64,
Oops, something went wrong.

0 comments on commit d2579f4

Please sign in to comment.
You can’t perform that action at this time.