Changing the calling convention gets us savings of about
60 cycles per call (measured with callgrind in
SCardBeginTransaction)
For compatibility with external users I've added an inline function with the
old parameter stxle.
Index: trunk/src/winscard_scf.c
===================================================================
--- trunk/src/winscard_scf.c (Revision 16)
+++ trunk/src/winscard_scf.c (Revision 17)
@@ -1315,8 +1315,7 @@
}
while(1) {
- *phCard = (PCSCLITE_SVC_IDENTITY + SYS_Random(SYS_GetSeed(),
- 1.0, 65535.0));
+ *phCard = (PCSCLITE_SVC_IDENTITY + SYS_RandomInt(1, 65535));
if(SCardGetHandleIndice(*phCard) == -1)
break;
}
@@ -1355,8 +1354,7 @@
if (status != SCF_STATUS_SUCCESS) return SCARD_E_NO_SERVICE;
while(1) {
- *phContext = (PCSCLITE_SVC_IDENTITY + SYS_Random(SYS_GetSeed(),
- 1.0, 65535.0));
+ *phContext = (PCSCLITE_SVC_IDENTITY + SYS_RandomInt(1, 65535));
if(-1 == SCardGetContextIndice(*phContext))
break;
}
Index: trunk/src/sys_generic.h
===================================================================
--- trunk/src/sys_generic.h (Revision 16)
+++ trunk/src/sys_generic.h (Revision 17)
@@ -81,7 +81,11 @@
int SYS_Fstat(int);
- int SYS_Random(int, float, float);
+ int SYS_RandomInt(int, int);
+ static inline int SYS_Random(int iSeed, float fStart, float fEnd)
+ {
+ return SYS_RandomInt(fStart, fEnd);
+ }
int SYS_GetSeed(void);
Index: trunk/src/sys_unix.c
===================================================================
--- trunk/src/sys_unix.c (Revision 16)
+++ trunk/src/sys_unix.c (Revision 17)
@@ -291,7 +291,7 @@
return fstat(iFd, &sStatus);
}
-int SYS_Random(int iSeed, float fStart, float fEnd)
+int SYS_RandomInt(int fStart, int fEnd)
{
static int iInitialized=0;
int iRandNum = 0;
@@ -302,7 +302,7 @@
iInitialized=1;
}
- iRandNum = 1 + (int) (fEnd * rand() / (RAND_MAX + fStart));
+ iRandNum = (int)((float)rand()/RAND_MAX * (fEnd - fStart)) + fStart;
return iRandNum;
}
Index: trunk/src/winscard.c
===================================================================
--- trunk/src/winscard.c (Revision 16)
+++ trunk/src/winscard.c (Revision 17)
@@ -62,8 +62,7 @@
* identified by clients and distinguished from others
*/
- *phContext = (PCSCLITE_SVC_IDENTITY + SYS_Random(SYS_GetSeed(),
- 1.0, 65535.0));
+ *phContext = (PCSCLITE_SVC_IDENTITY + SYS_RandomInt( 1, 65535));
DebugLogB("Establishing Context: %d", *phContext);
Index: trunk/src/readerfactory.c
===================================================================
--- trunk/src/readerfactory.c (Revision 16)
+++ trunk/src/readerfactory.c (Revision 17)
@@ -1126,7 +1126,7 @@
* Create a random handle with 16 bits check to see if it already is
* used.
*/
- randHandle = SYS_Random(SYS_GetSeed(), 10, 65000);
+ randHandle = SYS_RandomInt(10, 65000);
while (1)
{
@@ -1146,7 +1146,7 @@
/*
* Get a new handle and loop
again
*/
- randHandle =
SYS_Random(randHandle, 10, 65000);
+ randHandle = SYS_RandomInt(10,
65000);
continue;
}
}
Index: trunk/src/winscard_clnt.c
===================================================================
--- trunk/src/winscard_clnt.c (Revision 16)
+++ trunk/src/winscard_clnt.c (Revision 17)
@@ -795,7 +795,7 @@
/*
* This helps prevent starvation
*/
- randnum = SYS_Random(randnum, 1000.0, 10000.0);
+ randnum = SYS_RandomInt(1000, 10000);
SYS_USleep(randnum);
SYS_MutexUnLock(psContextMap[dwContextIndex].mMutex);
_______________________________________________
Muscle mailing list
[email protected]
http://lists.drizzle.com/mailman/listinfo/muscle