Change spinlock implementation, add fallbacks and move to threading.h.