compat: Add stdatomic.h compat header and waf check

Change atomics-using code to include compat/stdatomic.h instead of
directly including stdatomic.h, for compatibity with systems with old
libc and/or compilers.

We include the code from FreeBSD's stdatomic.h, which, due to supporting
both gcc 4.2 and clang, is compatible with the same compilers we already
supported with the old compat/atomics.h.