getblocktemplate: longpolling support (v2)

A bit reworked version of #2834 'getblocktemplate: longpolling support'

- Remove `fRPCRunning` and replace with a function `IsRPCRunning()`
- Remove unnecessary added includes
- Use our own `CWaitableCriticalSection` instead of `boost::mutex`
- Add our own typedef `CConditionVariable` for `boost::condition_variable`

Note: currently untested! I still need to find something to test this with @luke-jr.