Best pattern for WFI (wait-for-interrupt) on Cortex (ARM) microcontrolers
Put it inside a critical section.  ISRs won't run, so you don't run the risk of dont_sleep changing before WFI, but they will still wake the processor and the ISRs will execute as soon as the critical section ends.

uint8 interruptStatus;
interruptStatus = EnterCriticalSection();
if (!dont_sleep)
  WFI();
ExitCriticalSection(interruptStatus);


Your development environment probably has critical section functions, but it's roughly like this:

EnterCriticalSection is:

MRS r0, PRIMASK /* Save interrupt state. */
CPSID i /* Turn off interrupts. */
BX lr /* Return. */


ExitCriticalSection is:

MSR PRIMASK, r0 /* Restore interrupt states. */
BX lr /* Return. */