PrepareForAsyncCompletion(thread, 0);
if (needsToWait) { WaitOnThisThread(thread, timeout);
PRInt32 _MD_poll(PRPollDesc *pds, PRIntn npds, PRIntervalTime timeout){    PRThread    *thread = _PR_MD_CURRENT_THREAD();    intn is;    PRInt32 ready;        if (timeout == PR_INTERVAL_NO_WAIT) {        return CheckPollDescs(pds, npds);    }        _PR_INTSOFF(is);    PR_Lock(thread->md.asyncIOLock);    // ensure that we don't miss the firing of the notifier while checking socket status    // need to set up the thread    PrepareForAsyncCompletion(thread, 0);    SetDescPollThread(pds, npds, thread);    ready = CheckPollDescs(pds, npds);    PR_Unlock(thread->md.asyncIOLock);    _PR_FAST_INTSON(is);    if (ready == 0) {        WaitOnThisThread(thread, timeout);        ready = CheckPollDescs(pds, npds);    } else {        thread->io_pending = PR_FALSE;    }    SetDescPollThread(pds, npds, NULL);    return ready;}