summaryrefslogtreecommitdiff
path: root/na/kernel/pid.cc
diff options
context:
space:
mode:
authorRichard Qin <richard.qin.x@gmail.com>2026-07-10 11:31:46 +0800
committerRichard Qin <richard.qin.x@gmail.com>2026-07-10 11:31:46 +0800
commite90b72ec3082588b296956730bd2930cf8d5d671 (patch)
tree36ff6916af9b4176ea5a9662219d11e721f0b691 /na/kernel/pid.cc
parent1767d390fbf3d0c65389de46caf0b6d43ef3b6ad (diff)
downloadlume-e90b72ec3082588b296956730bd2930cf8d5d671.tar.gz
lume-e90b72ec3082588b296956730bd2930cf8d5d671.tar.xz
refactor: promote new architecture to repository root
Archive the deprecated implementation under lume-legacy, make the new kernel the default root-level build, and update repository entry points without changing kernel behavior.
Diffstat (limited to 'na/kernel/pid.cc')
-rw-r--r--na/kernel/pid.cc63
1 files changed, 0 insertions, 63 deletions
diff --git a/na/kernel/pid.cc b/na/kernel/pid.cc
deleted file mode 100644
index 04b846b..0000000
--- a/na/kernel/pid.cc
+++ /dev/null
@@ -1,63 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0-or-later */
-/* Copyright (C) 2026 Richard Qin */
-
-/*
- * PID Allocator — Bitmap-based O(1) block search
- * Reference: docs/specs/task.md §3.2
- */
-
-#include <lume/pid.h>
-
-void PidAllocator::init()
-{
- for (int i = 0; i < kBitmapWords; i++)
- bitmap_[i] = 0;
- next_hint_ = 1;
- bitmap_[0] |= 0x1ULL; /* Reserve PID 0 (idle/swapper) only.
- * PID 1 (init) is allocated normally — the first
- * kthread_create() call gets it, matching Linux. */
-}
-
-int32 PidAllocator::alloc()
-{
- LockGuard guard(lock_);
-
- int32 word_start = next_hint_ / 64;
-
- for (int32 passes = 0; passes < kBitmapWords; passes++) {
- int32 w = (word_start + passes) % kBitmapWords;
- uint64 free_bits = ~bitmap_[w];
- if (free_bits == 0)
- continue;
-
- int bit = 0;
- uint64 v = free_bits;
- while ((v & 1ULL) == 0) { v >>= 1; bit++; }
- int32 pid = w * 64 + bit;
-
- if (pid >= kMaxPid)
- continue;
-
- bitmap_[w] |= (1ULL << bit);
- next_hint_ = pid + 1;
- if (next_hint_ >= kMaxPid)
- next_hint_ = 2;
-
- return pid;
- }
-
- return -1;
-}
-
-void PidAllocator::free(int32 pid)
-{
- if (pid < 0 || pid >= kMaxPid)
- return;
-
- LockGuard guard(lock_);
- int32 w = pid / 64;
- int32 bit = pid % 64;
- bitmap_[w] &= ~(1ULL << bit);
-}
-
-PidAllocator g_pid_alloc;