Relocate locking to the object that owns the queue.  This way, we block push/pop threads for a minimal amount of time, so writing out the file is less likely to interfere with network capture.

Also a bit of cleanup.