[kernel] Add channel objects

Add the channel object for sending messages between threads. Currently
no good of passing channels to other threads, but global variables in a
single process work. Currently channels are slow and do double copies,
need to refine more.

Tags: ipc
This commit is contained in:
2020-07-26 17:29:11 -07:00
parent ae3290c53d
commit d3e9d92466
10 changed files with 264 additions and 3 deletions

View File

@@ -0,0 +1,76 @@
#include "j6/errors.h"
#include "j6/types.h"
#include "objects/channel.h"
#include "objects/thread.h"
#include "objects/process.h"
#include "scheduler.h"
namespace syscalls {
j6_status_t
channel_create(j6_handle_t *handle)
{
scheduler &s = scheduler::get();
TCB *tcb = s.current();
thread *parent = thread::from_tcb(tcb);
process &p = parent->parent();
channel *c = new channel;
*handle = p.add_handle(c);
return j6_status_ok;
}
j6_status_t
channel_close(j6_handle_t handle)
{
scheduler &s = scheduler::get();
TCB *tcb = s.current();
thread *parent = thread::from_tcb(tcb);
process &p = parent->parent();
kobject *o = p.lookup_handle(handle);
if (!o || o->get_type() != kobject::type::channel)
return j6_err_invalid_arg;
p.remove_handle(handle);
channel *c = static_cast<channel*>(o);
c->close();
return j6_status_ok;
}
j6_status_t
channel_send(j6_handle_t handle, size_t len, void *data)
{
scheduler &s = scheduler::get();
TCB *tcb = s.current();
thread *parent = thread::from_tcb(tcb);
process &p = parent->parent();
kobject *o = p.lookup_handle(handle);
if (!o || o->get_type() != kobject::type::channel)
return j6_err_invalid_arg;
channel *c = static_cast<channel*>(o);
return c->enqueue(len, data);
}
j6_status_t
channel_receive(j6_handle_t handle, size_t *len, void *data)
{
scheduler &s = scheduler::get();
TCB *tcb = s.current();
thread *parent = thread::from_tcb(tcb);
process &p = parent->parent();
kobject *o = p.lookup_handle(handle);
if (!o || o->get_type() != kobject::type::channel)
return j6_err_invalid_arg;
channel *c = static_cast<channel*>(o);
return c->dequeue(len, data);
}
} // namespace syscalls