[Pcsclite-cvs-commit] r4801 - /trunk/PCSC/src/winscard_svc.c

rousseau at users.alioth.debian.org rousseau at users.alioth.debian.org
Tue Mar 9 08:51:22 UTC 2010


Author: rousseau
Date: Tue Mar  9 08:51:22 2010
New Revision: 4801

URL: http://svn.debian.org/wsvn/pcsclite/?sc=1&rev=4801
Log:
manipulations of contextsList should now be thread safe

Modified:
    trunk/PCSC/src/winscard_svc.c

Modified: trunk/PCSC/src/winscard_svc.c
URL: http://svn.debian.org/wsvn/pcsclite/trunk/PCSC/src/winscard_svc.c?rev=4801&op=diff
==============================================================================
--- trunk/PCSC/src/winscard_svc.c (original)
+++ trunk/PCSC/src/winscard_svc.c Tue Mar  9 08:51:22 2010
@@ -52,8 +52,8 @@
 static int contextMaxThreadCounter = PCSC_MAX_CONTEXT_THREADS;
 static int contextMaxCardHandles = PCSC_MAX_CONTEXT_CARD_HANDLES;
 
-/* Context tracking list */
-static list_t contextsList;
+static list_t contextsList;	/**< Context tracking list */
+PCSCLITE_MUTEX contextsList_lock;	/**< lock for the above list */
 
 struct _psContext
 {
@@ -112,6 +112,8 @@
 		Log2(PCSC_LOG_CRITICAL, "list_attributes_seeker failed with return value: %X", lrv);
 		return -1;
 	}
+
+	(void)SYS_MutexInit(&contextsList_lock);
 
 	return 1;
 }
@@ -184,7 +186,9 @@
 		goto error;
 	}
 
+	(void)SYS_MutexLock(&contextsList_lock);
 	lrv = list_append(&contextsList, newContext);
+	(void)SYS_MutexUnLock(&contextsList_lock);
 	if (lrv < 0)
 	{
 		Log2(PCSC_LOG_CRITICAL, "list_append failed with return value: %X", lrv);
@@ -199,7 +203,9 @@
 		int lrv2;
 
 		Log2(PCSC_LOG_CRITICAL, "SYS_ThreadCreate failed: %s", strerror(rv));
+		(void)SYS_MutexLock(&contextsList_lock);
 		lrv2 = list_delete(&contextsList, newContext);
+		(void)SYS_MutexUnLock(&contextsList_lock);
 		if (lrv2 < 0)
 			Log2(PCSC_LOG_CRITICAL, "list_delete failed with error %X", lrv2);
 		list_destroy(&(newContext->cardsList));
@@ -522,8 +528,10 @@
 				READ_BODY(caStr)
 
 				/* find the client */
+				(void)SYS_MutexLock(&contextsList_lock);
 				psTargetContext = (SCONTEXT *) list_seek(&contextsList,
 					&(caStr.hContext));
+				(void)SYS_MutexUnLock(&contextsList_lock);
 				if (psTargetContext != NULL)
 				{
 					uint32_t fd = psTargetContext->dwClientID;
@@ -926,7 +934,9 @@
 	memset((void*) threadContext, 0, sizeof(SCONTEXT));
 	Log2(PCSC_LOG_DEBUG, "Freeing SCONTEXT @%X", threadContext);
 
+	(void)SYS_MutexLock(&contextsList_lock);
 	lrv = list_delete(&contextsList, threadContext);
+	(void)SYS_MutexUnLock(&contextsList_lock);
 	if (lrv < 0)
 		Log2(PCSC_LOG_CRITICAL, "list_delete failed with error %x", lrv);
 




More information about the Pcsclite-cvs-commit mailing list