Lines Matching refs:foz_db
111 update_foz_index(struct foz_db *foz_db, FILE *db_idx, unsigned file_idx)
159 struct foz_db_entry *entry = ralloc(foz_db->mem_ctx,
173 _mesa_hash_table_u64_insert(foz_db->index_db, key, entry);
199 load_foz_dbs(struct foz_db *foz_db, FILE *db_idx, uint8_t file_idx,
211 int err = lock_file_with_timeout(foz_db->file[file_idx], 100000000);
238 sizeof(stream_reference_magic_and_version), foz_db->file[file_idx]) !=
247 fflush(foz_db->file[file_idx]);
251 flock(fileno(foz_db->file[file_idx]), LOCK_UN);
253 update_foz_index(foz_db, db_idx, file_idx);
255 foz_db->alive = true;
259 flock(fileno(foz_db->file[file_idx]), LOCK_UN);
260 foz_destroy(foz_db);
269 foz_prepare(struct foz_db *foz_db, char *cache_path)
279 foz_db->file[0] = fopen(filename, "a+b");
280 foz_db->db_idx = fopen(idx_filename, "a+b");
285 if (!check_files_opened_successfully(foz_db->file[0], foz_db->db_idx))
288 simple_mtx_init(&foz_db->mtx, mtx_plain);
289 simple_mtx_init(&foz_db->flock_mtx, mtx_plain);
290 foz_db->mem_ctx = ralloc_context(NULL);
291 foz_db->index_db = _mesa_hash_table_u64_create(NULL);
293 if (!load_foz_dbs(foz_db, foz_db->db_idx, 0, false))
315 foz_db->file[file_idx] = fopen(filename, "rb");
321 if (!check_files_opened_successfully(foz_db->file[file_idx], db_idx)) {
323 foz_db->file[file_idx] = NULL;
328 if (!load_foz_dbs(foz_db, db_idx, file_idx, true)) {
344 foz_destroy(struct foz_db *foz_db)
346 if (foz_db->db_idx)
347 fclose(foz_db->db_idx);
349 if (foz_db->file[i])
350 fclose(foz_db->file[i]);
353 if (foz_db->mem_ctx) {
354 _mesa_hash_table_u64_destroy(foz_db->index_db);
355 ralloc_free(foz_db->mem_ctx);
356 simple_mtx_destroy(&foz_db->flock_mtx);
357 simple_mtx_destroy(&foz_db->mtx);
365 foz_read_entry(struct foz_db *foz_db, const uint8_t *cache_key_160bit,
372 if (!foz_db->alive)
375 simple_mtx_lock(&foz_db->mtx);
378 _mesa_hash_table_u64_search(foz_db->index_db, hash);
380 update_foz_index(foz_db, foz_db->db_idx, 0);
381 entry = _mesa_hash_table_u64_search(foz_db->index_db, hash);
384 simple_mtx_unlock(&foz_db->mtx);
389 if (fseek(foz_db->file[file_idx], entry->offset, SEEK_SET) < 0)
393 if (fread(&entry->header, 1, header_size, foz_db->file[file_idx]) !=
407 if (fread(data, 1, data_sz, foz_db->file[file_idx]) != data_sz)
416 simple_mtx_unlock(&foz_db->mtx);
427 simple_mtx_unlock(&foz_db->mtx);
435 foz_write_entry(struct foz_db *foz_db, const uint8_t *cache_key_160bit,
440 if (!foz_db->alive)
446 simple_mtx_lock(&foz_db->flock_mtx);
450 int err = lock_file_with_timeout(foz_db->file[0], 1000000000);
454 simple_mtx_lock(&foz_db->mtx);
456 update_foz_index(foz_db, foz_db->db_idx, 0);
459 _mesa_hash_table_u64_search(foz_db->index_db, hash);
461 simple_mtx_unlock(&foz_db->mtx);
462 flock(fileno(foz_db->file[0]), LOCK_UN);
463 simple_mtx_unlock(&foz_db->flock_mtx);
474 fseek(foz_db->file[0], 0, SEEK_END);
479 if (fwrite(hash_str, 1, FOSSILIZE_BLOB_HASH_LENGTH, foz_db->file[0]) !=
483 off_t offset = ftell(foz_db->file[0]);
486 if (fwrite(&header, 1, sizeof(header), foz_db->file[0]) != sizeof(header))
490 if (fwrite(blob, 1, blob_size, foz_db->file[0]) != blob_size)
494 fflush(foz_db->file[0]);
497 if (fwrite(hash_str, 1, FOSSILIZE_BLOB_HASH_LENGTH, foz_db->db_idx) !=
506 if (fwrite(&header, 1, sizeof(header), foz_db->db_idx) !=
510 if (fwrite(&offset, 1, sizeof(uint64_t), foz_db->db_idx) !=
515 fflush(foz_db->db_idx);
517 entry = ralloc(foz_db->mem_ctx, struct foz_db_entry);
522 _mesa_hash_table_u64_insert(foz_db->index_db, hash, entry);
524 simple_mtx_unlock(&foz_db->mtx);
525 flock(fileno(foz_db->file[0]), LOCK_UN);
526 simple_mtx_unlock(&foz_db->flock_mtx);
531 simple_mtx_unlock(&foz_db->mtx);
533 flock(fileno(foz_db->file[0]), LOCK_UN);
534 simple_mtx_unlock(&foz_db->flock_mtx);
540 foz_prepare(struct foz_db *foz_db, char *filename)
549 foz_destroy(struct foz_db *foz_db)
554 foz_read_entry(struct foz_db *foz_db, const uint8_t *cache_key_160bit,
561 foz_write_entry(struct foz_db *foz_db, const uint8_t *cache_key_160bit,