[zion/glacier] Move SharedPtr to glacier
This commit is contained in:
parent
f3443cf4de
commit
56eae3d4e5
|
@ -2,7 +2,7 @@
|
|||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "debug/debug.h"
|
||||
namespace glcr {
|
||||
|
||||
template <typename T>
|
||||
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<T>& other) {
|
||||
CheckValid();
|
||||
other.CheckValid();
|
||||
return ptr_ == other.ptr_;
|
||||
}
|
||||
bool operator==(const SharedPtr<T>& 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 <typename T, class... A>
|
||||
SharedPtr<T> MakeShared(A... args) {
|
||||
return {new T(args...)};
|
||||
}
|
||||
|
||||
} // namespace glcr
|
|
@ -10,7 +10,7 @@ z_err_t UnboundedMessageQueue::PushBack(uint64_t num_bytes, const void* bytes,
|
|||
return Z_ERR_UNIMPLEMENTED;
|
||||
}
|
||||
|
||||
auto message = MakeShared<Message>();
|
||||
auto message = glcr::MakeShared<Message>();
|
||||
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<Capability> cap) {
|
||||
auto msg = MakeShared<Message>();
|
||||
auto msg = glcr::MakeShared<Message>();
|
||||
msg->bytes = new uint8_t[8];
|
||||
msg->num_bytes = sizeof(init);
|
||||
|
||||
|
|
|
@ -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<RefPtr<Capability>> caps;
|
||||
};
|
||||
|
||||
LinkedList<SharedPtr<Message>> pending_messages_;
|
||||
LinkedList<glcr::SharedPtr<Message>> pending_messages_;
|
||||
};
|
||||
|
|
|
@ -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"
|
||||
|
||||
|
|
|
@ -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"
|
||||
|
|
Loading…
Reference in New Issue