configure: Express atomics/thread deps through the dependency system
atomics: cosmetics: Restructure ifdefs for greater clarity

Also fix the #endif comment in a few places and #include config.h to
avoid assuming it is #included implicitly.