Here we have a race condition. If this is interrupted just after function entry and the engine thread switches e.g. ON.
Than this function toggles to off even if it should stay on. Any idea to fix this without a mutex? 
Is verifying the state after toggle fine?