Atomic sections via masking global interrupts

Hi
Thanks for the detailed write-up.

Adding px4::critical as a generic abstraction makes sense.

px4::atomic is used from IRQ handlers. The only case where enter_critical_section is needed (as it’s not lock-free), is for drivers setting a 64bit timestamp from an IRQ handler. So it should be enough to change the defines to:

#if defined(__PX4_NUTTX) && (defined (__KERNEL__) || defined(CONFIG_BUILD_FLAT))

Then in user-space, GCC will automatically add the locking for non-lock-free calls to __atomic_* (we could still handle that explicitly if we want to).