From 56eae3d4e5a2db5b013e4551e37ebba7c212abc9 Mon Sep 17 00:00:00 2001 From: Drew Galbraith Date: Wed, 21 Jun 2023 14:48:29 -0700 Subject: [PATCH] [zion/glacier] Move SharedPtr to glacier --- {zion/lib => lib/glacier/memory}/shared_ptr.h | 41 ++++--------------- zion/lib/message_queue.cpp | 4 +- zion/lib/message_queue.h | 4 +- zion/object/channel.h | 1 - zion/object/port.h | 1 - 5 files changed, 13 insertions(+), 38 deletions(-) rename {zion/lib => lib/glacier/memory}/shared_ptr.h (62%) diff --git a/zion/lib/shared_ptr.h b/lib/glacier/memory/shared_ptr.h similarity index 62% rename from zion/lib/shared_ptr.h rename to lib/glacier/memory/shared_ptr.h index 3c7b12a..0c51015 100644 --- a/zion/lib/shared_ptr.h +++ b/lib/glacier/memory/shared_ptr.h @@ -2,7 +2,7 @@ #include -#include "debug/debug.h" +namespace glcr { template class SharedPtr { @@ -30,33 +30,14 @@ class SharedPtr { ~SharedPtr() { Cleanup(); } - T& operator*() { - CheckValid(); - return *ptr_; - } - const T& operator*() const { - CheckValid(); - return *ptr_; - } - T* operator->() { - CheckValid(); - return ptr_; - } - const T* operator->() const { - CheckValid(); - return ptr_; - } + T& operator*() { return *ptr_; } + const T& operator*() const { return *ptr_; } + T* operator->() { return ptr_; } + const T* operator->() const { return ptr_; } - T* ptr() { - CheckValid(); - return ptr_; - } + T* ptr() { return ptr_; } - bool operator==(const SharedPtr& other) { - CheckValid(); - other.CheckValid(); - return ptr_ == other.ptr_; - } + bool operator==(const SharedPtr& other) { return ptr_ == other.ptr_; } bool empty() { return !init_; } @@ -74,15 +55,11 @@ class SharedPtr { delete ref_cnt_; } } - - void CheckValid() const { - if (!init_) { - panic("Accessing invalid shared ptr"); - } - } }; template SharedPtr MakeShared(A... args) { return {new T(args...)}; } + +} // namespace glcr diff --git a/zion/lib/message_queue.cpp b/zion/lib/message_queue.cpp index 62e0755..1530679 100644 --- a/zion/lib/message_queue.cpp +++ b/zion/lib/message_queue.cpp @@ -10,7 +10,7 @@ z_err_t UnboundedMessageQueue::PushBack(uint64_t num_bytes, const void* bytes, return Z_ERR_UNIMPLEMENTED; } - auto message = MakeShared(); + auto message = glcr::MakeShared(); message->num_bytes = num_bytes; message->bytes = new uint8_t[num_bytes]; for (uint64_t i = 0; i < num_bytes; i++) { @@ -57,7 +57,7 @@ z_err_t UnboundedMessageQueue::PopFront(uint64_t* num_bytes, void* bytes, } void UnboundedMessageQueue::WriteKernel(uint64_t init, RefPtr cap) { - auto msg = MakeShared(); + auto msg = glcr::MakeShared(); msg->bytes = new uint8_t[8]; msg->num_bytes = sizeof(init); diff --git a/zion/lib/message_queue.h b/zion/lib/message_queue.h index 420e9e0..e89fa7d 100644 --- a/zion/lib/message_queue.h +++ b/zion/lib/message_queue.h @@ -1,9 +1,9 @@ #pragma once #include "capability/capability.h" +#include "glacier/memory/shared_ptr.h" #include "include/ztypes.h" #include "lib/linked_list.h" -#include "lib/shared_ptr.h" class MessageQueue { public: @@ -40,5 +40,5 @@ class UnboundedMessageQueue : public MessageQueue { LinkedList> caps; }; - LinkedList> pending_messages_; + LinkedList> pending_messages_; }; diff --git a/zion/object/channel.h b/zion/object/channel.h index bc23c47..c2c573c 100644 --- a/zion/object/channel.h +++ b/zion/object/channel.h @@ -7,7 +7,6 @@ #include "lib/mutex.h" #include "lib/pair.h" #include "lib/ref_ptr.h" -#include "lib/shared_ptr.h" #include "object/kernel_object.h" #include "usr/zcall_internal.h" diff --git a/zion/object/port.h b/zion/object/port.h index 7bfb7e6..15222b3 100644 --- a/zion/object/port.h +++ b/zion/object/port.h @@ -4,7 +4,6 @@ #include "lib/linked_list.h" #include "lib/message_queue.h" #include "lib/mutex.h" -#include "lib/shared_ptr.h" #include "object/kernel_object.h" #include "object/thread.h" #include "usr/zcall_internal.h"