[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());
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.");

View File

@ -34,21 +34,12 @@ glcr::ErrorOr<glcr::UniquePtr<YellowstoneServer>> 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<YellowstoneServer>(new YellowstoneServer(
endpoint_cap, glcr::Move(denali_mut), glcr::Move(victoriafalls_mut)));
return glcr::UniquePtr<YellowstoneServer>(
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<VFSClient>(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<VFSClient> YellowstoneServer::GetVFSClient() {

View File

@ -5,8 +5,8 @@
#include <glacier/memory/unique_ptr.h>
#include <glacier/status/error_or.h>
#include <mammoth/endpoint_server.h>
#include <mammoth/mutex.h>
#include <mammoth/port_server.h>
#include <mammoth/semaphore.h>
#include <mammoth/thread.h>
#include <victoriafalls/victoriafalls.yunq.client.h>
@ -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<VFSClient> 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);
};