Revamp locks a bit.

* Use custom futex-based lock on Linux (because it's way faster than pthreads).
* Use pthreads for OSX.
Avoid modulo for power of two operands.
Add assertion for #cpus.
Make DQs only use p in powers of two.
Check whether buffers have been enabled successfully.