kernel/eka/kernel/sexec.cpp
changeset 177 a232af6b0b1f
parent 134 95847726fe57
child 245 647ab20fee2e
--- a/kernel/eka/kernel/sexec.cpp	Wed Jun 23 12:52:28 2010 +0100
+++ b/kernel/eka/kernel/sexec.cpp	Wed Jun 23 12:58:21 2010 +0100
@@ -96,14 +96,26 @@
 	return aChunk->Top();
 	}
 
-void ExecHandler::MutexWait(DMutex* aMutex)
+TInt ExecHandler::MutexWait(DMutex* aMutex, TInt aTimeout)
 //
 // Wait for the mutex.
 //
 	{
-
-//	__KTRACE_OPT(KEXEC,Kern::Printf("Exec::MutexWait"));
-	aMutex->Wait();
+	if (aTimeout)	// 0 means wait forever, -1 means poll
+		{
+		if (aTimeout<-1)
+			{
+			return KErrArgument;
+			}
+		if (aTimeout>0)
+			{
+			// Convert microseconds to NTimer ticks, rounding up
+			TInt ntp = NKern::TickPeriod();
+			aTimeout += ntp-1;
+			aTimeout /= ntp;
+			}
+		}
+	return aMutex->Wait(aTimeout);
 	}
 
 void ExecHandler::MutexSignal(DMutex* aMutex)
@@ -555,20 +567,21 @@
 // Wait for a signal.
 //
 	{
-
 	__KTRACE_OPT(KEXEC,Kern::Printf("Exec::SemaphoreWait"));
-	if (aTimeout)
+	if (aTimeout)	// 0 means wait forever, -1 means poll
 		{
-		if (aTimeout<0)
+		if (aTimeout<-1)
 			{
 			NKern::UnlockSystem();
 			return KErrArgument;
 			}
-
-		// Convert microseconds to NTimer ticks, rounding up
-		TInt ntp = NKern::TickPeriod();
-		aTimeout += ntp-1;
-		aTimeout /= ntp;
+		if (aTimeout>0)
+			{
+			// Convert microseconds to NTimer ticks, rounding up
+			TInt ntp = NKern::TickPeriod();
+			aTimeout += ntp-1;
+			aTimeout /= ntp;
+			}
 		}
 	return aSemaphore->Wait(aTimeout);
 	}