Twice I've tried using epoch and managed to forget that in_epoch() only operates on preemptible epochs, so here's a first cut at rectifying this.
For default epochs, it's easy enough to verify that we're in the given epoch (AFAICT): if we're in a critical section and our record for the given epoch is active, then we're in it.
This patch also adds some additional INVARIANTS bookkeeping. Notably, we set and check the recorded thread in epoch_enter/epoch_exit to try and catch some edge-cases for the caller. It also checks upon freeing that none of the records had a thread in the the epoch, which may make it a little easier to diagnose some improper use if epoch_free() took place while some other thread was inside.