[zion] Move IPC objects to share code

This commit is contained in:
Drew Galbraith 2023-06-21 23:42:21 -07:00
parent 58df2c0ed2
commit 9dd457391c
14 changed files with 125 additions and 196 deletions

View file

@ -1,6 +1,5 @@
#pragma once
#include <glacier/container/intrusive_list.h>
#include <glacier/container/pair.h>
#include <glacier/memory/ref_ptr.h>
@ -8,6 +7,7 @@
#include "include/ztypes.h"
#include "lib/message_queue.h"
#include "lib/mutex.h"
#include "object/ipc_object.h"
#include "object/kernel_object.h"
#include "usr/zcall_internal.h"
@ -18,7 +18,7 @@ struct KernelObjectTag<Channel> {
static const uint64_t type = KernelObject::CHANNEL;
};
class Channel : public KernelObject {
class Channel : public IpcObject {
public:
uint64_t TypeTag() override { return KernelObject::CHANNEL; }
static glcr::Pair<glcr::RefPtr<Channel>, glcr::RefPtr<Channel>>
@ -26,25 +26,20 @@ class Channel : public KernelObject {
glcr::RefPtr<Channel> peer() { return peer_; }
z_err_t Write(uint64_t num_bytes, const void* bytes, uint64_t num_caps,
const z_cap_t* caps);
z_err_t Read(uint64_t* num_bytes, void* bytes, uint64_t* num_caps,
z_cap_t* caps);
virtual MessageQueue& GetSendMessageQueue() override {
return peer_->message_queue_;
}
virtual MessageQueue& GetRecvMessageQueue() override {
return message_queue_;
}
private:
// FIXME: We will likely never close the channel based on this
// circular dependency.
glcr::RefPtr<Channel> peer_{nullptr};
Mutex mutex_{"channel"};
UnboundedMessageQueue message_queue_;
glcr::IntrusiveList<Thread> blocked_threads_;
friend class glcr::MakeRefCountedFriend<Channel>;
Channel() {}
void SetPeer(const glcr::RefPtr<Channel>& peer) { peer_ = peer; }
z_err_t WriteInternal(uint64_t num_bytes, const void* bytes,
uint64_t num_caps, const z_cap_t* caps);
};