[Pcsclite-cvs-commit] r6358 - /trunk/PCSC/src/winscard_clnt.c

rousseau at users.alioth.debian.org rousseau at users.alioth.debian.org
Tue Jun 26 13:29:54 UTC 2012


Author: rousseau
Date: Tue Jun 26 13:29:53 2012
New Revision: 6358

URL: http://svn.debian.org/wsvn/pcsclite/?sc=1&rev=6358
Log:
SCardTransmit(): do not hold the mutex when waiting in a
SCARD_E_SHARING_VIOLATION loop

If SCardTransmit() is waiting because the reader is used by another
thread/process then we release the currentContextMap->mMutex, sleep, and
try to acquire the mutex again.
This will allow another thread using the same hContext to call
SCardEndTransaction() otherwise the mutex is already held by
SCardTransmit() and SCardEndTransaction() can't get it to finish the
transaction => dead lock

Thanks to Aleksey Samsonov for the patch
http://archives.neohapsis.com/archives/dev/muscle/2012-q2/0109.html

Modified:
    trunk/PCSC/src/winscard_clnt.c

Modified: trunk/PCSC/src/winscard_clnt.c
URL: http://svn.debian.org/wsvn/pcsclite/trunk/PCSC/src/winscard_clnt.c?rev=6358&op=diff
==============================================================================
--- trunk/PCSC/src/winscard_clnt.c (original)
+++ trunk/PCSC/src/winscard_clnt.c Tue Jun 26 13:29:53 2012
@@ -2719,6 +2719,9 @@
 		return SCARD_E_INVALID_HANDLE;
 	}
 
+	/* Retry loop for blocking behaviour */
+retry:
+
 	(void)pthread_mutex_lock(currentContextMap->mMutex);
 
 	/* check the handle is still valid */
@@ -2737,9 +2740,6 @@
 		goto end;
 	}
 
-	/* Retry loop for blocking behaviour */
-retry:
-
 	scTransmitStruct.hCard = hCard;
 	scTransmitStruct.cbSendLength = cbSendLength;
 	scTransmitStruct.pcbRecvLength = *pcbRecvLength;
@@ -2800,6 +2800,7 @@
 
 	if (sharing_shall_block && (SCARD_E_SHARING_VIOLATION == rv))
 	{
+		(void)pthread_mutex_unlock(currentContextMap->mMutex);
 		(void)SYS_USleep(PCSCLITE_LOCK_POLL_RATE);
 		goto retry;
 	}




More information about the Pcsclite-cvs-commit mailing list