summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrelyea%netscape.com <devnull@localhost>2000-06-13 21:34:52 +0000
committerrelyea%netscape.com <devnull@localhost>2000-06-13 21:34:52 +0000
commit930f5c5e6a7609ec639cc700ba7d5c33036ed07c (patch)
tree954c44a823ad3ee4a9441110596ac3beda540a93
parentb4dd7bda56eaf37da6408c8709968458cf3613fc (diff)
downloadnss-hg-930f5c5e6a7609ec639cc700ba7d5c33036ed07c.tar.gz
Reuse old Object structures rather than build and free them every time.
-rw-r--r--security/nss/lib/softoken/pkcs11i.h1
-rw-r--r--security/nss/lib/softoken/pkcs11u.c40
2 files changed, 39 insertions, 2 deletions
diff --git a/security/nss/lib/softoken/pkcs11i.h b/security/nss/lib/softoken/pkcs11i.h
index bea5a5b1c..495817aef 100644
--- a/security/nss/lib/softoken/pkcs11i.h
+++ b/security/nss/lib/softoken/pkcs11i.h
@@ -87,6 +87,7 @@ typedef void (*PK11Free)(void *);
#define TOKEN_OBJECT_HASH_SIZE 1024
#define SESSION_HASH_SIZE 512
#define MAX_KEY_LEN 256
+#define MAX_OBJECT_LIST_SIZE 800
/* Value to tell if an attribute is modifiable or not.
* NEVER: attribute is only set on creation.
diff --git a/security/nss/lib/softoken/pkcs11u.c b/security/nss/lib/softoken/pkcs11u.c
index 14bbdc8a3..fdb03a543 100644
--- a/security/nss/lib/softoken/pkcs11u.c
+++ b/security/nss/lib/softoken/pkcs11u.c
@@ -591,15 +591,51 @@ pk11_AddAttributeType(PK11Object *object,CK_ATTRIBUTE_TYPE type,void *valPtr,
*/
/* allocation hooks that allow us to recycle old object structures */
-static PK11Object *
+#ifdef MAX_OBJECT_LIST_SIZE
+static PK11Object * objectFreeList = NULL;
+static PRLock *objectLock = NULL;
+static int object_count = 0;
+#endif
+PK11Object *
pk11_GetObjectFromList(PRBool *hasLocks) {
- PK11Object *object = (PK11Object*)PORT_ZAlloc(sizeof(PK11Object));
+ PK11Object *object;
+
+#if MAX_OBJECT_LIST_SIZE
+ if (objectLock == NULL) {
+ objectLock = PR_NewLock();
+ }
+
+ PK11_USE_THREADS(PR_Lock(objectLock));
+ object = objectFreeList;
+ if (object) {
+ objectFreeList = object->next;
+ object_count--;
+ }
+ PK11_USE_THREADS(PR_Unlock(objectLock));
+ if (object) {
+ object->next = object->prev = NULL;
+ *hasLocks = PR_TRUE;
+ return object;
+ }
+#endif
+
+ object = (PK11Object*)PORT_ZAlloc(sizeof(PK11Object));
*hasLocks = PR_FALSE;
return object;
}
static void
pk11_PutObjectToList(PK11Object *object) {
+#ifdef MAX_OBJECT_LIST_SIZE
+ if (object_count < MAX_OBJECT_LIST_SIZE) {
+ PK11_USE_THREADS(PR_Lock(objectLock));
+ object->next = objectFreeList;
+ objectFreeList = object;
+ object_count++;
+ PK11_USE_THREADS(PR_Unlock(objectLock));
+ return;
+ }
+#endif
PK11_USE_THREADS(PR_DestroyLock(object->attributeLock);)
PK11_USE_THREADS(PR_DestroyLock(object->refLock);)
object->attributeLock = object->refLock = NULL;