I would make this a `while (1)` loop. The double checking of the condition (whether to call sleep) is odd.