Refactored and rolled out more thread safety:

- Macros LOCK, STANDARD_CLEANUP_BLOCK, WILL_RETURN implement it.
- TO use the error condition macros, you must use at least WILL_RETURN.
- See private_macros.h