Expand thread affinity support

Details on usage are in the docs.  This diff is mostly a fairly
simple refactor of the affinity setting routines and some parsing
of configuration parameters.