summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Qin <richard.qin.x@gmail.com>2026-05-13 16:27:16 +0800
committerRichard Qin <richard.qin.x@gmail.com>2026-05-13 16:27:16 +0800
commit8623ddb156882fa5d7e6d6aa48d025a89ebda186 (patch)
treec82cb2f801df61000ba5bec5ee2d42810aa30719
parent4668c7bcc6224a34822cfc6cbc4ea62593ea898b (diff)
downloadlume-8623ddb156882fa5d7e6d6aa48d025a89ebda186.tar.gz
lume-8623ddb156882fa5d7e6d6aa48d025a89ebda186.tar.xz
feat: add PID allocator implementation with bitmap-based allocation
-rw-r--r--na/include/lume/pid.h29
1 files changed, 29 insertions, 0 deletions
diff --git a/na/include/lume/pid.h b/na/include/lume/pid.h
new file mode 100644
index 0000000..8503750
--- /dev/null
+++ b/na/include/lume/pid.h
@@ -0,0 +1,29 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/* Copyright (C) 2026 Richard Qin */
+
+#pragma once
+
+/*
+ * PID Allocator — Bitmap-based O(1) block search
+ * Reference: docs/specs/task.md §3.2
+ */
+
+#include <lume/types.h>
+#include <kernel/sync/spinlock.h>
+
+inline constexpr int32 kMaxPid = 32768;
+
+class PidAllocator {
+public:
+ void init();
+ int32 alloc();
+ void free(int32 pid);
+
+private:
+ static constexpr int32 kBitmapWords = kMaxPid / 64;
+ Spinlock lock_;
+ uint64 bitmap_[kBitmapWords];
+ int32 next_hint_ = 2;
+};
+
+extern PidAllocator g_pid_alloc;