acadia/zion/object/channel.h

51 lines
1.4 KiB
C
Raw Normal View History

#pragma once
#include <glacier/container/intrusive_list.h>
2023-06-21 20:47:40 -07:00
#include <glacier/container/pair.h>
2023-06-21 15:07:40 -07:00
#include <glacier/memory/ref_ptr.h>
#include "capability/capability.h"
#include "include/ztypes.h"
#include "lib/message_queue.h"
2023-06-15 16:20:29 -07:00
#include "lib/mutex.h"
#include "object/kernel_object.h"
#include "usr/zcall_internal.h"
class Channel;
template <>
struct KernelObjectTag<Channel> {
static const uint64_t type = KernelObject::CHANNEL;
};
class Channel : public KernelObject {
public:
uint64_t TypeTag() override { return KernelObject::CHANNEL; }
2023-06-21 20:47:40 -07:00
static glcr::Pair<glcr::RefPtr<Channel>, glcr::RefPtr<Channel>>
CreateChannelPair();
2023-06-21 15:07:40 -07:00
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);
private:
// FIXME: We will likely never close the channel based on this
// circular dependency.
2023-06-21 15:07:40 -07:00
glcr::RefPtr<Channel> peer_{nullptr};
2023-06-15 16:20:29 -07:00
Mutex mutex_{"channel"};
UnboundedMessageQueue message_queue_;
2023-06-15 16:20:29 -07:00
glcr::IntrusiveList<Thread> blocked_threads_;
2023-06-21 15:07:40 -07:00
friend class glcr::MakeRefCountedFriend<Channel>;
Channel() {}
2023-06-21 15:07:40 -07:00
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);
};