Rework the mempool locking code.

It was previously possible for the unprotected iteration of the mempool
orphans to lead to undefined results.  This commit remedies that by
reworking the locking code a bit.  It also embeds the mutex directly into
the mempool struct rather than having a separate field for it so the
syntax is a slightly cleaner.