Change atomics to be templated functions and fix other compile errors.