diff --git a/Cargo.lock b/Cargo.lock index 282ac02..2746f82 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -54,51 +54,6 @@ dependencies = [ "libc 0.2.39 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "owning_ref" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "stable_deref_trait 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "parking_lot" -version = "0.5.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "owning_ref 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", - "parking_lot_core 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "parking_lot_core" -version = "0.2.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "libc 0.2.39 (registry+https://github.com/rust-lang/crates.io-index)", - "rand 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", - "smallvec 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "pi_db" -version = "0.1.0" -dependencies = [ - "fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", - "parking_lot 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)", - "pi_lib 0.1.0", -] - -[[package]] -name = "pi_lib" -version = "0.1.0" -dependencies = [ - "fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", - "lazy_static 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "pi_vm" version = "0.1.0" @@ -108,8 +63,6 @@ dependencies = [ "lazy_static 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.39 (registry+https://github.com/rust-lang/crates.io-index)", "magnetic 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "pi_db 0.1.0", - "pi_lib 0.1.0", "rand 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", "threadpool 1.7.1 (registry+https://github.com/rust-lang/crates.io-index)", "time 0.1.39 (registry+https://github.com/rust-lang/crates.io-index)", @@ -130,16 +83,6 @@ name = "redox_syscall" version = "0.1.37" source = "registry+https://github.com/rust-lang/crates.io-index" -[[package]] -name = "smallvec" -version = "0.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "stable_deref_trait" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" - [[package]] name = "threadpool" version = "1.7.1" @@ -197,13 +140,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum libc 0.2.39 (registry+https://github.com/rust-lang/crates.io-index)" = "f54263ad99207254cf58b5f701ecb432c717445ea2ee8af387334bdd1a03fdff" "checksum magnetic 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8765614d70a06c9c36b40892f85cd3f3c7dc6ac56a9cb25d4f7ecd7d5473c0b3" "checksum num_cpus 1.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c51a3322e4bca9d212ad9a158a02abc6934d005490c054a2778df73a70aa0a30" -"checksum owning_ref 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "cdf84f41639e037b484f93433aa3897863b561ed65c6e59c7073d7c561710f37" -"checksum parking_lot 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)" = "d4d05f1349491390b1730afba60bb20d55761bef489a954546b58b4b34e1e2ac" -"checksum parking_lot_core 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)" = "4db1a8ccf734a7bce794cc19b3df06ed87ab2f3907036b693c68f56b4d4537fa" "checksum rand 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "eba5f8cb59cc50ed56be8880a5c7b496bfd9bd26394e176bc67884094145c2c5" "checksum redox_syscall 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)" = "0d92eecebad22b767915e4d529f89f28ee96dbbf5a4810d2b844373f136417fd" -"checksum smallvec 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)" = "03dab98ab5ded3a8b43b2c80751194608d0b2aa0f1d46cf95d1c35e192844aa7" -"checksum stable_deref_trait 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "15132e0e364248108c5e2c02e3ab539be8d6f5d52a01ca9bbf27ed657316f02b" "checksum threadpool 1.7.1 (registry+https://github.com/rust-lang/crates.io-index)" = "e2f0c90a5f3459330ac8bc0d2f879c693bb7a2f59689c1083fc4ef83834da865" "checksum time 0.1.39 (registry+https://github.com/rust-lang/crates.io-index)" = "a15375f1df02096fb3317256ce2cee6a1f42fc84ea5ad5fc8c421cfe40c73098" "checksum winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a" diff --git a/Cargo.toml b/Cargo.toml index 437320a..703630f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,6 +11,4 @@ rand = "*" magnetic = "*" threadpool = "*" lazy_static = "*" -kernel32-sys = "*" -pi_lib = { path = "../pi_lib" } -pi_db = { path = "../pi_db" } \ No newline at end of file +kernel32-sys = "*" \ No newline at end of file diff --git a/src/lib.rs b/src/lib.rs index dcc2a1d..eeba9d5 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -23,9 +23,6 @@ extern crate lazy_static; #[cfg(not(unix))] extern crate kernel32; -extern crate pi_lib; -extern crate pi_db; - pub mod adapter; pub mod util; pub mod worker; diff --git a/src/pi_vm_impl.rs b/src/pi_vm_impl.rs index 2f8b5ca..3d7c791 100644 --- a/src/pi_vm_impl.rs +++ b/src/pi_vm_impl.rs @@ -8,9 +8,6 @@ use magnetic::mpmc::*; use magnetic::buffer::dynamic::DynamicBuffer; use magnetic::{Producer, Consumer}; -use pi_lib::atom::Atom; -use pi_db::mgr::Mgr; - use task::TaskType; use task_pool::TaskPool; use adapter::{JSStatus, JS, try_js_destroy, dukc_vm_status_check, dukc_vm_status_switch, dukc_vm_status_sub, dukc_wakeup, dukc_continue, js_reply_callback}; @@ -73,36 +70,28 @@ impl VMFactory { } //从虚拟机池中获取一个虚拟机,并调用指定的js全局函数 - pub fn call(&self, uid: u32, mgr: Mgr, topic: Atom, payload: Arc>, info: &'static str) { + pub fn call(&self, uid: u32, args: Box JS>, info: &'static str) { match self.consumer.try_pop() { Err(_) => { //没有空闲虚拟机,则立即构建临时虚拟机 match self.new_vm() { None => (), - Some(vm) => { + Some(mut vm) => { let func = Box::new(move || { - //TODO js全局函数还未确定,且参数列表也未确定 vm.get_js_function("call".to_string()); - vm.new_str((*topic).clone()); - let array = vm.new_uint8_array(payload.len() as u32); - array.from_bytes(payload.as_slice()); - vm.new_native_object(Arc::into_raw(Arc::new(mgr)) as usize); - vm.call(3); + vm = args(vm); + vm.call(4); }); cast_task(TaskType::Sync, 5000000000 + uid as u64, func, info); } } } - Ok(vm) => { + Ok(mut vm) => { let producer = self.producer.clone(); let func = Box::new(move || { - //TODO js全局函数还未确定,且参数列表也未确定 vm.get_js_function("call".to_string()); - vm.new_str((*topic).clone()); - let array = vm.new_uint8_array(payload.len() as u32); - array.from_bytes(payload.as_slice()); - vm.new_native_object(Arc::into_raw(Arc::new(mgr)) as usize); - vm.call(3); + vm = args(vm); + vm.call(4); //调用完成后复用虚拟机 match producer.try_push(vm) { Err(_) => (), @@ -134,13 +123,6 @@ impl VMFactory { } } -/* -* Topic处理器 -*/ -pub struct TopicHandler { - len: AtomicUsize, -} - /* * 线程安全的向任务池投递任务 */