Merged with HEAD from 8/18 or so. unlabeled-3.15.8
authorcls%seawood.org
Fri, 20 Aug 1999 16:21:37 +0000
branchunlabeled-3.15.8
changeset 771 019dfdc83a36
parent 652 9b519a6613de
push idunknown
push userunknown
push dateunknown
Merged with HEAD from 8/18 or so.
pr/src/md/mac/macio.c
--- a/pr/src/md/mac/macio.c
+++ b/pr/src/md/mac/macio.c
@@ -222,17 +222,17 @@ PRInt32 ReadWriteProc(PRFileDesc *fd, vo
 	else
 	{
 		static IOCompletionUPP	sCompletionUPP = NULL;
 		
 		/* allocate the callback Universal Procedure Pointer (UPP). This actually allocates
 		   a 32 byte Ptr in the heap, so only do this once
 		*/
 		if (!sCompletionUPP)
-			sCompletionUPP = NewIOCompletionProc((ProcPtr)&AsyncIOCompletion);
+			sCompletionUPP = NewIOCompletionProc((IOCompletionProcPtr)&AsyncIOCompletion);
 			
 		/* grab the thread so we know which one to post to at completion */
 		pbAsync.thread	= me;
 
 		pbAsync.pb.ioParam.ioCompletion	= sCompletionUPP;
 		pbAsync.pb.ioParam.ioResult		= noErr;
 		pbAsync.pb.ioParam.ioRefNum		= refNum;
 		pbAsync.pb.ioParam.ioBuffer		= buf;
@@ -240,23 +240,46 @@ PRInt32 ReadWriteProc(PRFileDesc *fd, vo
 		pbAsync.pb.ioParam.ioPosMode	= fsAtMark;
 		pbAsync.pb.ioParam.ioPosOffset	= 0;
 
 		/* 
 		** Issue the async read call and wait for the io semaphore associated
 		** with this thread.
 		** Don't compute error code from async call. Bug in OS returns a garbage value.
 		*/
-	    me->io_pending = PR_TRUE;
 	    me->io_fd = refNum;
 		me->md.osErrCode = noErr;
 		if (op == READ_ASYNC)
-			(void) PBReadAsync(&pbAsync);
+		{
+			/*
+			**  Skanky optimization so that reads < 2K are actually done synchronously
+			**  to optimize performance on small reads (e.g. registry reads on startup)
+			*/
+			if (bytes > 2048L)
+			{
+	   			me->io_pending = PR_TRUE; /* Only mark thread io pending in async call */
+				(void) PBReadAsync(&pbAsync);
+			}
+			else
+			{
+				(void) PBReadSync(&pbAsync);
+				/*
+				** This is probbaly redundant but want to make sure we indicate the read
+				** is complete so we don't wander off into the Sargasso Sea of Mac
+				** threading
+				*/
+				pbAsync.pb.ioParam.ioResult = 0;
+			}
+		}
 		else
+		{
+			/* writes are currently always async so mark thread io pending */
+	   		me->io_pending = PR_TRUE;
 			(void) PBWriteAsync(&pbAsync);
+		}
 		
 		/* See if the i/o call is still pending before we actually yield */
 		if (pbAsync.pb.ioParam.ioResult == 1)
 			WaitOnThisThread(me, PR_INTERVAL_NO_TIMEOUT);
 	}
 	
 	err = me->md.osErrCode;
 	if (err != noErr)