| OLD | NEW |
| 1 /* This Source Code Form is subject to the terms of the Mozilla Public | 1 /* This Source Code Form is subject to the terms of the Mozilla Public |
| 2 * License, v. 2.0. If a copy of the MPL was not distributed with this | 2 * License, v. 2.0. If a copy of the MPL was not distributed with this |
| 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
| 4 | 4 |
| 5 /* | 5 /* |
| 6 * hash.c | 6 * hash.c |
| 7 * | 7 * |
| 8 * This is merely a couple wrappers around NSPR's PLHashTable, using | 8 * This is merely a couple wrappers around NSPR's PLHashTable, using |
| 9 * the identity hash and arena-aware allocators. The reason I did | 9 * the identity hash and arena-aware allocators. The reason I did |
| 10 * this is that hash tables are used in a few places throughout the | 10 * this is that hash tables are used in a few places throughout the |
| (...skipping 30 matching lines...) Expand all Loading... |
| 41 PLHashTable *plHashTable; | 41 PLHashTable *plHashTable; |
| 42 CK_ULONG count; | 42 CK_ULONG count; |
| 43 }; | 43 }; |
| 44 | 44 |
| 45 static PLHashNumber | 45 static PLHashNumber |
| 46 nss_ckfw_identity_hash | 46 nss_ckfw_identity_hash |
| 47 ( | 47 ( |
| 48 const void *key | 48 const void *key |
| 49 ) | 49 ) |
| 50 { | 50 { |
| 51 PRUint32 i = (PRUint32)key; | 51 return (PLHashNumber)((char *)key - (char *)NULL); |
| 52 PR_ASSERT(sizeof(PLHashNumber) == sizeof(PRUint32)); | |
| 53 return (PLHashNumber)i; | |
| 54 } | 52 } |
| 55 | 53 |
| 56 /* | 54 /* |
| 57 * nssCKFWHash_Create | 55 * nssCKFWHash_Create |
| 58 * | 56 * |
| 59 */ | 57 */ |
| 60 NSS_IMPLEMENT nssCKFWHash * | 58 NSS_IMPLEMENT nssCKFWHash * |
| 61 nssCKFWHash_Create | 59 nssCKFWHash_Create |
| 62 ( | 60 ( |
| 63 NSSCKFWInstance *fwInstance, | 61 NSSCKFWInstance *fwInstance, |
| (...skipping 16 matching lines...) Expand all Loading... |
| 80 | 78 |
| 81 rv = nss_ZNEW(arena, nssCKFWHash); | 79 rv = nss_ZNEW(arena, nssCKFWHash); |
| 82 if (!rv) { | 80 if (!rv) { |
| 83 *pError = CKR_HOST_MEMORY; | 81 *pError = CKR_HOST_MEMORY; |
| 84 return (nssCKFWHash *)NULL; | 82 return (nssCKFWHash *)NULL; |
| 85 } | 83 } |
| 86 | 84 |
| 87 rv->mutex = nssCKFWInstance_CreateMutex(fwInstance, arena, pError); | 85 rv->mutex = nssCKFWInstance_CreateMutex(fwInstance, arena, pError); |
| 88 if (!rv->mutex) { | 86 if (!rv->mutex) { |
| 89 if( CKR_OK == *pError ) { | 87 if( CKR_OK == *pError ) { |
| 90 (void)nss_ZFreeIf(rv); | |
| 91 *pError = CKR_GENERAL_ERROR; | 88 *pError = CKR_GENERAL_ERROR; |
| 92 } | 89 } |
| 90 (void)nss_ZFreeIf(rv); |
| 93 return (nssCKFWHash *)NULL; | 91 return (nssCKFWHash *)NULL; |
| 94 } | 92 } |
| 95 | 93 |
| 96 rv->plHashTable = PL_NewHashTable(0, nss_ckfw_identity_hash, | 94 rv->plHashTable = PL_NewHashTable(0, nss_ckfw_identity_hash, |
| 97 PL_CompareValues, PL_CompareValues, &nssArenaHashAllocOps, arena); | 95 PL_CompareValues, PL_CompareValues, &nssArenaHashAllocOps, arena); |
| 98 if (!rv->plHashTable) { | 96 if (!rv->plHashTable) { |
| 99 (void)nssCKFWMutex_Destroy(rv->mutex); | 97 (void)nssCKFWMutex_Destroy(rv->mutex); |
| 100 (void)nss_ZFreeIf(rv); | 98 (void)nss_ZFreeIf(rv); |
| 101 *pError = CKR_HOST_MEMORY; | 99 *pError = CKR_HOST_MEMORY; |
| 102 return (nssCKFWHash *)NULL; | 100 return (nssCKFWHash *)NULL; |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 293 if( CKR_OK != nssCKFWMutex_Lock(hash->mutex) ) { | 291 if( CKR_OK != nssCKFWMutex_Lock(hash->mutex) ) { |
| 294 return; | 292 return; |
| 295 } | 293 } |
| 296 | 294 |
| 297 PL_HashTableEnumerateEntries(hash->plHashTable, nss_ckfwhash_enumerator, &as); | 295 PL_HashTableEnumerateEntries(hash->plHashTable, nss_ckfwhash_enumerator, &as); |
| 298 | 296 |
| 299 (void)nssCKFWMutex_Unlock(hash->mutex); | 297 (void)nssCKFWMutex_Unlock(hash->mutex); |
| 300 | 298 |
| 301 return; | 299 return; |
| 302 } | 300 } |
| OLD | NEW |