/** * Remove cached entry for key, optionally disposing of the whole structure. * Cached entry is flushed if it was dirty and flush is set. * * @return the reusable cached entry if dispose was FALSE and the key was * indeed cached, NULL otherwise. */ static struct cached * remove_entry(dbmw_t *dw, gconstpointer key, gboolean dispose, gboolean flush) { struct cached *old; gpointer old_key; gboolean found; found = map_lookup_extended(dw->values, key, &old_key, (gpointer) &old); if (!found) return NULL; g_assert(old != NULL); if (old->dirty && flush) write_back(dw, key, old); hash_list_remove(dw->keys, key); map_remove(dw->values, key); wfree(old_key, dbmw_keylen(dw, old_key)); if (!dispose) return old; /* * Dispose of the cache structure. */ free_value(dw, old, TRUE); WFREE(old); return NULL; }
/** * Remove cached entry for key, optionally disposing of the whole structure. * Cached entry is flushed if it was dirty and flush is set. * * @return the reusable cached entry if dispose was FALSE and the key was * indeed cached, NULL otherwise. */ static struct cached * remove_entry(dbmw_t *dw, const void *key, bool dispose, bool flush) { struct cached *old; void *old_key; bool found; found = map_lookup_extended(dw->values, key, &old_key, (void *) &old); if (!found) return NULL; g_assert(old != NULL); if (dbg_ds_debugging(dw->dbg, 3, DBG_DSF_CACHING)) { dbg_ds_log(dw->dbg, dw, "%s: %s key=%s (%s)", G_STRFUNC, old->dirty ? "dirty" : "clean", dbg_ds_keystr(dw->dbg, key, (size_t) -1), flush ? "flushing" : " discarding"); } if (old->dirty && flush) write_back(dw, key, old); hash_list_remove(dw->keys, key); map_remove(dw->values, key); wfree(old_key, dbmw_keylen(dw, old_key)); if (!dispose) return old; /* * Dispose of the cache structure. */ free_value(dw, old, TRUE); WFREE(old); return NULL; }