From a45aabe68c5222dfe964797a9aec5d8c186f1a7d Mon Sep 17 00:00:00 2001 From: Christian Helmuth Date: Tue, 12 Apr 2022 14:32:35 +0200 Subject: [PATCH] usb_block: handle block requests in Signal_handler only Before this commit, the block-request handler was implemented as Io_signal_handler and, additionally, the USB driver called the block-request handler on request completion directly on I/O level. This is generally a bad idea because I/O handlers should avoid to have direct global side effects. In contrast, application logic should be implemented in way that it consumes atomic state changes after I/O completed. Now USB I/O completion locally submits a signal to the block-request Signal_handler. --- repos/os/src/drivers/usb_block/main.cc | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/repos/os/src/drivers/usb_block/main.cc b/repos/os/src/drivers/usb_block/main.cc index 475e5e596d..315ffe8c62 100644 --- a/repos/os/src/drivers/usb_block/main.cc +++ b/repos/os/src/drivers/usb_block/main.cc @@ -149,7 +149,7 @@ struct Usb::Block_driver : Usb::Completion Usb::Connection usb { env, &alloc, get_label<128>(config.xml()).string(), 2 * (1<<20), state_change_dispatcher }; Usb::Device device; - Signal_handler
&wake_up_handler; + Signal_handler
&block_request_handler; /* * Reporter @@ -651,7 +651,11 @@ struct Usb::Block_driver : Usb::Completion request->block_request.success = success; request->completed = true; - wake_up_handler.dispatch(0); + /* + * An I/O operation completed, thus trigger block-request handling on + * component service level. + */ + block_request_handler.local_submit(); } /** @@ -789,10 +793,10 @@ struct Usb::Block_driver : Usb::Completion */ Block_driver(Env &env, Allocator &alloc, Genode::Signal_context_capability sigh, - Signal_handler
&wake_up_handler) + Signal_handler
&block_request_handler) : env(env), ep(env.ep()), announce_sigh(sigh), alloc(&alloc), - device(&alloc, usb, ep), wake_up_handler(wake_up_handler) + device(&alloc, usb, ep), block_request_handler(block_request_handler) { parse_config(config.xml()); reporter.enabled(true); @@ -915,7 +919,7 @@ struct Usb::Main : Rpc_object> Signal_handler
announce_dispatcher { env.ep(), *this, &Usb::Main::announce }; - Io_signal_handler
request_handler { + Signal_handler
request_handler { env.ep(), *this, &Main::handle_requests }; Block_driver driver { env, heap, announce_dispatcher, request_handler };