chiark / gitweb /
impl InstanceGuard::destroy
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Fri, 17 Jul 2020 23:20:03 +0000 (00:20 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Fri, 17 Jul 2020 23:20:03 +0000 (00:20 +0100)
src/global.rs

index c23537c1c60ce65a88c3cb8146d38603e95ebdc8..59b20bdf9bfd5405432583c939aeff111559551f 100644 (file)
@@ -141,6 +141,16 @@ impl InstanceGuard<'_> {
     Id::global_tokens(PRIVATE_Y).write().unwrap().insert(token, iad);
   }
 
+  pub fn destroy(mut self) {
+    Self::forget_all_tokens(&mut self.ig.tokens_players);
+    Self::forget_all_tokens(&mut self.ig.tokens_clients);
+  }
+  fn forget_all_tokens<Id:AccessId>(tokens: &mut TokenRegistry<Id>) {
+    let global : &RwLock<TokenTable<Id>> = AccessId::global_tokens(PRIVATE_Y);
+    let mut global = global.write().unwrap();
+    for t in tokens.tr.drain() { global.remove(&t); }
+  }
+
   #[throws(OE)]
   fn save_game_now(&mut self) { eprintln!("xxx would save!"); }
   #[throws(OE)]