2023-06-12 19:20:51 -07:00
|
|
|
#pragma once
|
|
|
|
|
2023-06-16 15:58:50 -07:00
|
|
|
#include "capability/capability.h"
|
2023-06-12 19:20:51 -07:00
|
|
|
#include "lib/linked_list.h"
|
2023-06-20 15:29:32 -07:00
|
|
|
#include "lib/message_queue.h"
|
2023-06-12 20:56:25 -07:00
|
|
|
#include "lib/mutex.h"
|
2023-06-12 19:20:51 -07:00
|
|
|
#include "object/kernel_object.h"
|
2023-06-12 20:56:25 -07:00
|
|
|
#include "object/thread.h"
|
2023-06-12 19:20:51 -07:00
|
|
|
#include "usr/zcall_internal.h"
|
|
|
|
|
2023-06-16 14:53:57 -07:00
|
|
|
class Port;
|
|
|
|
|
|
|
|
template <>
|
|
|
|
struct KernelObjectTag<Port> {
|
|
|
|
static const uint64_t type = KernelObject::PORT;
|
|
|
|
};
|
|
|
|
|
2023-06-12 19:20:51 -07:00
|
|
|
class Port : public KernelObject {
|
|
|
|
public:
|
2023-06-16 14:53:57 -07:00
|
|
|
uint64_t TypeTag() override { return KernelObject::PORT; }
|
|
|
|
|
2023-06-12 19:20:51 -07:00
|
|
|
Port();
|
|
|
|
|
2023-06-20 15:29:32 -07:00
|
|
|
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);
|
2023-06-12 19:20:51 -07:00
|
|
|
|
2023-06-17 00:07:58 -07:00
|
|
|
void WriteKernel(uint64_t init, RefPtr<Capability> cap);
|
|
|
|
|
2023-06-16 23:15:28 -07:00
|
|
|
bool HasMessages();
|
|
|
|
|
2023-06-12 19:20:51 -07:00
|
|
|
private:
|
2023-06-20 15:29:32 -07:00
|
|
|
UnboundedMessageQueue message_queue_;
|
2023-06-12 20:56:25 -07:00
|
|
|
LinkedList<RefPtr<Thread>> blocked_threads_;
|
|
|
|
|
|
|
|
Mutex mutex_{"Port"};
|
2023-06-12 19:20:51 -07:00
|
|
|
};
|