[Pcsclite-cvs-commit] r6637 - /trunk/PCSC/src/winscard_clnt.c
rousseau at users.alioth.debian.org
rousseau at users.alioth.debian.org
Mon May 27 13:47:38 UTC 2013
Author: rousseau
Date: Mon May 27 13:47:37 2013
New Revision: 6637
URL: http://svn.debian.org/wsvn/pcsclite/?sc=1&rev=6637
Log:
mMutex is now directly inside the _psContextMap structure and no more a pointer
The mutex was dynamically allocated at runtime using malloc(3) and
referenced using a pointer. This was introduced in revision 572 (Dec
2003) by Damien Sauveron.
Using a direct pthread_mutex_t structure will save memory (one pointer
removed per context), improve performances (one malloc/free removed) and
make the code safer (one malloc failure removed).
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=6637&op=diff
==============================================================================
--- trunk/PCSC/src/winscard_clnt.c (original)
+++ trunk/PCSC/src/winscard_clnt.c Mon May 27 13:47:37 2013
@@ -289,7 +289,7 @@
{
DWORD dwClientID; /**< Client Connection ID */
SCARDCONTEXT hContext; /**< Application Context ID */
- pthread_mutex_t * mMutex; /**< Mutex for this context */
+ pthread_mutex_t mMutex; /**< Mutex for this context */
list_t channelMapList;
char cancellable; /**< We are in a cancellable call */
};
@@ -656,7 +656,7 @@
goto error;
}
- (void)pthread_mutex_lock(currentContextMap->mMutex);
+ (void)pthread_mutex_lock(¤tContextMap->mMutex);
/* check the context is still opened */
currentContextMap = SCardGetContext(hContext);
@@ -690,7 +690,7 @@
rv = scReleaseStruct.rv;
end:
- (void)pthread_mutex_unlock(currentContextMap->mMutex);
+ (void)pthread_mutex_unlock(¤tContextMap->mMutex);
/*
* Remove the local context from the stack
@@ -797,7 +797,7 @@
if (NULL == currentContextMap)
return SCARD_E_INVALID_HANDLE;
- (void)pthread_mutex_lock(currentContextMap->mMutex);
+ (void)pthread_mutex_lock(¤tContextMap->mMutex);
/* check the context is still opened */
currentContextMap = SCardGetContext(hContext);
@@ -845,7 +845,7 @@
rv = scConnectStruct.rv;
end:
- (void)pthread_mutex_unlock(currentContextMap->mMutex);
+ (void)pthread_mutex_unlock(¤tContextMap->mMutex);
PROFILE_END(rv)
API_TRACE_OUT("%d", *pdwActiveProtocol)
@@ -951,7 +951,7 @@
/* Retry loop for blocking behaviour */
retry:
- (void)pthread_mutex_lock(currentContextMap->mMutex);
+ (void)pthread_mutex_lock(¤tContextMap->mMutex);
/* check the handle is still valid */
rv = SCardGetContextAndChannelFromHandle(hCard, ¤tContextMap,
@@ -988,7 +988,7 @@
if (sharing_shall_block && (SCARD_E_SHARING_VIOLATION == rv))
{
- (void)pthread_mutex_unlock(currentContextMap->mMutex);
+ (void)pthread_mutex_unlock(¤tContextMap->mMutex);
(void)SYS_USleep(PCSCLITE_LOCK_POLL_RATE);
goto retry;
}
@@ -996,7 +996,7 @@
*pdwActiveProtocol = scReconnectStruct.dwActiveProtocol;
end:
- (void)pthread_mutex_unlock(currentContextMap->mMutex);
+ (void)pthread_mutex_unlock(¤tContextMap->mMutex);
PROFILE_END(rv)
@@ -1055,7 +1055,7 @@
goto error;
}
- (void)pthread_mutex_lock(currentContextMap->mMutex);
+ (void)pthread_mutex_lock(¤tContextMap->mMutex);
/* check the handle is still valid */
rv = SCardGetContextAndChannelFromHandle(hCard, ¤tContextMap,
@@ -1093,7 +1093,7 @@
rv = scDisconnectStruct.rv;
end:
- (void)pthread_mutex_unlock(currentContextMap->mMutex);
+ (void)pthread_mutex_unlock(¤tContextMap->mMutex);
error:
PROFILE_END(rv)
@@ -1162,7 +1162,7 @@
for(;;)
{
- (void)pthread_mutex_lock(currentContextMap->mMutex);
+ (void)pthread_mutex_lock(¤tContextMap->mMutex);
/* check the handle is still valid */
rv = SCardGetContextAndChannelFromHandle(hCard, ¤tContextMap,
@@ -1197,11 +1197,11 @@
if (SCARD_E_SHARING_VIOLATION != rv)
break;
- (void)pthread_mutex_unlock(currentContextMap->mMutex);
+ (void)pthread_mutex_unlock(¤tContextMap->mMutex);
(void)SYS_USleep(PCSCLITE_LOCK_POLL_RATE);
}
- (void)pthread_mutex_unlock(currentContextMap->mMutex);
+ (void)pthread_mutex_unlock(¤tContextMap->mMutex);
PROFILE_END(rv)
@@ -1266,7 +1266,7 @@
if (rv == -1)
return SCARD_E_INVALID_HANDLE;
- (void)pthread_mutex_lock(currentContextMap->mMutex);
+ (void)pthread_mutex_lock(¤tContextMap->mMutex);
/* check the handle is still valid */
rv = SCardGetContextAndChannelFromHandle(hCard, ¤tContextMap,
@@ -1305,7 +1305,7 @@
rv = scEndStruct.rv;
end:
- (void)pthread_mutex_unlock(currentContextMap->mMutex);
+ (void)pthread_mutex_unlock(¤tContextMap->mMutex);
PROFILE_END(rv)
@@ -1456,7 +1456,7 @@
/* Retry loop for blocking behaviour */
retry:
- (void)pthread_mutex_lock(currentContextMap->mMutex);
+ (void)pthread_mutex_lock(¤tContextMap->mMutex);
/* check the handle is still valid */
rv = SCardGetContextAndChannelFromHandle(hCard, ¤tContextMap,
@@ -1509,7 +1509,7 @@
if (sharing_shall_block && (SCARD_E_SHARING_VIOLATION == rv))
{
- (void)pthread_mutex_unlock(currentContextMap->mMutex);
+ (void)pthread_mutex_unlock(¤tContextMap->mMutex);
(void)SYS_USleep(PCSCLITE_LOCK_POLL_RATE);
goto retry;
}
@@ -1591,7 +1591,7 @@
}
end:
- (void)pthread_mutex_unlock(currentContextMap->mMutex);
+ (void)pthread_mutex_unlock(¤tContextMap->mMutex);
PROFILE_END(rv)
@@ -1759,7 +1759,7 @@
goto error;
}
- (void)pthread_mutex_lock(currentContextMap->mMutex);
+ (void)pthread_mutex_lock(¤tContextMap->mMutex);
/* check the context is still opened */
currentContextMap = SCardGetContext(hContext);
@@ -2184,7 +2184,7 @@
end:
Log1(PCSC_LOG_DEBUG, "Event Loop End");
- (void)pthread_mutex_unlock(currentContextMap->mMutex);
+ (void)pthread_mutex_unlock(¤tContextMap->mMutex);
error:
PROFILE_END(rv)
@@ -2275,7 +2275,7 @@
return SCARD_E_INVALID_HANDLE;
}
- (void)pthread_mutex_lock(currentContextMap->mMutex);
+ (void)pthread_mutex_lock(¤tContextMap->mMutex);
/* check the handle is still valid */
rv = SCardGetContextAndChannelFromHandle(hCard, ¤tContextMap,
@@ -2339,7 +2339,7 @@
rv = scControlStruct.rv;
end:
- (void)pthread_mutex_unlock(currentContextMap->mMutex);
+ (void)pthread_mutex_unlock(¤tContextMap->mMutex);
PROFILE_END(rv)
@@ -2567,7 +2567,7 @@
if (rv == -1)
return SCARD_E_INVALID_HANDLE;
- (void)pthread_mutex_lock(currentContextMap->mMutex);
+ (void)pthread_mutex_lock(¤tContextMap->mMutex);
/* check the handle is still valid */
rv = SCardGetContextAndChannelFromHandle(hCard, ¤tContextMap,
@@ -2628,7 +2628,7 @@
rv = scGetSetStruct.rv;
end:
- (void)pthread_mutex_unlock(currentContextMap->mMutex);
+ (void)pthread_mutex_unlock(¤tContextMap->mMutex);
return rv;
}
@@ -2722,7 +2722,7 @@
/* Retry loop for blocking behaviour */
retry:
- (void)pthread_mutex_lock(currentContextMap->mMutex);
+ (void)pthread_mutex_lock(¤tContextMap->mMutex);
/* check the handle is still valid */
rv = SCardGetContextAndChannelFromHandle(hCard, ¤tContextMap,
@@ -2800,7 +2800,7 @@
if (sharing_shall_block && (SCARD_E_SHARING_VIOLATION == rv))
{
- (void)pthread_mutex_unlock(currentContextMap->mMutex);
+ (void)pthread_mutex_unlock(¤tContextMap->mMutex);
(void)SYS_USleep(PCSCLITE_LOCK_POLL_RATE);
goto retry;
}
@@ -2808,7 +2808,7 @@
*pcbRecvLength = scTransmitStruct.pcbRecvLength;
end:
- (void)pthread_mutex_unlock(currentContextMap->mMutex);
+ (void)pthread_mutex_unlock(¤tContextMap->mMutex);
PROFILE_END(rv)
@@ -2894,7 +2894,7 @@
return SCARD_E_INVALID_HANDLE;
}
- (void)pthread_mutex_lock(currentContextMap->mMutex);
+ (void)pthread_mutex_lock(¤tContextMap->mMutex);
/* check the context is still opened */
currentContextMap = SCardGetContext(hContext);
@@ -2970,7 +2970,7 @@
/* set the reader names length */
*pcchReaders = dwReadersLen;
- (void)pthread_mutex_unlock(currentContextMap->mMutex);
+ (void)pthread_mutex_unlock(¤tContextMap->mMutex);
PROFILE_END(rv)
API_TRACE_OUT("%d", *pcchReaders)
@@ -3083,7 +3083,7 @@
if (NULL == currentContextMap)
return SCARD_E_INVALID_HANDLE;
- (void)pthread_mutex_lock(currentContextMap->mMutex);
+ (void)pthread_mutex_lock(¤tContextMap->mMutex);
/* check the context is still opened */
currentContextMap = SCardGetContext(hContext);
@@ -3125,7 +3125,7 @@
end:
*pcchGroups = dwGroups;
- (void)pthread_mutex_unlock(currentContextMap->mMutex);
+ (void)pthread_mutex_unlock(¤tContextMap->mMutex);
PROFILE_END(rv)
@@ -3298,14 +3298,7 @@
newContextMap->dwClientID = dwClientID;
newContextMap->cancellable = FALSE;
- newContextMap->mMutex = malloc(sizeof(pthread_mutex_t));
- if (NULL == newContextMap->mMutex)
- {
- Log2(PCSC_LOG_DEBUG, "Freeing SCONTEXTMAP @%p", newContextMap);
- free(newContextMap);
- return SCARD_E_NO_MEMORY;
- }
- (void)pthread_mutex_init(newContextMap->mMutex, NULL);
+ (void)pthread_mutex_init(&newContextMap->mMutex, NULL);
lrv = list_init(&newContextMap->channelMapList);
if (lrv < 0)
@@ -3337,8 +3330,7 @@
error:
- (void)pthread_mutex_destroy(newContextMap->mMutex);
- free(newContextMap->mMutex);
+ (void)pthread_mutex_destroy(&newContextMap->mMutex);
free(newContextMap);
return SCARD_E_NO_MEMORY;
@@ -3413,9 +3405,7 @@
targetContextMap->hContext = 0;
(void)ClientCloseSession(targetContextMap->dwClientID);
targetContextMap->dwClientID = 0;
- (void)pthread_mutex_destroy(targetContextMap->mMutex);
- free(targetContextMap->mMutex);
- targetContextMap->mMutex = NULL;
+ (void)pthread_mutex_destroy(&targetContextMap->mMutex);
listSize = list_size(&targetContextMap->channelMapList);
for (list_index = 0; list_index < listSize; list_index++)
More information about the Pcsclite-cvs-commit
mailing list