[Pcsclite-git-commit] [CCID] 01/02: ifdhandler: only GetNewReaderIndex() has to be thread protected

Ludovic Rousseau rousseau at moszumanska.debian.org
Wed Jan 4 12:46:06 UTC 2017


This is an automated email from the git hooks/post-receive script.

rousseau pushed a commit to branch master
in repository CCID.

commit d1a15209f818b5de139d691841e56613bbca9727
Author: Ludovic Rousseau <ludovic.rousseau at free.fr>
Date:   Wed Jan 4 13:34:41 2017 +0100

    ifdhandler: only GetNewReaderIndex() has to be thread protected
    
    Once a new reader_index has been attribuyed the functions are thread
    safe. Only the call to GetNewReaderIndex() need to be protected.
    
    The mutex was introduced in 8c6ed32fa1649a3648eb768d7c692e0e1e67f2ed
    "add support of thread safe (APDU multiplexing on different readers)" in
    September 2003 and, at that time, GetNewReaderIndex() was not yet used
    or implemented.
---
 src/ifdhandler.c | 20 +++++++++++---------
 1 file changed, 11 insertions(+), 9 deletions(-)

diff --git a/src/ifdhandler.c b/src/ifdhandler.c
index 991e6b0..d97bd37 100644
--- a/src/ifdhandler.c
+++ b/src/ifdhandler.c
@@ -114,7 +114,17 @@ static RESPONSECODE CreateChannelByNameOrChannel(DWORD Lun,
 		DEBUG_INFO3("Lun: " DWORD_X ", Channel: " DWORD_X, Lun, Channel);
 	}
 
-	if (-1 == (reader_index = GetNewReaderIndex(Lun)))
+#ifdef HAVE_PTHREAD
+	(void)pthread_mutex_lock(&ifdh_context_mutex);
+#endif
+
+	reader_index = GetNewReaderIndex(Lun);
+
+#ifdef HAVE_PTHREAD
+	(void)pthread_mutex_unlock(&ifdh_context_mutex);
+#endif
+
+	if (-1 == reader_index)
 		return IFD_COMMUNICATION_ERROR;
 
 	/* Reset ATR buffer */
@@ -130,10 +140,6 @@ static RESPONSECODE CreateChannelByNameOrChannel(DWORD Lun,
 	else
 		CcidSlots[reader_index].readerName = strdup("no name");
 
-#ifdef HAVE_PTHREAD
-	(void)pthread_mutex_lock(&ifdh_context_mutex);
-#endif
-
 	if (lpcDevice)
 		ret = OpenPortByName(reader_index, lpcDevice);
 	else
@@ -203,10 +209,6 @@ static RESPONSECODE CreateChannelByNameOrChannel(DWORD Lun,
 	}
 
 error:
-#ifdef HAVE_PTHREAD
-	(void)pthread_mutex_unlock(&ifdh_context_mutex);
-#endif
-
 	if (return_value != IFD_SUCCESS)
 	{
 		/* release the allocated resources */

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pcsclite/CCID.git



More information about the Pcsclite-cvs-commit mailing list