MXUserHistoTearDown(Atomic_ReadPtr(&lock->heldHisto));
#endif
- HashTable_Free(lock->holderTable);
+ HashTable_FreeUnsafe(lock->holderTable);
lock->header.signature = 0; // just in case...
free((void *) lock->header.name); // avoid const warnings
lock->header.name = NULL;
if (ht == NULL) {
ht = new;
} else {
- new->atomic = FALSE;
- HashTable_Free(new);
+ HashTable_FreeUnsafe(new);
}
}
ASSERT(ht == Atomic_ReadPtr(var));
}
+/*
+ *----------------------------------------------------------------------
+ *
+ * HashTable_Clear --
+ *
+ * Clear all entries a hashtable by freeing them.
+ *
+ * Results:
+ * None.
+ *
+ * Side effects:
+ * None.
+ *
+ *----------------------------------------------------------------------
+ */
+
+static void
+HashTableClearInternal(HashTable *ht) // IN/OUT:
+{
+ int i;
+
+ ht->numElements = 0;
+
+ for (i = 0; i < ht->numEntries; i++) {
+ HashTableEntry *entry;
+
+ while ((entry = ENTRY(ht->buckets[i])) != NULL) {
+ SETENTRY(ht->buckets[i], ENTRY(entry->next));
+ if (ht->copyKey) {
+ free((void *) entry->keyStr);
+ }
+ if (ht->freeEntryFn) {
+ ht->freeEntryFn(Atomic_ReadPtr(&entry->clientData));
+ }
+ free(entry);
+ }
+ }
+}
+
+
+void
+HashTable_Clear(HashTable *ht) // IN/OUT:
+{
+ ASSERT(ht);
+ ASSERT(!ht->atomic);
+
+ HashTableClearInternal(ht);
+}
+
+
/*
*----------------------------------------------------------------------
*
ASSERT(ht);
ASSERT(!ht->atomic);
- HashTable_Clear(ht);
+ HashTableClearInternal(ht);
free(ht->buckets);
free(ht);
/*
*----------------------------------------------------------------------
*
- * HashTable_Clear --
+ * HashTable_FreeUnsafe --
*
- * Clear all entries a hashtable by freeing them.
+ * HashTable_Free for atomic hash tables. Non-atomic hash tables
+ * should always use HashTable_Free. The caller should make sure
+ * no other thread may access the hash table when this is called.
*
* Results:
* None.
*/
void
-HashTable_Clear(HashTable *ht) // IN/OUT:
+HashTable_FreeUnsafe(HashTable *ht) // IN/OUT:
{
- int i;
-
ASSERT(ht);
- ASSERT(!ht->atomic);
- ht->numElements = 0;
+ HashTableClearInternal(ht);
- for (i = 0; i < ht->numEntries; i++) {
- HashTableEntry *entry;
-
- while ((entry = ENTRY(ht->buckets[i])) != NULL) {
- SETENTRY(ht->buckets[i], ENTRY(entry->next));
- if (ht->copyKey) {
- free((void *) entry->keyStr);
- }
- if (ht->freeEntryFn) {
- ht->freeEntryFn(Atomic_ReadPtr(&entry->clientData));
- }
- free(entry);
- }
- }
+ free(ht->buckets);
+ free(ht);
}