static struct file_object * file_object_alloc(const int fd, const char * const pathname, int accmode) { static const struct file_object zero_fo; struct file_object *fo; hikset_t *ht; g_return_val_if_fail(fd >= 0, NULL); g_return_val_if_fail(pathname, NULL); g_return_val_if_fail(is_absolute_path(pathname), NULL); g_return_val_if_fail(!file_object_find(pathname, accmode), NULL); ht = file_object_mode_get_table(accmode); g_return_val_if_fail(ht, NULL); WALLOC(fo); *fo = zero_fo; fo->magic = FILE_OBJECT_MAGIC; fo->ref_count = 1; fo->fd = fd; fo->accmode = accmode; fo->pathname = atom_str_get(pathname); file_object_check(fo); g_assert(is_valid_fd(fo->fd)); hikset_insert(ht, fo); return fo; }
/** * Add value to the table. * * If it was already present, its lifetime is reset to the aging delay. * * The key argument is freed immediately if there is a free routine for * keys and the key was present in the table. * * The previous value is freed and replaced by the new one if there is * an insertion conflict and the key pointers are different. */ void aging_insert(aging_table_t *ag, const void *key, void *value) { bool found; void *ovalue; time_t now = tm_time(); struct aging_value *aval; aging_check(ag); aging_synchronize(ag); found = hikset_lookup_extended(ag->table, key, &ovalue); if (found) { aval = ovalue; if (ag->kvfree != NULL) { /* * We discard the new and keep the old key instead. * That way, we don't have to update the hash table. */ (*ag->kvfree)(deconstify_pointer(key), aval->value); } /* * Value existed for this key, reset its lifetime by moving the * entry to the tail of the list. */ aval->value = value; aval->last_insert = now; elist_moveto_tail(&ag->list, aval); } else { WALLOC(aval); aval->value = value; aval->key = deconstify_pointer(key); aval->last_insert = now; hikset_insert(ag->table, aval); elist_append(&ag->list, aval); } aging_return_void(ag); }