Files
jsix/src/kernel/syscalls/channel.cpp
Justin C. Miller 9b75acf0b5 [kernel] Re-add channel syscalls
Channels were unused, and while they were listed in syscalls.def, they
had no syscalls listed in their interface. This change adds them back,
and updates them to the curren syscall style.
2022-01-27 22:37:04 -08:00

54 lines
952 B
C++

#include <j6/errors.h>
#include <j6/types.h>
#include <util/counted.h>
#include "objects/channel.h"
#include "syscalls/helpers.h"
using namespace obj;
namespace syscalls {
j6_status_t
channel_create(j6_handle_t *self)
{
construct_handle<channel>(self);
return j6_status_ok;
}
j6_status_t
channel_send(channel *self, void *data, size_t *data_len)
{
if (self->closed())
return j6_status_closed;
const util::buffer buffer {data, *data_len};
*data_len = self->enqueue(buffer);
return j6_status_ok;
}
j6_status_t
channel_receive(channel *self, void *data, size_t *data_len)
{
if (self->closed())
return j6_status_closed;
util::buffer buffer {data, *data_len};
*data_len = self->dequeue(buffer);
return j6_status_ok;
}
j6_status_t
channel_close(channel *self)
{
if (self->closed())
return j6_status_closed;
self->close();
return j6_status_ok;
}
} // namespace syscalls