From 740c92bf152d1f2fa3929f5e654c25b4986946cd Mon Sep 17 00:00:00 2001 From: Alexander van der Grinten Date: Fri, 25 May 2018 23:50:17 +0200 Subject: [PATCH] general: Update to new libasync mechanism --- drivers/block/ata/src/main.cpp | 8 +++++--- drivers/clocktracker/src/main.cpp | 8 +++++--- drivers/gfx/bochs/src/main.cpp | 10 ++++++---- drivers/gfx/intel/src/main.cpp | 8 +++++--- drivers/gfx/plainfb/src/main.cpp | 8 +++++--- drivers/gfx/virtio/src/main.cpp | 8 +++++--- drivers/kbd/src/main.cpp | 19 ++++++++++--------- drivers/uart/src/main.cpp | 3 +-- drivers/usb/devices/hid/src/main.cpp | 8 +++++--- drivers/usb/devices/storage/src/main.cpp | 8 +++++--- drivers/usb/hcds/ehci/src/main.cpp | 8 +++++--- drivers/usb/hcds/uhci/src/main.cpp | 8 +++++--- drivers/virtio/src/main-block.cpp | 8 +++++--- hel/include/helix/ipc.hpp | 6 ++++-- hel/src/globals.cpp | 5 +++++ mbus/src/main.cpp | 8 +++++--- posix/subsystem/src/inotify.cpp | 1 + posix/subsystem/src/main.cpp | 22 +++++++++++++--------- posix/subsystem/src/signalfd.cpp | 1 + 19 files changed, 96 insertions(+), 59 deletions(-) diff --git a/drivers/block/ata/src/main.cpp b/drivers/block/ata/src/main.cpp index ec1ce425d..692bb112c 100644 --- a/drivers/block/ata/src/main.cpp +++ b/drivers/block/ata/src/main.cpp @@ -216,9 +216,11 @@ Controller globalController; int main() { printf("block-ata: Starting driver\n"); - globalController.run(); + { + async::queue_scope scope{helix::globalQueue()}; + globalController.run(); + } - while(true) - helix::Dispatcher::global().dispatch(); + helix::globalQueue()->run(); } diff --git a/drivers/clocktracker/src/main.cpp b/drivers/clocktracker/src/main.cpp index e01030670..cbcb158c5 100644 --- a/drivers/clocktracker/src/main.cpp +++ b/drivers/clocktracker/src/main.cpp @@ -163,10 +163,12 @@ COFIBER_ROUTINE(cofiber::no_future, initializeDriver(), ([] { int main() { std::cout << "drivers/clocktracker: Starting driver" << std::endl; - initializeDriver(); + { + async::queue_scope scope{helix::globalQueue()}; + initializeDriver(); + } - while(true) - helix::Dispatcher::global().dispatch(); + helix::globalQueue()->run(); return 0; } diff --git a/drivers/gfx/bochs/src/main.cpp b/drivers/gfx/bochs/src/main.cpp index f414fb17b..5f6385f4e 100644 --- a/drivers/gfx/bochs/src/main.cpp +++ b/drivers/gfx/bochs/src/main.cpp @@ -505,11 +505,13 @@ COFIBER_ROUTINE(cofiber::no_future, observeControllers(), ([] { int main() { printf("gfx/bochs: Starting driver\n"); - - observeControllers(); - while(true) - helix::Dispatcher::global().dispatch(); + { + async::queue_scope scope{helix::globalQueue()}; + observeControllers(); + } + + helix::globalQueue()->run(); return 0; } diff --git a/drivers/gfx/intel/src/main.cpp b/drivers/gfx/intel/src/main.cpp index d245f8475..e010adf78 100644 --- a/drivers/gfx/intel/src/main.cpp +++ b/drivers/gfx/intel/src/main.cpp @@ -603,10 +603,12 @@ COFIBER_ROUTINE(cofiber::no_future, observeControllers(), ([] { int main() { printf("Starting Intel graphics driver\n"); - observeControllers(); + { + async::queue_scope scope{helix::globalQueue()}; + observeControllers(); + } - while(true) - helix::Dispatcher::global().dispatch(); + helix::globalQueue()->run(); return 0; } diff --git a/drivers/gfx/plainfb/src/main.cpp b/drivers/gfx/plainfb/src/main.cpp index fb99622e2..210c59a6d 100644 --- a/drivers/gfx/plainfb/src/main.cpp +++ b/drivers/gfx/plainfb/src/main.cpp @@ -422,10 +422,12 @@ COFIBER_ROUTINE(cofiber::no_future, observeControllers(), ([] { int main() { std::cout << "gfx/plainfb: Starting driver" << std::endl; - observeControllers(); + { + async::queue_scope scope{helix::globalQueue()}; + observeControllers(); + } - while(true) - helix::Dispatcher::global().dispatch(); + helix::globalQueue()->run(); return 0; } diff --git a/drivers/gfx/virtio/src/main.cpp b/drivers/gfx/virtio/src/main.cpp index f2bb9cc35..1f24a6933 100644 --- a/drivers/gfx/virtio/src/main.cpp +++ b/drivers/gfx/virtio/src/main.cpp @@ -674,10 +674,12 @@ COFIBER_ROUTINE(cofiber::no_future, observeControllers(), ([] { int main() { std::cout << "gfx/virtio: Starting driver" << std::endl; - observeControllers(); + { + async::queue_scope scope{helix::globalQueue()}; + observeControllers(); + } - while(true) - helix::Dispatcher::global().dispatch(); + helix::globalQueue()->run(); return 0; } diff --git a/drivers/kbd/src/main.cpp b/drivers/kbd/src/main.cpp index d09be8bde..062fbb532 100644 --- a/drivers/kbd/src/main.cpp +++ b/drivers/kbd/src/main.cpp @@ -508,18 +508,19 @@ int main() { sendByte(0xF4); mouseState = kMouseWaitForAck; - runKbd(); - runMouse(); + { + async::queue_scope scope{helix::globalQueue()}; - std::cout << "ps2-hid: mbus objects are ready" << std::endl; + runKbd(); + runMouse(); + std::cout << "ps2-hid: mbus objects are ready" << std::endl; - handleKbdIrqs(); - handleMouseIrqs(); -// pollController(); - - while(true) { - helix::Dispatcher::global().dispatch(); + handleKbdIrqs(); + handleMouseIrqs(); + // pollController(); } + + helix::globalQueue()->run(); return 0; } diff --git a/drivers/uart/src/main.cpp b/drivers/uart/src/main.cpp index 9b3dc7d32..4988efea6 100644 --- a/drivers/uart/src/main.cpp +++ b/drivers/uart/src/main.cpp @@ -262,8 +262,7 @@ int main() { handleIrqs(); - while(true) - helix::Dispatcher::global().dispatch(); + helix::globalQueue()->run(); return 0; } diff --git a/drivers/usb/devices/hid/src/main.cpp b/drivers/usb/devices/hid/src/main.cpp index 6795e9bd6..f3dc2ae00 100644 --- a/drivers/usb/devices/hid/src/main.cpp +++ b/drivers/usb/devices/hid/src/main.cpp @@ -659,10 +659,12 @@ int main() { // HEL_CHECK(helSetPriority(kHelThisThread, 2)); - observeDevices(); + { + async::queue_scope scope{helix::globalQueue()}; + observeDevices(); + } - while(true) - helix::Dispatcher::global().dispatch(); + helix::globalQueue()->run(); return 0; } diff --git a/drivers/usb/devices/storage/src/main.cpp b/drivers/usb/devices/storage/src/main.cpp index c54173a40..4cb31dd9f 100644 --- a/drivers/usb/devices/storage/src/main.cpp +++ b/drivers/usb/devices/storage/src/main.cpp @@ -214,10 +214,12 @@ COFIBER_ROUTINE(cofiber::no_future, observeDevices(), ([] { int main() { std::cout << "block-usb: Starting driver" << std::endl; - observeDevices(); + { + async::queue_scope scope{helix::globalQueue()}; + observeDevices(); + } - while(true) - helix::Dispatcher::global().dispatch(); + helix::globalQueue()->run(); return 0; } diff --git a/drivers/usb/hcds/ehci/src/main.cpp b/drivers/usb/hcds/ehci/src/main.cpp index fae419bbf..ad3d0ef28 100644 --- a/drivers/usb/hcds/ehci/src/main.cpp +++ b/drivers/usb/hcds/ehci/src/main.cpp @@ -1006,10 +1006,12 @@ int main() { // HEL_CHECK(helSetPriority(kHelThisThread, 2)); - observeControllers(); + { + async::queue_scope scope{helix::globalQueue()}; + observeControllers(); + } - while(true) - helix::Dispatcher::global().dispatch(); + helix::globalQueue()->run(); return 0; } diff --git a/drivers/usb/hcds/uhci/src/main.cpp b/drivers/usb/hcds/uhci/src/main.cpp index d77f04c6b..b0ae077a1 100644 --- a/drivers/usb/hcds/uhci/src/main.cpp +++ b/drivers/usb/hcds/uhci/src/main.cpp @@ -1072,10 +1072,12 @@ int main() { // HEL_CHECK(helSetPriority(kHelThisThread, 2)); - observeControllers(); + { + async::queue_scope scope{helix::globalQueue()}; + observeControllers(); + } - while(true) - helix::Dispatcher::global().dispatch(); + helix::globalQueue()->run(); return 0; } diff --git a/drivers/virtio/src/main-block.cpp b/drivers/virtio/src/main-block.cpp index 8be23a43e..389f47bde 100644 --- a/drivers/virtio/src/main-block.cpp +++ b/drivers/virtio/src/main-block.cpp @@ -69,9 +69,11 @@ int main() { // HEL_CHECK(helSetPriority(kHelThisThread, 3)); - observeDevices(); + { + async::queue_scope scope{helix::globalQueue()}; + observeDevices(); + } - while(true) - helix::Dispatcher::global().dispatch(); + helix::globalQueue()->run(); } diff --git a/hel/include/helix/ipc.hpp b/hel/include/helix/ipc.hpp index 145357d19..8baf2ebdc 100644 --- a/hel/include/helix/ipc.hpp +++ b/hel/include/helix/ipc.hpp @@ -203,7 +203,7 @@ struct Context { virtual void complete(ElementHandle element) = 0; }; -struct Dispatcher { +struct Dispatcher : async::io_service { friend struct ElementHandle; private: @@ -246,7 +246,7 @@ struct Dispatcher { return _handle; } - void dispatch() { + void wait() override { while(true) { if(_retrieveIndex == _nextIndex) { assert(_activeChunks < (1 << sizeShift)); @@ -853,6 +853,8 @@ inline Submission submitAwaitEvent(BorrowedDescriptor descriptor, AwaitEvent *op return {descriptor, operation, sequence, dispatcher}; } +async::run_queue *globalQueue(); + } // namespace helix #endif // HELIX_HPP diff --git a/hel/src/globals.cpp b/hel/src/globals.cpp index fbdcfcbf9..b5fa71bab 100644 --- a/hel/src/globals.cpp +++ b/hel/src/globals.cpp @@ -12,5 +12,10 @@ Dispatcher &Dispatcher::global() { return dispatcher; } +async::run_queue *globalQueue() { + static async::run_queue queue{&Dispatcher::global()}; + return &queue; +} + } // namespace helix diff --git a/mbus/src/main.cpp b/mbus/src/main.cpp index fd6835af0..b6bc47e94 100644 --- a/mbus/src/main.cpp +++ b/mbus/src/main.cpp @@ -399,9 +399,11 @@ int main() { if(peekauxval(AT_XPIPE, &xpipe)) throw std::runtime_error("No AT_XPIPE specified"); - serve(helix::UniqueLane(xpipe)); + { + async::queue_scope scope{helix::globalQueue()}; + serve(helix::UniqueLane(xpipe)); + } - while(true) - helix::Dispatcher::global().dispatch(); + helix::globalQueue()->run(); } diff --git a/posix/subsystem/src/inotify.cpp b/posix/subsystem/src/inotify.cpp index 9a1a92cbc..c66885c60 100644 --- a/posix/subsystem/src/inotify.cpp +++ b/posix/subsystem/src/inotify.cpp @@ -32,6 +32,7 @@ struct OpenFile : File { COFIBER_ROUTINE(expected, poll(uint64_t sequence) override, ([=] { std::cout << "posix: Fix inotify::poll()" << std::endl; + COFIBER_AWAIT cofiber::suspend_always{}; })) helix::BorrowedDescriptor getPassthroughLane() override { diff --git a/posix/subsystem/src/main.cpp b/posix/subsystem/src/main.cpp index 74391fb5d..65bd0b820 100644 --- a/posix/subsystem/src/main.cpp +++ b/posix/subsystem/src/main.cpp @@ -1557,17 +1557,21 @@ int main() { std::cout << "Starting posix-subsystem" << std::endl; // HEL_CHECK(helSetPriority(kHelThisThread, 1)); + + { + async::queue_scope scope{helix::globalQueue()}; + + drvcore::initialize(); - drvcore::initialize(); + charRegistry.install(createHeloutDevice()); + charRegistry.install(pts::createMasterDevice()); + block_subsystem::run(); + drm_subsystem::run(); + input_subsystem::run(); - charRegistry.install(createHeloutDevice()); - charRegistry.install(pts::createMasterDevice()); - block_subsystem::run(); - drm_subsystem::run(); - input_subsystem::run(); - runInit(); + runInit(); + } - while(true) - helix::Dispatcher::global().dispatch(); + helix::globalQueue()->run(); } diff --git a/posix/subsystem/src/signalfd.cpp b/posix/subsystem/src/signalfd.cpp index dfbf7da08..76d16834a 100644 --- a/posix/subsystem/src/signalfd.cpp +++ b/posix/subsystem/src/signalfd.cpp @@ -30,6 +30,7 @@ struct OpenFile : File { COFIBER_ROUTINE(expected, poll(uint64_t sequence) override, ([=] { std::cout << "posix: Fix signalfd::poll()" << std::endl; + COFIBER_AWAIT cofiber::suspend_always{}; })) helix::BorrowedDescriptor getPassthroughLane() override {