acadia/zion/object/port.h
Drew Galbraith a47bac9966 [zion] Dynamically check Capability type.
Instead of passing an enum with the capability when creating it, relying
on polymorphism and a template struct tag to determine the object type
at runtime.

This is cleaner and avoids errors where we pass the wrong capability
type with the cap and do a bad cast at runtime.
2023-06-16 14:53:57 -07:00

37 lines
673 B
C++

#pragma once
#include "lib/linked_list.h"
#include "lib/mutex.h"
#include "object/kernel_object.h"
#include "object/thread.h"
#include "usr/zcall_internal.h"
class Port;
template <>
struct KernelObjectTag<Port> {
static const uint64_t type = KernelObject::PORT;
};
class Port : public KernelObject {
public:
uint64_t TypeTag() override { return KernelObject::PORT; }
Port();
z_err_t Write(const ZMessage& msg);
z_err_t Read(ZMessage& msg);
private:
struct Message {
uint64_t type;
uint64_t num_bytes;
uint8_t* bytes;
};
LinkedList<Message> pending_messages_;
LinkedList<RefPtr<Thread>> blocked_threads_;
Mutex mutex_{"Port"};
};