From 19e394ae7bc9ccfa89f23f5b8c844f724bae3d9b Mon Sep 17 00:00:00 2001 From: Drew Galbraith Date: Wed, 22 Nov 2023 13:30:59 -0800 Subject: [PATCH] [Yellowstone] Use semaphores for handling yellowstone registration. --- sys/yellowstone/yellowstone.cpp | 4 ++-- sys/yellowstone/yellowstone_server.cpp | 31 ++++++++------------------ sys/yellowstone/yellowstone_server.h | 13 +++++------ 3 files changed, 17 insertions(+), 31 deletions(-) diff --git a/sys/yellowstone/yellowstone.cpp b/sys/yellowstone/yellowstone.cpp index a7b9571..7100572 100644 --- a/sys/yellowstone/yellowstone.cpp +++ b/sys/yellowstone/yellowstone.cpp @@ -27,12 +27,12 @@ uint64_t main(uint64_t port_cap) { ASSIGN_OR_RETURN(YellowstoneClient client1, server->CreateClient()); check(SpawnProcess(gBootDenaliVmmoCap, client1.Capability())); - check(server->WaitDenaliRegistered()); + server->WaitDenaliRegistered(); ASSIGN_OR_RETURN(YellowstoneClient client2, server->CreateClient()); check(SpawnProcess(gBootVictoriaFallsVmmoCap, client2.Capability())); - check(server->WaitVictoriaFallsRegistered()); + server->WaitVictoriaFallsRegistered(); dbgln("VFS Available."); diff --git a/sys/yellowstone/yellowstone_server.cpp b/sys/yellowstone/yellowstone_server.cpp index d6a26c7..e1ca72f 100644 --- a/sys/yellowstone/yellowstone_server.cpp +++ b/sys/yellowstone/yellowstone_server.cpp @@ -34,21 +34,12 @@ glcr::ErrorOr> YellowstoneServer::Create() { z_cap_t endpoint_cap; RET_ERR(ZEndpointCreate(&endpoint_cap)); - ASSIGN_OR_RETURN(Mutex denali_mut, Mutex::Create()); - RET_ERR(denali_mut.Lock()); - - ASSIGN_OR_RETURN(Mutex victoriafalls_mut, Mutex::Create()); - RET_ERR(victoriafalls_mut.Lock()); - - return glcr::UniquePtr(new YellowstoneServer( - endpoint_cap, glcr::Move(denali_mut), glcr::Move(victoriafalls_mut))); + return glcr::UniquePtr( + new YellowstoneServer(endpoint_cap)); } -YellowstoneServer::YellowstoneServer(z_cap_t endpoint_cap, Mutex&& denali_mutex, - Mutex&& victoriafalls_mutex) - : YellowstoneServerBase(endpoint_cap), - has_denali_mutex_(glcr::Move(denali_mutex)), - has_victoriafalls_mutex_(glcr::Move(victoriafalls_mutex)) {} +YellowstoneServer::YellowstoneServer(z_cap_t endpoint_cap) + : YellowstoneServerBase(endpoint_cap) {} glcr::ErrorCode YellowstoneServer::HandleGetAhciInfo(const Empty&, AhciInfo& info) { @@ -105,12 +96,12 @@ glcr::ErrorCode YellowstoneServer::HandleRegisterEndpoint( device_id_ = part_info_or.value().device_id; lba_offset_ = part_info_or.value().partition_lba; - check(has_denali_mutex_.Release()); + has_denali_semaphore_.Signal(); } else if (req.endpoint_name() == "victoriafalls") { // FIXME: Probably make a separate copy for use within yellowstone vs // transmit to other processes. vfs_client_ = glcr::MakeShared(req.endpoint_capability()); - check(has_victoriafalls_mutex_.Release()); + has_victoriafalls_semaphore_.Signal(); } else { dbgln("[WARN] Got endpoint cap type: {}", req.endpoint_name().cstr()); } @@ -129,14 +120,10 @@ glcr::ErrorCode YellowstoneServer::HandleGetEndpoint( return glcr::OK; } -glcr::ErrorCode YellowstoneServer::WaitDenaliRegistered() { - RET_ERR(has_denali_mutex_.Lock()); - return has_denali_mutex_.Release(); -} +void YellowstoneServer::WaitDenaliRegistered() { has_denali_semaphore_.Wait(); } -glcr::ErrorCode YellowstoneServer::WaitVictoriaFallsRegistered() { - RET_ERR(has_victoriafalls_mutex_.Lock()); - return has_victoriafalls_mutex_.Release(); +void YellowstoneServer::WaitVictoriaFallsRegistered() { + has_victoriafalls_semaphore_.Wait(); } glcr::SharedPtr YellowstoneServer::GetVFSClient() { diff --git a/sys/yellowstone/yellowstone_server.h b/sys/yellowstone/yellowstone_server.h index c7c279b..b301984 100644 --- a/sys/yellowstone/yellowstone_server.h +++ b/sys/yellowstone/yellowstone_server.h @@ -5,8 +5,8 @@ #include #include #include -#include #include +#include #include #include @@ -26,8 +26,8 @@ class YellowstoneServer : public YellowstoneServerBase { glcr::ErrorCode HandleGetEndpoint(const GetEndpointRequest&, Endpoint&) override; - glcr::ErrorCode WaitDenaliRegistered(); - glcr::ErrorCode WaitVictoriaFallsRegistered(); + void WaitDenaliRegistered(); + void WaitVictoriaFallsRegistered(); glcr::SharedPtr GetVFSClient(); @@ -40,9 +40,8 @@ class YellowstoneServer : public YellowstoneServerBase { PciReader pci_reader_; - Mutex has_denali_mutex_; - Mutex has_victoriafalls_mutex_; + Semaphore has_denali_semaphore_; + Semaphore has_victoriafalls_semaphore_; - YellowstoneServer(z_cap_t endpoint_cap, Mutex&& denali_mutex, - Mutex&& victoriafalls_mutex); + YellowstoneServer(z_cap_t endpoint_cap); };