[kernel] Make koid generation per-type

Previously koids were a single global counter tagged with the type in
the top bits. Now there are per-type counters that each increment
separately.
This commit is contained in:
2020-10-18 20:48:09 -07:00
parent 8bb9e22218
commit 82b7082fc5

View File

@@ -5,7 +5,7 @@
#include "objects/thread.h" #include "objects/thread.h"
// TODO: per-cpu this? // TODO: per-cpu this?
static j6_koid_t next_koid; static j6_koid_t next_koids [static_cast<size_t>(kobject::type::max)] = { 0 };
kobject::kobject(type t, j6_signal_t signals) : kobject::kobject(type t, j6_signal_t signals) :
m_koid(koid_generate(t)), m_koid(koid_generate(t)),
@@ -22,7 +22,9 @@ kobject::~kobject()
j6_koid_t j6_koid_t
kobject::koid_generate(type t) kobject::koid_generate(type t)
{ {
return (static_cast<uint64_t>(t) << 48) | next_koid++; kassert(t < type::max, "Object type out of bounds");
uint64_t type_int = static_cast<uint64_t>(t);
return (type_int << 48) | next_koids[type_int]++;
} }
kobject::type kobject::type