Waiting-time distributions for queues with dynamic priorities