Fix bug 29338 "PR_Poll should not poll (spin) on Mac". Checking in for sfraser. r=dougt, sdagley, gordon, sr=sfraser, or vice versa.

This commit is contained in:
gordon%netscape.com 2001-03-13 07:02:53 +00:00
Родитель 29a0f4877d
Коммит 28a5bd7c67
2 изменённых файлов: 17 добавлений и 7 удалений

Просмотреть файл

@ -124,6 +124,7 @@ struct _MDFileDesc {
_MDSocketCallerInfo misc;
_MDSocketCallerInfo read;
_MDSocketCallerInfo write;
_MDSocketCallerInfo poll;
};
/*

Просмотреть файл

@ -308,6 +308,7 @@ static pascal void NotifierRoutine(void * contextPtr, OTEventCode code, OTResul
_MDFileDesc * md = &(secret->md);
EndpointRef endpoint = (EndpointRef)secret->md.osfd;
PRThread * thread = NULL;
PRThread * pollThread = md->poll.thread;
OSStatus err;
OTResult resultOT;
TDiscon discon;
@ -468,7 +469,11 @@ static pascal void NotifierRoutine(void * contextPtr, OTEventCode code, OTResul
return;
}
if (pollThread)
WakeUpNotifiedThread(pollThread, kOTNoError);
else
WakeUpNotifiedThread(thread, result);
}
@ -1675,8 +1680,10 @@ PRInt32 _MD_writev(PRFileDesc *fd, const struct PRIOVec *iov, PRInt32 iov_size,
static PRBool GetState(PRFileDesc *fd, PRBool *readReady, PRBool *writeReady, PRBool *exceptReady)
{
OTResult resultOT;
size_t availableData;
*readReady = fd->secret->md.readReady;
resultOT = OTCountDataBytes((EndpointRef)fd->secret->md.osfd, &availableData);
*readReady = fd->secret->md.readReady && (availableData > 0);
*exceptReady = fd->secret->md.exceptReady;
resultOT = OTGetEndpointState((EndpointRef)fd->secret->md.osfd);
@ -1697,14 +1704,11 @@ PRInt32 _MD_poll(PRPollDesc *pds, PRIntn npds, PRIntervalTime timeout)
{
PRInt32 ready = 0;
PRPollDesc *pd, *epd;
PRIntervalTime sleepTime, timein;
PRThread *thread = _PR_MD_CURRENT_THREAD();
PRIntervalTime timein;
sleepTime = PR_MillisecondsToInterval(5UL);
if (PR_INTERVAL_NO_TIMEOUT != timeout)
{
if (sleepTime > timeout) sleepTime = timeout;
timein = PR_IntervalNow();
}
do
{
@ -1741,6 +1745,8 @@ PRInt32 _MD_poll(PRPollDesc *pds, PRIntn npds, PRIntervalTime timeout)
PR_ASSERT(NULL != bottomFD);
if ((NULL != bottomFD) && (_PR_FILEDESC_OPEN == bottomFD->secret->state))
{
bottomFD->secret->md.poll.thread = thread;
if (GetState(bottomFD, &readReady, &writeReady, &exceptReady))
{
if (readReady)
@ -1774,7 +1780,10 @@ PRInt32 _MD_poll(PRPollDesc *pds, PRIntn npds, PRIntervalTime timeout)
if (ready > 0) return ready;
(void) PR_Sleep(sleepTime);
thread->io_pending = PR_TRUE;
thread->io_fd = NULL;
thread->md.osErrCode = noErr;
WaitOnThisThread(thread, timeout);
} while ((timeout == PR_INTERVAL_NO_TIMEOUT) ||
(((PRIntervalTime)(PR_IntervalNow() - timein)) < timeout));