getblocktemplate: longpolling support (v2)

A bit reworked version of #2834 'getblocktemplate: longpolling support'. Just a final push in trying to get it merged.

- Remove `fRPCRunning` and replace with a function `IsRPCRunning()`
- Remove unnecessary added includes
- Use our own `CWaitableCriticalSection` instead of `boost::mutex` (amounts to the same, ours is a wrapper)
- Add our own typedef `CConditionVariable` for `boost::condition_variable`
- Make it compile and work in disable-wallet builds, as well as when running in runtime disable-wallet mode

Note: currently untested! I still need to find something to test this with @luke-jr.

This should use mempool.GetTransactionsUpdated() instead of nTransactionsUpdatedLast