[kernel] Simplify mailbox code, and messages

A number of simplifications of mailboxes now that the interface is much
simpler, and synchronous.

* call and respond can now only transfer one handle at a time
* mailbox objects got rid of the message queue, and just have
  wait_queues of blocked threads, and a reply_to map.
* threads now have a message_data struct on them for use by mailboxes
This commit is contained in:
Justin C. Miller
2022-10-14 01:02:56 -07:00
parent e830a3d37b
commit 1a04310f80
12 changed files with 147 additions and 274 deletions

View File

@@ -61,10 +61,7 @@ channel_pump_loop()
uint64_t tag = j6_proto_sl_register;
uint64_t proto_id = "jsix.protocol.stream.ouput"_id;
size_t handle_count = 1;
result = j6_mailbox_call(slp,
&tag, &proto_id,
&cout_write, &handle_count);
result = j6_mailbox_call(slp, &tag, &proto_id, &cout_write);
if (result != j6_status_ok)
return 4;

View File

@@ -25,23 +25,17 @@ service_locator_start(j6_handle_t mb)
uint64_t tag = 0;
uint64_t subtag = 0;
uint16_t reply_tag = 0;
j6_handle_t handles[10] = {0};
const size_t handles_capacity = sizeof(handles)/sizeof(j6_handle_t);
size_t handles_count = 0;
uint64_t reply_tag = 0;
j6_handle_t give_handle = j6_handle_invalid;
uint64_t proto_id;
while (true) {
size_t handles_in = handles_count;
handles_count = handles_capacity;
j6_status_t s = j6_mailbox_respond(mb, &tag, &subtag, &give_handle,
&reply_tag, j6_mailbox_block);
j6_status_t s = j6_mailbox_respond(mb,
&tag, &subtag,
handles, &handles_count,
handles_in, &reply_tag,
j6_mailbox_block);
if (s != j6_status_ok)
while (1);
handle_entry *found = nullptr;
@@ -49,22 +43,21 @@ service_locator_start(j6_handle_t mb)
case j6_proto_base_get_proto_id:
tag = j6_proto_base_proto_id;
subtag = j6_proto_sl_id;
handles_count = 0;
give_handle = j6_handle_invalid;
break;
case j6_proto_sl_register:
proto_id = subtag;
if (handles_count != 1) {
if (give_handle == j6_handle_invalid) {
tag = j6_proto_base_status;
subtag = j6_err_invalid_arg;
handles_count = 0;
break;
}
services.insert( {proto_id, handles[0]} );
services.insert( {proto_id, give_handle} );
tag = j6_proto_base_status;
subtag = j6_status_ok;
handles_count = 0;
give_handle = j6_handle_invalid;
break;
case j6_proto_sl_find:
@@ -72,18 +65,16 @@ service_locator_start(j6_handle_t mb)
tag = j6_proto_sl_result;
found = services.find(proto_id);
if (found) {
handles_count = 1;
handles[0] = found->handle;
} else {
handles_count = 0;
}
if (found)
give_handle = found->handle;
else
give_handle = j6_handle_invalid;
break;
default:
tag = j6_proto_base_status;
subtag = j6_err_invalid_arg;
handles_count = 0;
give_handle = j6_handle_invalid;
break;
}
}

View File

@@ -125,13 +125,11 @@ main(int argc, const char **argv)
for (unsigned i = 0; i < 100; ++i) {
uint64_t tag = j6_proto_sl_find;
uint64_t proto_id = "jsix.protocol.stream.ouput"_id;
size_t handle_count = 0;
j6_status_t s = j6_mailbox_call(slp, &tag,
&proto_id, &cout, &handle_count);
j6_status_t s = j6_mailbox_call(slp, &tag, &proto_id, &cout);
if (s == j6_status_ok &&
tag == j6_proto_sl_result &&
handle_count == 1)
cout != j6_handle_invalid)
break;
cout = j6_handle_invalid;