static int cmpd_exists(Store *store, const char *file_name) { if (h_get(store->dir.cmpd->entries, file_name) != NULL) { return true; } else { return false; } }
static int ram_exists(Store *store, const char *filename) { if (h_get(store->dir.ht, filename) != NULL) { return true; } else { return false; } }
static int mntlist_contains(char *host, char *path) { struct mntentry m; m.m_host = host; m.m_path = path; return (h_get(mntlist, &m) != NULL); }
static off_t cmpd_length(Store *store, char *file_name) { FileEntry *fe = h_get(store->dir.cmpd->entries, file_name); if (fe != NULL) { return fe->length; } else { return 0; } }
static off_t ram_length(Store *store, const char *filename) { RAMFile *rf = (RAMFile *)h_get(store->dir.ht, filename); if (rf != NULL) { return rf->len; } else { return 0; } }
Symbol intern_and_free(char *str) { Symbol symbol = (Symbol)h_get(symbol_table, str); if (!symbol) { symbol = (Symbol)str; h_set(symbol_table, str, str); } else { free(str); } return symbol; }
static OutStream *ram_new_output(Store *store, const char *filename) { RAMFile *rf = (RAMFile *)h_get(store->dir.ht, filename); OutStream *os = os_new(); if (rf == NULL) { rf = rf_new(filename); h_set(store->dir.ht, rf->name, rf); } REF(rf); os->pointer = 0; os->file.rf = rf; os->m = &RAM_OUT_STREAM_METHODS; return os; }
static void ram_rename(Store *store, const char *from, const char *to) { RAMFile *rf = (RAMFile *)h_rem(store->dir.ht, from, false); RAMFile *tmp; if (rf == NULL) { RAISE(IO_ERROR, "couldn't rename \"%s\" to \"%s\". \"%s\"" " doesn't exist", from, to, from); } free(rf->name); rf->name = estrdup(to); /* clean up the file we are overwriting */ tmp = (RAMFile *)h_get(store->dir.ht, to); if (tmp != NULL) { DEREF(tmp); } h_set(store->dir.ht, rf->name, rf); }
void mntlist_delete(char *host, char *path) { struct mntentry *m, mm; mm.m_host = host; mm.m_path = path; (void) rw_wrlock(&rmtab_lock); if (m = (struct mntentry *)h_get(mntlist, &mm)) { rmtab_delete(m->m_pos); (void) h_delete(mntlist, m); free(m->m_path); free(m->m_host); free(m); if (RMTAB_TOOMANY_DELETED()) rmtab_rewrite(); } (void) rw_unlock(&rmtab_lock); }
static InStream *cmpd_open_input(Store *store, const char *file_name) { FileEntry *entry; CompoundStore *cmpd = store->dir.cmpd; InStream *is; mutex_lock(&store->mutex); if (cmpd->stream == NULL) { mutex_unlock(&store->mutex); RAISE(IO_ERROR, "Can't open compound file input stream. Parent " "stream is closed."); } entry = h_get(cmpd->entries, file_name); if (entry == NULL) { mutex_unlock(&store->mutex); RAISE(IO_ERROR, "File %s does not exist: ", file_name); } is = cmpd_create_input(cmpd->stream, entry->offset, entry->length); mutex_unlock(&store->mutex); return is; }
Store *open_fs_store(const char *pathname) { Store *store = NULL; mutex_lock(&stores_mutex); if (!stores) { stores = h_new_str(NULL, (free_ft)fs_destroy); register_for_cleanup(stores, (free_ft)h_destroy); } store = (Store *)h_get(stores, pathname); if (store) { mutex_lock(&store->mutex); store->ref_cnt++; mutex_unlock(&store->mutex); } else { store = fs_store_new(pathname); h_set(stores, store->dir.path, store); } mutex_unlock(&stores_mutex); return store; }
static int memqueue_poll_queue(poll_args_t *user_args) { int rev = 0; int i = 0; int total_msgs = 0; int total_bound_queues = 0; cli_binder_t *cli_binder = NULL; memqueue_t *q = NULL; cli_binder = cli_binder_create(user_args->timeout); for (i = 0; i < user_args->total; i++) { q = h_get(memqueue_ins.queue_store, user_args->queue_args[i].q_id); if (!q) continue; total_bound_queues++; if (q->consumer_expiry && user_args->queue_args[i].consumer_id != NULL) memqueue_refresh_consumer(q, user_args->queue_args[i].consumer_id); memqueue_resched(&memqueue_ins, q); //printf("q->rev is %d and user_rev is %d\n", q->rev, user_args->queue_args[i].rev); if (q->rev < user_args->queue_args[i].rev) rev = -1; else rev = user_args->queue_args[i].rev; /* bind poller */ memqueue_bind(q, cli_binder, rev, user_args->queue_args[i].include_consumers); total_msgs += cli_binder_enqueue_msgs(cli_binder, q, rev, user_args->queue_args[i].latest); } if (total_bound_queues == 0) { cli_binder_free(cli_binder); memqueue_respond(MEMQUEUE_NOT_FOUND, NULL); return 0; } /* Do we have messages that match our rev requirements already? */ if (total_msgs == 0) lthread_cond_wait(cli_binder->cond, cli_binder->timeout); if (cli_binder_has_pending_msgs(cli_binder)) memqueue_respond(MEMQUEUE_MSGS, cli_binder); else memqueue_respond(MEMQUEUE_TIMEOUT, NULL); memqueue_unbind_all(cli_binder); cli_binder_release_pending_msgs(cli_binder); cli_binder_free(cli_binder); return 0; }
static void ram_touch(Store *store, const char *filename) { if (h_get(store->dir.ht, filename) == NULL) { h_set(store->dir.ht, filename, rf_new(filename)); } }
INLINE void *h_get_int(Hash *self, const unsigned long key) { return h_get(self, (const void *)key); }