This is simply a cleanup of D18482 (patch taken with permission) while adapting it to match what we have already implemented for libcxx.
Note that I haven't included the external-threading stuff yet, this is only refactoring pthread usage of libcxxabi. A follow-up patch will add the external-threading support.
Does this configuration need to be in a public header if it's only used internally? I think config.h or threading_support.h would be a better place for this to live.