From 779f732ba48fe64e1073d3e46b1027b0ecf1bba5 Mon Sep 17 00:00:00 2001 From: longjin Date: Thu, 31 Oct 2024 14:09:28 +0000 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=88=A0=E9=99=A4=E5=9C=A8=20#949=20?= =?UTF-8?q?=E4=B8=AD=E6=84=8F=E5=A4=96=E6=B7=BB=E5=8A=A0=E7=9A=84=E6=97=A7?= =?UTF-8?q?=E7=89=88ida?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://github.com/DragonOS-Community/DragonOS/pull/949 Signed-off-by: longjin --- kernel/src/libs/ida/src/lib.rs | 55 ---------------------------------- 1 file changed, 55 deletions(-) delete mode 100644 kernel/src/libs/ida/src/lib.rs diff --git a/kernel/src/libs/ida/src/lib.rs b/kernel/src/libs/ida/src/lib.rs deleted file mode 100644 index ac25d557c..000000000 --- a/kernel/src/libs/ida/src/lib.rs +++ /dev/null @@ -1,55 +0,0 @@ -#![no_std] -#![feature(core_intrinsics)] -#![allow(clippy::needless_return)] - -use core::intrinsics::unlikely; -use core::sync::atomic::{AtomicBool, AtomicUsize, Ordering}; - -/// id分配器 -/// -/// TODO: 当前只是为了简单实现功能,将来这里应使用类似linux的ida的方式去实现 -#[derive(Debug)] -pub struct IdAllocator { - current_id: AtomicUsize, - max_id: usize, - dead: AtomicBool, -} - -impl IdAllocator { - /// 创建一个新的id分配器 - pub const fn new(initial_id: usize, max_id: usize) -> Self { - Self { - current_id: AtomicUsize::new(initial_id), - max_id, - dead: AtomicBool::new(false), - } - } - - /// 分配一个新的id - /// - /// ## 返回 - /// - /// 如果分配成功,返回Some(id),否则返回None - pub fn alloc(&self) -> Option { - if unlikely(self.dead.load(Ordering::SeqCst)) { - return None; - } - - let ret = self.current_id.fetch_add(1, Ordering::SeqCst); - // 如果id溢出,panic - if ret == self.max_id { - self.dead.store(true, Ordering::SeqCst); - return None; - } - - return Some(ret); - } - - pub fn free(&self, _id: usize) { - // todo: free - } - - pub fn get_max_id(&self) -> usize { - self.max_id - } -}