I believe the logic after this point is for the case when the queue either empty or is about to become empty. If it is empty, it just returns None, if there is a single item in the queue, it pushes the stub node that represents an empty queue so head is the stub node and then checks again to see if next is empty (another thread might have added something to the queue).