Thread-safety / signal-safety fixups

See subject.  The only commit I'm not really sure about is the last one (fa4a97d).  Let me know if you want to see anything reworked.