Code cleanup
Use atomic-primops for Counter
Switch timeout handling to atomic-primops

This is more experimental than the previous commit. Benchmarking is
necessary to see if the less readable code here is worth it.