[glacier] Add a vector class
This commit is contained in:
parent
64d355b20d
commit
02e6b49d90
6 changed files with 126 additions and 30 deletions
|
|
@ -68,3 +68,4 @@ void* operator new(uint64_t size) { return GetKernelHeap().Allocate(size); }
|
|||
void* operator new[](uint64_t size) { return GetKernelHeap().Allocate(size); }
|
||||
|
||||
void operator delete(void*, uint64_t) {}
|
||||
void operator delete[](void*) {}
|
||||
|
|
|
|||
|
|
@ -39,25 +39,19 @@ glcr::RefPtr<Thread> Process::CreateThread() {
|
|||
|
||||
glcr::RefPtr<Thread> Process::GetThread(uint64_t tid) {
|
||||
MutexHolder lock(mutex_);
|
||||
auto iter = threads_.begin();
|
||||
while (iter != threads_.end()) {
|
||||
if ((*iter)->tid() == tid) {
|
||||
return *iter;
|
||||
}
|
||||
++iter;
|
||||
if (tid >= threads_.size()) {
|
||||
panic("Bad thread access %u on process %u with %u threads.", tid, id_,
|
||||
threads_.size());
|
||||
}
|
||||
panic("Bad thread access.");
|
||||
return nullptr;
|
||||
return threads_[tid];
|
||||
}
|
||||
|
||||
void Process::CheckState() {
|
||||
MutexHolder lock(mutex_);
|
||||
auto iter = threads_.begin();
|
||||
while (iter != threads_.end()) {
|
||||
if ((*iter)->GetState() != Thread::FINISHED) {
|
||||
for (uint64_t i = 0; i < threads_.size(); i++) {
|
||||
if (threads_[i]->GetState() != Thread::FINISHED) {
|
||||
return;
|
||||
}
|
||||
++iter;
|
||||
}
|
||||
state_ = FINISHED;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
#pragma once
|
||||
|
||||
#include <glacier/container/linked_list.h>
|
||||
#include <glacier/container/vector.h>
|
||||
#include <glacier/memory/ref_ptr.h>
|
||||
#include <stdint.h>
|
||||
|
||||
|
|
@ -64,8 +64,7 @@ class Process : public KernelObject {
|
|||
State state_;
|
||||
|
||||
uint64_t next_thread_id_ = 0;
|
||||
uint64_t next_cap_id_ = 0x100;
|
||||
|
||||
glcr::LinkedList<glcr::RefPtr<Thread>> threads_;
|
||||
glcr::Vector<glcr::RefPtr<Thread>> threads_;
|
||||
CapabilityTable caps_;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -14,23 +14,15 @@ void ProcessManager::InsertProcess(const glcr::RefPtr<Process>& proc) {
|
|||
}
|
||||
|
||||
Process& ProcessManager::FromId(uint64_t pid) {
|
||||
auto iter = proc_list_.begin();
|
||||
while (iter != proc_list_.end()) {
|
||||
if ((*iter)->id() == pid) {
|
||||
return **iter;
|
||||
}
|
||||
++iter;
|
||||
if (pid >= proc_list_.size()) {
|
||||
panic("Bad proc access %u, have %u processes", pid, proc_list_.size());
|
||||
}
|
||||
|
||||
panic("Searching for invalid process id");
|
||||
return *((Process*)0);
|
||||
return *proc_list_[pid];
|
||||
}
|
||||
|
||||
void ProcessManager::DumpProcessStates() {
|
||||
dbgln("Process States: %u", proc_list_.size());
|
||||
auto iter = proc_list_.begin();
|
||||
while (iter != proc_list_.end()) {
|
||||
dbgln("%u: %u", (*iter)->id(), (*iter)->GetState());
|
||||
++iter;
|
||||
for (uint64_t i = 0; i < proc_list_.size(); i++) {
|
||||
dbgln("%u: %u", proc_list_[i]->id(), proc_list_[i]->GetState());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
#pragma once
|
||||
|
||||
#include <glacier/container/linked_list.h>
|
||||
#include <glacier/container/vector.h>
|
||||
#include <glacier/memory/ref_ptr.h>
|
||||
|
||||
#include "object/process.h"
|
||||
|
|
@ -18,7 +18,7 @@ class ProcessManager {
|
|||
|
||||
private:
|
||||
// TODO: This should be a hashmap.
|
||||
glcr::LinkedList<glcr::RefPtr<Process>> proc_list_;
|
||||
glcr::Vector<glcr::RefPtr<Process>> proc_list_;
|
||||
};
|
||||
|
||||
extern ProcessManager* gProcMan;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue