First 2 commits avoid unlock/lock mempool.cs and cs_main interchangeably by turning a loop in two loops - each mutex is locked throughout each corresponding loop.
Then explicit lock in CTxMemPool::RemoveUnbroadcastTx, CTxMemPool::GetUnbroadcastTxs and CTxMemPool::exists is removed forcing just 3 explicit WITH_LOCK where exists() is called and just 1 where GetUnbroadcastTxs() is called. This can be improved by adding an auxiliary function that locks and calls the original.