use crate::external::*;
use parking_lot::Mutex;
use pi_async_task::Runnable;
use pi_result::RawResult as Result;
use pi_task_pool::{TaskExecutor, TaskHandle, TaskPool, TaskWeight};
use std::sync::atomic::{AtomicBool, AtomicUsize};
pub struct TaskPoolQueue {
pool: &'static TaskPool<Option<Runnable>, NoFastPath>,
access: Mutex<()>,
queued: AtomicUsize,
closed: AtomicBool,
random: fn() -> u64,
}
struct NoFastPath;
impl TaskExecutor<Option<Runnable>> for NoFastPath {
fn fast_path_threshold(&self) -> usize {
0
}
fn is_idle(&self) -> bool {
false
}
fn try_execute(
&self,
task: TaskHandle<Option<Runnable>, Self>,
) -> Result<(), TaskHandle<Option<Runnable>, Self>> {
Err(task)
}
}
impl TaskPoolQueue {
pub fn new(random: fn() -> u64) -> Self {
pool_new_inner(random)
}
}
impl TaskPoolQueue {
pub fn close(&self) -> BatchAttempt {
pool_close_inner(self)
}
}
impl ExternalTaskQueue for TaskPoolQueue {
fn try_push(&self, task: Runnable) -> Result<(), ExternalPushError> {
pool_push_inner(self, task)
}
fn try_take_batch(&self) -> BatchAttempt {
pool_take_inner(self)
}
fn len(&self) -> usize {
pool_len_inner(self)
}
}
impl Drop for TaskPoolQueue {
fn drop(&mut self) {
pool_drop_inner(self)
}
}
include!("pool_inner.rs");