52 lines
1.3 KiB
C
52 lines
1.3 KiB
C
// SPDX-License-Identifier: MIT
|
|
|
|
#pragma once
|
|
|
|
#include <zinnia/channel.h>
|
|
#include <zinnia/status.h>
|
|
#include <kernel/spin.h>
|
|
#include <kernel/tailq.h>
|
|
#include <kernel/wait.h>
|
|
#include <stddef.h>
|
|
|
|
struct namespace_desc;
|
|
|
|
struct channel_msg {
|
|
void* data;
|
|
size_t num_bytes;
|
|
struct namespace_desc* descs;
|
|
size_t num_handles;
|
|
tailq_link(struct channel_msg) next;
|
|
};
|
|
|
|
struct channel {
|
|
struct channel* peer;
|
|
struct spinlock lock;
|
|
enum zn_channel_flags flags;
|
|
tailq_head(struct channel_msg) messages;
|
|
struct wait_queue waiters;
|
|
};
|
|
|
|
// Creates a linked pair of channel endpoints.
|
|
zn_status_t channel_create(struct channel** ep0, struct channel** ep1);
|
|
|
|
// Writes a message to the peer channel.
|
|
// On success, ownership of `data` and `descs` transfers to the message.
|
|
// On failure, the caller retains ownership and must free them.
|
|
zn_status_t channel_write(
|
|
struct channel* ch,
|
|
void* data,
|
|
size_t num_bytes,
|
|
struct namespace_desc* descs,
|
|
size_t num_handles
|
|
);
|
|
|
|
// Non-blocking dequeue of the next message.
|
|
zn_status_t channel_read(struct channel* ch, struct channel_msg** msg);
|
|
|
|
// Non-blocking check for message availability.
|
|
zn_status_t channel_poll(struct channel* ch);
|
|
|
|
// Frees a channel message and its associated data and descriptors.
|
|
void channel_msg_free(struct channel_msg* msg);
|