[Yellowstone] Use semaphores for handling yellowstone registration.

This commit is contained in:
Drew Galbraith 2023-11-22 13:30:59 -08:00
parent 41bf78cf98
commit 19e394ae7b
3 changed files with 17 additions and 31 deletions

View File

@ -27,12 +27,12 @@ uint64_t main(uint64_t port_cap) {
ASSIGN_OR_RETURN(YellowstoneClient client1, server->CreateClient()); ASSIGN_OR_RETURN(YellowstoneClient client1, server->CreateClient());
check(SpawnProcess(gBootDenaliVmmoCap, client1.Capability())); check(SpawnProcess(gBootDenaliVmmoCap, client1.Capability()));
check(server->WaitDenaliRegistered()); server->WaitDenaliRegistered();
ASSIGN_OR_RETURN(YellowstoneClient client2, server->CreateClient()); ASSIGN_OR_RETURN(YellowstoneClient client2, server->CreateClient());
check(SpawnProcess(gBootVictoriaFallsVmmoCap, client2.Capability())); check(SpawnProcess(gBootVictoriaFallsVmmoCap, client2.Capability()));
check(server->WaitVictoriaFallsRegistered()); server->WaitVictoriaFallsRegistered();
dbgln("VFS Available."); dbgln("VFS Available.");

View File

@ -34,21 +34,12 @@ glcr::ErrorOr<glcr::UniquePtr<YellowstoneServer>> YellowstoneServer::Create() {
z_cap_t endpoint_cap; z_cap_t endpoint_cap;
RET_ERR(ZEndpointCreate(&endpoint_cap)); RET_ERR(ZEndpointCreate(&endpoint_cap));
ASSIGN_OR_RETURN(Mutex denali_mut, Mutex::Create()); return glcr::UniquePtr<YellowstoneServer>(
RET_ERR(denali_mut.Lock()); new YellowstoneServer(endpoint_cap));
ASSIGN_OR_RETURN(Mutex victoriafalls_mut, Mutex::Create());
RET_ERR(victoriafalls_mut.Lock());
return glcr::UniquePtr<YellowstoneServer>(new YellowstoneServer(
endpoint_cap, glcr::Move(denali_mut), glcr::Move(victoriafalls_mut)));
} }
YellowstoneServer::YellowstoneServer(z_cap_t endpoint_cap, Mutex&& denali_mutex, YellowstoneServer::YellowstoneServer(z_cap_t endpoint_cap)
Mutex&& victoriafalls_mutex) : YellowstoneServerBase(endpoint_cap) {}
: YellowstoneServerBase(endpoint_cap),
has_denali_mutex_(glcr::Move(denali_mutex)),
has_victoriafalls_mutex_(glcr::Move(victoriafalls_mutex)) {}
glcr::ErrorCode YellowstoneServer::HandleGetAhciInfo(const Empty&, glcr::ErrorCode YellowstoneServer::HandleGetAhciInfo(const Empty&,
AhciInfo& info) { AhciInfo& info) {
@ -105,12 +96,12 @@ glcr::ErrorCode YellowstoneServer::HandleRegisterEndpoint(
device_id_ = part_info_or.value().device_id; device_id_ = part_info_or.value().device_id;
lba_offset_ = part_info_or.value().partition_lba; lba_offset_ = part_info_or.value().partition_lba;
check(has_denali_mutex_.Release()); has_denali_semaphore_.Signal();
} else if (req.endpoint_name() == "victoriafalls") { } else if (req.endpoint_name() == "victoriafalls") {
// FIXME: Probably make a separate copy for use within yellowstone vs // FIXME: Probably make a separate copy for use within yellowstone vs
// transmit to other processes. // transmit to other processes.
vfs_client_ = glcr::MakeShared<VFSClient>(req.endpoint_capability()); vfs_client_ = glcr::MakeShared<VFSClient>(req.endpoint_capability());
check(has_victoriafalls_mutex_.Release()); has_victoriafalls_semaphore_.Signal();
} else { } else {
dbgln("[WARN] Got endpoint cap type: {}", req.endpoint_name().cstr()); dbgln("[WARN] Got endpoint cap type: {}", req.endpoint_name().cstr());
} }
@ -129,14 +120,10 @@ glcr::ErrorCode YellowstoneServer::HandleGetEndpoint(
return glcr::OK; return glcr::OK;
} }
glcr::ErrorCode YellowstoneServer::WaitDenaliRegistered() { void YellowstoneServer::WaitDenaliRegistered() { has_denali_semaphore_.Wait(); }
RET_ERR(has_denali_mutex_.Lock());
return has_denali_mutex_.Release();
}
glcr::ErrorCode YellowstoneServer::WaitVictoriaFallsRegistered() { void YellowstoneServer::WaitVictoriaFallsRegistered() {
RET_ERR(has_victoriafalls_mutex_.Lock()); has_victoriafalls_semaphore_.Wait();
return has_victoriafalls_mutex_.Release();
} }
glcr::SharedPtr<VFSClient> YellowstoneServer::GetVFSClient() { glcr::SharedPtr<VFSClient> YellowstoneServer::GetVFSClient() {

View File

@ -5,8 +5,8 @@
#include <glacier/memory/unique_ptr.h> #include <glacier/memory/unique_ptr.h>
#include <glacier/status/error_or.h> #include <glacier/status/error_or.h>
#include <mammoth/endpoint_server.h> #include <mammoth/endpoint_server.h>
#include <mammoth/mutex.h>
#include <mammoth/port_server.h> #include <mammoth/port_server.h>
#include <mammoth/semaphore.h>
#include <mammoth/thread.h> #include <mammoth/thread.h>
#include <victoriafalls/victoriafalls.yunq.client.h> #include <victoriafalls/victoriafalls.yunq.client.h>
@ -26,8 +26,8 @@ class YellowstoneServer : public YellowstoneServerBase {
glcr::ErrorCode HandleGetEndpoint(const GetEndpointRequest&, glcr::ErrorCode HandleGetEndpoint(const GetEndpointRequest&,
Endpoint&) override; Endpoint&) override;
glcr::ErrorCode WaitDenaliRegistered(); void WaitDenaliRegistered();
glcr::ErrorCode WaitVictoriaFallsRegistered(); void WaitVictoriaFallsRegistered();
glcr::SharedPtr<VFSClient> GetVFSClient(); glcr::SharedPtr<VFSClient> GetVFSClient();
@ -40,9 +40,8 @@ class YellowstoneServer : public YellowstoneServerBase {
PciReader pci_reader_; PciReader pci_reader_;
Mutex has_denali_mutex_; Semaphore has_denali_semaphore_;
Mutex has_victoriafalls_mutex_; Semaphore has_victoriafalls_semaphore_;
YellowstoneServer(z_cap_t endpoint_cap, Mutex&& denali_mutex, YellowstoneServer(z_cap_t endpoint_cap);
Mutex&& victoriafalls_mutex);
}; };