diff options
author | gordon%netscape.com <devnull@localhost> | 2001-03-13 06:58:48 +0000 |
---|---|---|
committer | gordon%netscape.com <devnull@localhost> | 2001-03-13 06:58:48 +0000 |
commit | 8155f49882424611ddbbe3cd5298f6f9f4b5e2f5 (patch) | |
tree | e26b998b3bd5f65c32e51c62dc27aa6bdb43cb0a | |
parent | 78657cc7baa01da69195632473b39a56c0f79ae5 (diff) | |
download | nspr-hg-8155f49882424611ddbbe3cd5298f6f9f4b5e2f5.tar.gz |
fix for bug 29338 "PR_Poll should not poll (spin) on Mac". Checking in for sfraser. r=dougt, gordon, sdagley sr=sfraser or vice versa.
-rw-r--r-- | pr/include/md/_macos.h | 1 | ||||
-rw-r--r-- | pr/src/md/mac/macsockotpt.c | 23 |
2 files changed, 17 insertions, 7 deletions
diff --git a/pr/include/md/_macos.h b/pr/include/md/_macos.h index bcbca3c4..43318527 100644 --- a/pr/include/md/_macos.h +++ b/pr/include/md/_macos.h @@ -103,6 +103,7 @@ struct _MDFileDesc { _MDSocketCallerInfo misc; _MDSocketCallerInfo read; _MDSocketCallerInfo write; + _MDSocketCallerInfo poll; }; /* diff --git a/pr/src/md/mac/macsockotpt.c b/pr/src/md/mac/macsockotpt.c index 08191884..b42e176d 100644 --- a/pr/src/md/mac/macsockotpt.c +++ b/pr/src/md/mac/macsockotpt.c @@ -292,6 +292,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; @@ -452,7 +453,11 @@ static pascal void NotifierRoutine(void * contextPtr, OTEventCode code, OTResul return; } + if (pollThread) + WakeUpNotifiedThread(pollThread, kOTNoError); + else WakeUpNotifiedThread(thread, result); + } @@ -1658,8 +1663,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); @@ -1680,14 +1687,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 { @@ -1724,6 +1728,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) @@ -1757,7 +1763,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)); |