From f86eb18a6e3a10ecb96497f0d2be91fb231e7520 Mon Sep 17 00:00:00 2001 From: Yeastplume Date: Sat, 28 Sep 2019 17:24:40 +0100 Subject: [PATCH] Change tui tx_pool lock to try_read, only lock once (#3063) --- servers/src/grin/server.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/servers/src/grin/server.rs b/servers/src/grin/server.rs index 8e17573582..248ba546a4 100644 --- a/servers/src/grin/server.rs +++ b/servers/src/grin/server.rs @@ -475,9 +475,17 @@ impl Server { .map(|p| PeerStats::from_peer(&p)) .collect(); + let (tx_pool_size, stem_pool_size) = { + let tx_pool_lock = self.tx_pool.try_read(); + match tx_pool_lock { + Some(l) => (l.txpool.entries.len(), l.stempool.entries.len()), + None => (0, 0), + } + }; + let tx_stats = TxStats { - tx_pool_size: self.tx_pool.read().txpool.entries.len(), - stem_pool_size: self.tx_pool.read().stempool.entries.len(), + tx_pool_size, + stem_pool_size, }; let head = self.chain.head_header()?;