[Pcsclite-cvs-commit] r5415 - in /trunk/PCSC/src: eventhandler.c readerfactory.c readerfactory.h winscard.c
rousseau at users.alioth.debian.org
rousseau at users.alioth.debian.org
Tue Nov 23 08:30:15 UTC 2010
Author: rousseau
Date: Tue Nov 23 08:30:14 2010
New Revision: 5415
URL: http://svn.debian.org/wsvn/pcsclite/?sc=1&rev=5415
Log:
Add a mutex to make the test and set of the powerState field atomic.
Modified:
trunk/PCSC/src/eventhandler.c
trunk/PCSC/src/readerfactory.c
trunk/PCSC/src/readerfactory.h
trunk/PCSC/src/winscard.c
Modified: trunk/PCSC/src/eventhandler.c
URL: http://svn.debian.org/wsvn/pcsclite/trunk/PCSC/src/eventhandler.c?rev=5415&op=diff
==============================================================================
--- trunk/PCSC/src/eventhandler.c (original)
+++ trunk/PCSC/src/eventhandler.c Tue Nov 23 08:30:14 2010
@@ -440,6 +440,7 @@
#ifndef DISABLE_ON_DEMAND_POWER_ON
/* the card is powered but not used */
+ (void)pthread_mutex_lock(&rContext->powerState_lock);
if (POWER_STATE_POWERED == rContext->powerState)
{
/* power down */
@@ -459,6 +460,7 @@
rContext->powerState = POWER_STATE_POWERED;
Log1(PCSC_LOG_DEBUG, "powerState: POWER_STATE_POWERED");
}
+ (void)pthread_mutex_unlock(&rContext->powerState_lock);
#endif
if (rContext->hLockId == 0xFFFF)
Modified: trunk/PCSC/src/readerfactory.c
URL: http://svn.debian.org/wsvn/pcsclite/trunk/PCSC/src/readerfactory.c?rev=5415&op=diff
==============================================================================
--- trunk/PCSC/src/readerfactory.c (original)
+++ trunk/PCSC/src/readerfactory.c Tue Nov 23 08:30:14 2010
@@ -207,6 +207,10 @@
(void)pthread_mutex_init(&sReadersContexts[dwContext]->handlesList_lock,
NULL);
+
+ (void)pthread_mutex_init(&sReadersContexts[dwContext]->powerState_lock,
+ NULL);
+ sReadersContexts[dwContext]->powerState = POWER_STATE_UNPOWERED;
/* If a clone to this reader exists take some values from that clone */
if (parentNode >= 0 && parentNode < PCSCLITE_MAX_READERS_CONTEXTS)
@@ -398,6 +402,9 @@
}
(void)pthread_mutex_init(&sReadersContexts[dwContextB]->handlesList_lock, NULL);
+ (void)pthread_mutex_init(&sReadersContexts[dwContextB]->powerState_lock,
+ NULL);
+ sReadersContexts[dwContextB]->powerState = POWER_STATE_UNPOWERED;
/* Call on the parent driver to see if the slots are thread safe */
dwGetSize = sizeof(ucThread);
Modified: trunk/PCSC/src/readerfactory.h
URL: http://svn.debian.org/wsvn/pcsclite/trunk/PCSC/src/readerfactory.h?rev=5415&op=diff
==============================================================================
--- trunk/PCSC/src/readerfactory.h (original)
+++ trunk/PCSC/src/readerfactory.h Tue Nov 23 08:30:14 2010
@@ -114,6 +114,7 @@
int * pFeeds; /**< Number of shared client to lib */
int * pMutex; /**< Number of client to mutex */
int powerState; /**< auto power off state */
+ pthread_mutex_t powerState_lock; /**< powerState mutex */
struct pubReaderStatesList *readerState; /**< link to the reader state */
/* we can't use READER_CONTEXT * here since eventhandler.h can't be
Modified: trunk/PCSC/src/winscard.c
URL: http://svn.debian.org/wsvn/pcsclite/trunk/PCSC/src/winscard.c?rev=5415&op=diff
==============================================================================
--- trunk/PCSC/src/winscard.c (original)
+++ trunk/PCSC/src/winscard.c Tue Nov 23 08:30:14 2010
@@ -292,6 +292,7 @@
}
/* Power on (again) the card if needed */
+ (void)pthread_mutex_lock(&rContext->powerState_lock);
if (POWER_STATE_UNPOWERED == rContext->powerState)
{
DWORD dwAtrLen;
@@ -318,12 +319,14 @@
if (! (readerState & SCARD_POWERED))
{
Log1(PCSC_LOG_ERROR, "Card Not Powered");
+ (void)pthread_mutex_unlock(&rContext->powerState_lock);
return SCARD_W_UNPOWERED_CARD;
}
/* the card is now in use */
rContext->powerState = POWER_STATE_INUSE;
Log1(PCSC_LOG_DEBUG, "powerState: POWER_STATE_INUSE");
+ (void)pthread_mutex_unlock(&rContext->powerState_lock);
}
/*******************************************
@@ -959,6 +962,7 @@
RESPONSECODE (*fct)(DWORD) = NULL;
DWORD dwGetSize;
+ (void)pthread_mutex_lock(&rContext->powerState_lock);
if (POWER_STATE_INUSE == rContext->powerState)
{
#ifdef DISABLE_AUTO_POWER_ON
@@ -972,6 +976,7 @@
Log1(PCSC_LOG_DEBUG, "powerState: POWER_STATE_GRACE_PERIOD");
#endif
}
+ (void)pthread_mutex_unlock(&rContext->powerState_lock);
/* ask to stop the "polling" thread so it can be restarted using
* the correct timeout */
More information about the Pcsclite-cvs-commit
mailing list