/*****************************************************************************/
int
-hashtable_insert(struct hashtable *h, void *k, void *v)
+hashtable_insert(struct hashtable *h, void *k, void *v, hashtable_flag_t flags)
{
/* This method allows duplicate keys - but they shouldn't be used */
unsigned int index;
index = indexFor(h->tablelength,e->h);
e->k = k;
e->v = v;
+ e->flags = flags;
e->next = h->table[index];
h->table[index] = e;
return -1;
*pE = e->next;
h->entrycount--;
v = e->v;
- freekey(e->k);
+ if (e->flags & HASHTABLE_FLAG_FREE_KEY) {
+ freekey(e->k);
+ }
free(e);
return v;
}
/*****************************************************************************/
/* destroy */
void
-hashtable_destroy(struct hashtable *h, int free_keys, int free_values)
+hashtable_destroy(struct hashtable *h)
{
unsigned int i;
struct entry *e, *f;
{
e = table[i];
while (NULL != e)
- { f = e; e = e->next; if (free_keys) freekey(f->k); if (free_values) free(f->v); free(f); }
+ { f = e; e = e->next; if (f->flags & HASHTABLE_FLAG_FREE_KEY) freekey(f->k); if (f->flags & HASHTABLE_FLAG_FREE_VALUE) free(f->v); free(f); }
}
free(h->table);
* If in doubt, remove before insert.
*/
+
+typedef enum {
+ HASHTABLE_FLAG_NONE = 0,
+ HASHTABLE_FLAG_FREE_KEY = (1 << 0),
+ HASHTABLE_FLAG_FREE_VALUE = (1 << 1)
+} hashtable_flag_t;
+
int
-hashtable_insert(struct hashtable *h, void *k, void *v);
+hashtable_insert(struct hashtable *h, void *k, void *v, hashtable_flag_t flags);
#define DEFINE_HASHTABLE_INSERT(fnname, keytype, valuetype) \
int fnname (struct hashtable *h, keytype *k, valuetype *v) \
*/
void
-hashtable_destroy(struct hashtable *h, int free_keys, int free_values);
+hashtable_destroy(struct hashtable *h);
struct hashtable_iterator *hashtable_first(struct hashtable *h);
struct hashtable_iterator *hashtable_next(struct hashtable_iterator *i);
name = buf;
}
span->name = strdup(name);
- hashtable_insert(globals.span_hash, (void *)span->name, span);
+ hashtable_insert(globals.span_hash, (void *)span->name, span, HASHTABLE_FLAG_NONE);
zap_mutex_unlock(globals.mutex);
zap_log(ZAP_LOG_DEBUG, "created span %d (%s) of type %s\n", span->span_id, span->name, type);
if (hashtable_search(globals.interface_hash, (void *)interface->name)) {
zap_log(ZAP_LOG_ERROR, "Interface %s already loaded!\n", interface->name);
} else {
- hashtable_insert(globals.interface_hash, (void *)interface->name, interface);
+ hashtable_insert(globals.interface_hash, (void *)interface->name, interface, HASHTABLE_FLAG_NONE);
process_module_config(interface);
x++;
}
zap_log(ZAP_LOG_ERROR, "Module %s already loaded!\n", mod->name);
zap_dso_destroy(&lib);
} else {
- hashtable_insert(globals.module_hash, (void *)mod->name, mod);
+ hashtable_insert(globals.module_hash, (void *)mod->name, mod, HASHTABLE_FLAG_NONE);
count++;
}
zap_mutex_unlock(globals.mutex);
zap_unload_modules();
zap_mutex_lock(globals.mutex);
- hashtable_destroy(globals.interface_hash, 0, 0);
- hashtable_destroy(globals.module_hash, 0, 0);
- hashtable_destroy(globals.span_hash, 0, 0);
+ hashtable_destroy(globals.interface_hash);
+ hashtable_destroy(globals.module_hash);
+ hashtable_destroy(globals.span_hash);
zap_mutex_unlock(globals.mutex);
zap_mutex_destroy(&globals.mutex);