Struct poolite::Pool
[−]
[src]
pub struct Pool { /* fields omitted */ }
Pool struct.
Methods
impl Pool
[src]
fn new() -> Self
Creates and returns a Pool.
fn num_cpus() -> usize
Returns the number of CPUs of the current machine.
You can use it on min()
or load_limit()
.
Maybe you also need std::usize::MIN
or std::usize::MAX
.
Warning: It be initialized by new()
,Don't use it before new()
(Otherwise it will return 1).
fn daemon(self, daemon: Option<u64>) -> Self
Sets whether to open the daemon for the Pool, the default is Some(5000)(thread's default idle time(ms)).
You can use None
to close.
fn get_daemon(&self) -> Option<Duration>
Returns the value of daemon()
.
fn min(self, min: usize) -> Self
Sets the minimum number of threads in the Pool,default is num_cpus()+1
.
fn get_min(&self) -> usize
Returns the value of the minimum number of threads in the Pool.
fn time_out(self, time_out: u64) -> Self
Sets thread's idle time(ms) except minimum number of threads,default is 5000(ms).
fn get_time_out(&self) -> Duration
Returns the value of the thread's idle time(Duration).
fn name<T: AsRef<str>>(self, name: T) -> Self where T: Debug
Sets thread's name where them in the Pool,default is None('<unnamed>'
).
fn get_name(&self) -> Option<String>
Returns thread's name.
fn stack_size(self, size: usize) -> Self
Sets thread's stack_size where them in the Pool,default depends on OS.
fn get_stack_size(&self) -> Option<usize>
Returns thread's stack_size.
fn load_limit(self, load_limit: usize) -> Self
Sets the value of load_limit for the Pool,
pool will create new thread while tasks_queue_len()/threads
bigger than it,default is num_cpus()* num_cpus()
.
Warning: Pool maybe block when min()
is 0 and load_limit()
is'not 0,until tasks_queue_len()/threads
bigger than load_limit.
fn get_load_limit(&self) -> usize
Returns the value of load_limit.
Complete Example for Creating and Settings:
extern crate poolite;
use poolite::Pool;
let pool = Pool::new()
.daemon(Some(5000))
.min(Pool::num_cpus() + 1)
.time_out(5000) //5000ms
.name("name")
.stack_size(2 * 1024 * 1024) //2MiB
.load_limit(Pool::num_cpus() * Pool::num_cpus())
.run();
impl Pool
[src]
fn run(self) -> Self
Lets the Pool to start running(Add the number of min threads to the pool).
fn spawn(&self, task: Box<FnBox() + Send + 'static>)
Adds a task to the Pool,
it receives Box<Fn() + Send + 'static>,Box<FnMut() + Send + 'static>
and
Box<FnOnce() + Send + 'static>(Box<FnBox() + Send + 'static>)
.
impl Pool
[src]
fn is_empty(&self) -> bool
All threads are waiting and tasks_queue'length is 0.
fn tasks_len(&self) -> usize
Returns the length of the tasks_queue.
fn strong_count(&self) -> usize
Approximately equal to len()
.
fn len(&self) -> usize
Returns the thread'number in the Pool.
fn wait_len(&self) -> usize
Returns the thread'number that is waiting in the Pool