[zion/glacier] Move SharedPtr to glacier
This commit is contained in:
parent
f3443cf4de
commit
56eae3d4e5
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
#include "debug/debug.h"
|
namespace glcr {
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
class SharedPtr {
|
class SharedPtr {
|
||||||
|
@ -30,33 +30,14 @@ class SharedPtr {
|
||||||
|
|
||||||
~SharedPtr() { Cleanup(); }
|
~SharedPtr() { Cleanup(); }
|
||||||
|
|
||||||
T& operator*() {
|
T& operator*() { return *ptr_; }
|
||||||
CheckValid();
|
const T& operator*() const { return *ptr_; }
|
||||||
return *ptr_;
|
T* operator->() { return ptr_; }
|
||||||
}
|
const T* operator->() const { return ptr_; }
|
||||||
const T& operator*() const {
|
|
||||||
CheckValid();
|
|
||||||
return *ptr_;
|
|
||||||
}
|
|
||||||
T* operator->() {
|
|
||||||
CheckValid();
|
|
||||||
return ptr_;
|
|
||||||
}
|
|
||||||
const T* operator->() const {
|
|
||||||
CheckValid();
|
|
||||||
return ptr_;
|
|
||||||
}
|
|
||||||
|
|
||||||
T* ptr() {
|
T* ptr() { return ptr_; }
|
||||||
CheckValid();
|
|
||||||
return ptr_;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool operator==(const SharedPtr<T>& other) {
|
bool operator==(const SharedPtr<T>& other) { return ptr_ == other.ptr_; }
|
||||||
CheckValid();
|
|
||||||
other.CheckValid();
|
|
||||||
return ptr_ == other.ptr_;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool empty() { return !init_; }
|
bool empty() { return !init_; }
|
||||||
|
|
||||||
|
@ -74,15 +55,11 @@ class SharedPtr {
|
||||||
delete ref_cnt_;
|
delete ref_cnt_;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CheckValid() const {
|
|
||||||
if (!init_) {
|
|
||||||
panic("Accessing invalid shared ptr");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename T, class... A>
|
template <typename T, class... A>
|
||||||
SharedPtr<T> MakeShared(A... args) {
|
SharedPtr<T> MakeShared(A... args) {
|
||||||
return {new T(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;
|
return Z_ERR_UNIMPLEMENTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto message = MakeShared<Message>();
|
auto message = glcr::MakeShared<Message>();
|
||||||
message->num_bytes = num_bytes;
|
message->num_bytes = num_bytes;
|
||||||
message->bytes = new uint8_t[num_bytes];
|
message->bytes = new uint8_t[num_bytes];
|
||||||
for (uint64_t i = 0; i < num_bytes; i++) {
|
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) {
|
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->bytes = new uint8_t[8];
|
||||||
msg->num_bytes = sizeof(init);
|
msg->num_bytes = sizeof(init);
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "capability/capability.h"
|
#include "capability/capability.h"
|
||||||
|
#include "glacier/memory/shared_ptr.h"
|
||||||
#include "include/ztypes.h"
|
#include "include/ztypes.h"
|
||||||
#include "lib/linked_list.h"
|
#include "lib/linked_list.h"
|
||||||
#include "lib/shared_ptr.h"
|
|
||||||
|
|
||||||
class MessageQueue {
|
class MessageQueue {
|
||||||
public:
|
public:
|
||||||
|
@ -40,5 +40,5 @@ class UnboundedMessageQueue : public MessageQueue {
|
||||||
LinkedList<RefPtr<Capability>> caps;
|
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/mutex.h"
|
||||||
#include "lib/pair.h"
|
#include "lib/pair.h"
|
||||||
#include "lib/ref_ptr.h"
|
#include "lib/ref_ptr.h"
|
||||||
#include "lib/shared_ptr.h"
|
|
||||||
#include "object/kernel_object.h"
|
#include "object/kernel_object.h"
|
||||||
#include "usr/zcall_internal.h"
|
#include "usr/zcall_internal.h"
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
#include "lib/linked_list.h"
|
#include "lib/linked_list.h"
|
||||||
#include "lib/message_queue.h"
|
#include "lib/message_queue.h"
|
||||||
#include "lib/mutex.h"
|
#include "lib/mutex.h"
|
||||||
#include "lib/shared_ptr.h"
|
|
||||||
#include "object/kernel_object.h"
|
#include "object/kernel_object.h"
|
||||||
#include "object/thread.h"
|
#include "object/thread.h"
|
||||||
#include "usr/zcall_internal.h"
|
#include "usr/zcall_internal.h"
|
||||||
|
|
Loading…
Reference in New Issue