Add RWCollection, a read-write locked collection with a mostly safe API
The codebase is badly lacking a read-write collection utility that promotes proper use through its API.
RWCollection cannot be manipulated directly, but through views that also hold a lock. It is possible to have several read views at once, but the collection can only be read from using them. It is possible to only hold one write view at once, and the collection can be modified using it.
Added unit tests for the new code.
Reviewers: #bitcoin_abc, schancel
Reviewed By: #bitcoin_abc, schancel
Subscribers: schancel, Fabien, teamcity
Differential Revision: https://reviews.bitcoinabc.org/D2005