[kernel] Simplify mailbox interface to call/respond

The only real usage of mailbox was mailbox_call or
mailbox_respond_receive. This change simplifies the interface to just
these syscalls.
This commit is contained in:
Justin C. Miller
2022-10-11 17:36:23 -07:00
parent 9ac4e51224
commit c9bcc87511
5 changed files with 53 additions and 157 deletions

View File

@@ -45,18 +45,6 @@ mailbox::close()
m_queue.clear();
}
void
mailbox::send(message *msg)
{
util::scoped_lock lock {m_message_lock};
m_messages.push_back(msg);
thread *t = m_queue.pop_next();
lock.release();
if (t) t->wake(has_message);
}
bool
mailbox::call(message *msg)
{

View File

@@ -39,11 +39,6 @@ public:
/// Check if the mailbox has been closed
inline bool closed() const { return m_closed; }
/// Send a message to a thread waiting to receive on this mailbox. If no threads
/// are currently trying to receive, block the current thread.
/// \arg msg The mailbox::message data structure to send
void send(message *msg);
/// Send a message to a thread waiting to receive on this mailbox, and block the
/// current thread awaiting a response. The response will be placed in the message
/// object provided.

View File

@@ -69,63 +69,6 @@ prep_receive(
}
}
j6_status_t
mailbox_send(
mailbox *self,
uint64_t tag,
uint64_t subtag,
j6_handle_t * handles,
size_t handle_count)
{
mailbox::message *msg = new mailbox::message;
j6_status_t s = prep_send(msg,
tag, subtag,
handles, handle_count);
if (s != j6_status_ok) {
delete msg;
return s;
}
self->send(msg);
return j6_status_ok;
}
j6_status_t
mailbox_receive(
mailbox *self,
uint64_t *tag,
uint64_t *subtag,
j6_handle_t *handles,
size_t *handle_count,
uint16_t *reply_tag,
uint64_t flags)
{
if (*handle_count < mailbox::max_handle_count)
return j6_err_insufficient;
mailbox::message *msg = nullptr;
bool block = flags & j6_mailbox_block;
if (!self->receive(msg, block)) {
// No message received
return self->closed() ? j6_status_closed :
!block ? j6_status_would_block :
j6_err_unexpected;
}
prep_receive(msg,
tag, subtag, reply_tag,
handles, handle_count);
if (*reply_tag == 0)
delete msg;
return j6_status_ok;
}
j6_status_t
mailbox_call(
mailbox *self,
@@ -159,34 +102,8 @@ mailbox_call(
return j6_status_ok;
}
j6_status_t
mailbox_respond(
mailbox *self,
uint64_t tag,
uint64_t subtag,
j6_handle_t * handles,
size_t handle_count,
uint16_t reply_tag)
{
mailbox::replyer reply = self->reply(reply_tag);
if (!reply.valid())
return j6_err_invalid_arg;
j6_status_t s = prep_send(reply.msg, tag, subtag,
handles, handle_count);
if (s != j6_status_ok) {
reply.error(s);
return s;
}
return j6_status_ok;
}
j6_status_t
mailbox_respond_receive(
mailbox *self,
uint64_t *tag,
uint64_t *subtag,
@@ -196,17 +113,43 @@ mailbox_respond_receive(
uint16_t *reply_tag,
uint64_t flags)
{
j6_status_t s = mailbox_respond(self, *tag, *subtag, handles, handles_in, *reply_tag);
if (s != j6_status_ok)
return s;
if (*reply_tag) {
mailbox::replyer reply = self->reply(*reply_tag);
if (!reply.valid())
return j6_err_invalid_arg;
s = mailbox_receive(self, tag, subtag, handles, handle_count, reply_tag, flags);
if (s != j6_status_ok)
return s;
j6_status_t s = prep_send(reply.msg, *tag, *subtag,
handles, handles_in);
if (s != j6_status_ok) {
reply.error(s);
return s;
}
}
if (*handle_count < mailbox::max_handle_count)
return j6_err_insufficient;
mailbox::message *msg = nullptr;
bool block = flags & j6_mailbox_block;
if (!self->receive(msg, block)) {
// No message received
return self->closed() ? j6_status_closed :
!block ? j6_status_would_block :
j6_err_unexpected;
}
prep_receive(msg,
tag, subtag, reply_tag,
handles, handle_count);
if (*reply_tag == 0)
delete msg;
return j6_status_ok;
}
} // namespace syscalls