Changed to use p_nextlock instead of p_nextwaiting.