Skip to content

Commit

Permalink
将任务池、工作池和工具库移动到pi_base
Browse files Browse the repository at this point in the history
  • Loading branch information
zuon committed Jun 7, 2018
1 parent 6e27926 commit 5fc9c6b
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 946 deletions.
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ threadpool = "*"
lazy_static = "*"
kernel32-sys = "*"

pi_lib = { path = "../pi_lib" }
pi_lib = { path = "../pi_lib" }
pi_base = { path = "../pi_base" }
8 changes: 1 addition & 7 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,11 @@
#![feature(slice_internals)]
#![feature(duration_from_micros)]

extern crate fnv;
extern crate core;
extern crate time;
extern crate libc;
extern crate rand;
extern crate magnetic;
extern crate threadpool;

#[macro_use]
extern crate lazy_static;
Expand All @@ -24,13 +22,9 @@ extern crate lazy_static;
extern crate kernel32;

extern crate pi_lib;
extern crate pi_base;

pub mod adapter;
pub mod util;
pub mod worker;
pub mod worker_pool;
pub mod task;
pub mod task_pool;
pub mod native_object_impl;
pub mod pi_vm_impl;
pub mod bonmgr;
28 changes: 7 additions & 21 deletions src/pi_vm_impl.rs
Original file line number Diff line number Diff line change
@@ -1,22 +1,18 @@
use std::thread;
use std::boxed::FnBox;
use std::time::Duration;
use std::sync::{Arc, Mutex, Condvar};
use std::sync::Arc;
use std::sync::atomic::{Ordering, AtomicUsize};

use magnetic::mpmc::*;
use magnetic::buffer::dynamic::DynamicBuffer;
use magnetic::{Producer, Consumer};

use task::TaskType;
use task_pool::TaskPool;
use pi_base::task::TaskType;
use pi_base::pi_base_impl::cast_js_task;
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};
use pi_lib::atom::Atom;

lazy_static! {
pub static ref JS_TASK_POOL: Arc<(Mutex<TaskPool>, Condvar)> = Arc::new((Mutex::new(TaskPool::new(10)), Condvar::new()));
}

/*
* 虚拟机工厂
*/
Expand Down Expand Up @@ -89,7 +85,7 @@ impl VMFactory {
vm = args(vm);
vm.call(4);
});
cast_task(TaskType::Sync, 5000000000 + uid as u64, func, info);
cast_js_task(TaskType::Sync, 5000000000 + uid as u64, func, info);
}
}
}
Expand All @@ -105,7 +101,7 @@ impl VMFactory {
Ok(_) => (),
}
});
cast_task(TaskType::Sync, 5000000000 + uid as u64, func, info);
cast_js_task(TaskType::Sync, 5000000000 + uid as u64, func, info);
},
}
}
Expand All @@ -130,16 +126,6 @@ impl VMFactory {
}
}

/*
* 线程安全的向任务池投递任务
*/
pub fn cast_task(task_type: TaskType, priority: u64, func: Box<FnBox()>, info: Atom) {
let &(ref lock, ref cvar) = &**JS_TASK_POOL;
let mut task_pool = lock.lock().unwrap();
(*task_pool).push(task_type, priority, func, info);
cvar.notify_one();
}

/*
* 线程安全的回应阻塞调用
*/
Expand Down Expand Up @@ -169,7 +155,7 @@ pub fn block_reply(js: Arc<JS>, result: Box<FnBox(Arc<JS>)>, task_type: TaskType
}
}
});
cast_task(task_type, priority, func, info);
cast_js_task(task_type, priority, func, info);
}

/*
Expand Down Expand Up @@ -201,7 +187,7 @@ pub fn block_throw(js: Arc<JS>, reason: String, task_type: TaskType, priority: u
}
}
});
cast_task(task_type, priority, func, info);
cast_js_task(task_type, priority, func, info);
}

#[cfg(all(feature="unstable", any(target_arch = "x86", target_arch = "x86_64")))]
Expand Down
143 changes: 0 additions & 143 deletions src/task.rs

This file was deleted.

Loading

0 comments on commit 5fc9c6b

Please sign in to comment.