chore: delete useless unsafe
@@ -51,7 +51,7 @@ impl ExecutorTasksQueue {
/// # Safety
///
/// Method is thread unsafe and require thread safe call
- pub unsafe fn steal_task_to_context(&self, context: &mut ExecutorWorkerContext) {
+ pub fn steal_task_to_context(&self, context: &mut ExecutorWorkerContext) {
{
let mut workers_tasks = self.workers_tasks.lock();
@@ -82,7 +82,7 @@ impl ExecutorTasksQueue {
context.get_workers_notify().wait(context.get_worker_num());
}
- pub unsafe fn init_tasks(&self, mut tasks: VecDeque<ExecutorTask>) {
+ pub fn init_tasks(&self, mut tasks: VecDeque<ExecutorTask>) {
let mut worker_id = 0;
let mut workers_tasks = self.workers_tasks.lock();
while let Some(task) = tasks.pop_front() {
@@ -97,7 +97,6 @@ impl ExecutorTasksQueue {
#[allow(unused_assignments)]
pub fn push_tasks(&self, ctx: &mut ExecutorWorkerContext, mut tasks: VecDeque<ExecutorTask>) {
- unsafe {
let mut wake_worker_id = None;
{
let worker_id = ctx.get_worker_num();
@@ -113,7 +112,6 @@ impl ExecutorTasksQueue {
ctx.get_workers_notify().wakeup(wake_worker_id);
}
}
- }
pub fn completed_async_task(&self, task: CompletedAsyncTask) {
let mut workers_tasks = self.workers_tasks.lock();
@@ -214,7 +212,7 @@ impl ExecutorTasks {
worker_id
}
- pub unsafe fn pop_task(&mut self, mut worker_id: usize) -> ExecutorTask {
+ pub fn pop_task(&mut self, mut worker_id: usize) -> ExecutorTask {
for _index in 0..self.workers_sync_tasks.len() {
match self.pop_worker_task(worker_id) {
ExecutorTask::None => {
@@ -232,10 +230,16 @@ impl ExecutorTasks {
ExecutorTask::None
}
- pub unsafe fn push_task(&mut self, worker_id: usize, task: ExecutorTask) {
+ pub fn push_task(&mut self, worker_id: usize, task: ExecutorTask) {
self.tasks_size += 1;
+ assert!(worker_id < self.workers_sync_tasks.len(), "out of index");
let sync_queue = &mut self.workers_sync_tasks[worker_id];
+ assert!(worker_id < self.workers_async_tasks.len(), "out of index");
let async_queue = &mut self.workers_async_tasks[worker_id];
+ assert!(
+ worker_id < self.workers_completed_async_tasks.len(),
+ "out of index"
+ );
let completed_queue = &mut self.workers_completed_async_tasks[worker_id];
match task {
