Skip to content

Commit

Permalink
SM: Check if service already exists before creating port
Browse files Browse the repository at this point in the history
  • Loading branch information
roblabla committed Aug 12, 2019
1 parent 19807bd commit 306d95b
Showing 1 changed file with 19 additions and 12 deletions.
31 changes: 19 additions & 12 deletions sm/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,21 +177,28 @@ impl IUserInterfaceAsync for UserInterface {
/// registered service.
fn register_service(&mut self, _work_queue: WorkQueue<'static>, servicename: u64, is_light: bool, max_handles: u32) -> FutureObj<'_, Result<ServerPort, Error>> {
let servicename = ServiceName(servicename);
let (clientport, serverport) = match syscalls::create_port(max_handles, is_light, &servicename.0.to_ne_bytes()) {
Ok(v) => v,
Err(err) => return FutureObj::new(Box::new(futures::future::err(err.into())))

let serverport = {
let mut services_lock = SERVICES.lock();
let entry = match services_lock.entry(servicename) {
Entry::Occupied(_) => return FutureObj::new(Box::new(futures::future::err(SmError::ServiceAlreadyRegistered.into()))),
Entry::Vacant(vacant) => vacant,
};

let (clientport, serverport) = match syscalls::create_port(max_handles, is_light, &servicename.0.to_ne_bytes()) {
Ok(v) => v,
Err(err) => return FutureObj::new(Box::new(futures::future::err(err.into())))
};

entry.insert(clientport);

serverport
};
match SERVICES.lock().entry(servicename) {
Entry::Occupied(_) => FutureObj::new(Box::new(futures::future::err(SmError::ServiceAlreadyRegistered.into()))),
Entry::Vacant(vacant) => {
vacant.insert(clientport);

// Wake up potential get_service.
SERVICES_EVENT.0.signal().unwrap();
// Wake up potential get_service.
SERVICES_EVENT.0.signal().unwrap();

FutureObj::new(Box::new(futures::future::ok(serverport)))
}
}
FutureObj::new(Box::new(futures::future::ok(serverport)))
}

/// Unregister a service.
Expand Down

0 comments on commit 306d95b

Please # to comment.