Make the headers C++ compatible.

The is frustrated because libgcc's stdatomic.h (as of 4.9) does not
support C++ so we have to put in a hack to keep some the code that
uses atomics working correctly.

Signed-off-by: Daniel Thompson <daniel@redfelineninja.org.uk>