/*---------------------------------------------------------------------------*/ int xio_sessions_cache_remove(uint32_t session_id) { struct xio_session *s; struct xio_key_int32 key; spin_lock(&ss_lock); key.id = session_id; HT_LOOKUP(&sessions_cache, &key, s, sessions_htbl); if (s == NULL) { spin_unlock(&ss_lock); return -1; } HT_REMOVE(&sessions_cache, s, xio_session, sessions_htbl); spin_unlock(&ss_lock); return 0; }
/** * Cancel a waitpid_callback_t, or clean up after one has triggered. Releases * all storage held by <b>ent</b>. */ void clear_waitpid_callback(waitpid_callback_t *ent) { waitpid_callback_t *old_ent; if (ent == NULL) return; if (ent->running) { old_ent = HT_REMOVE(process_map, &process_map, ent); if (old_ent != ent) { log_warn(LD_BUG, "Couldn't remove waitpid monitor for pid %u.", (unsigned) ent->pid); return; } } tor_free(ent); }
int main() { hash_table_t *table = hash_table_new(MODE_VALUEREF); int i = 1; int val = 100; int val2 = 200; int j = 2; int x =0; for (x=0;x<300;x++) { // use the macro HT_ADD(table, &j, &val); // or use the function //hash_table_add(table, &j, i, (void *) &val, sizeof(int)); val++; j++; } hash_table_add(table, &j, i, (void *) &val2, 1); j--; j--; hash_table_remove(table, &j, i); HT_REMOVE(table, &j); if (hash_table_has_key(table, &j, i)) { printf("Key found %d\n", j); } else { printf("Key NOT found %d\n", j); } val = -100; val2 = -200; int *value = NULL; value = (int* ) HT_LOOKUP(table, &j); void** keys = NULL; size_t num = hash_table_get_keys(table, keys); printf("found %d keys\n", (int)num); printf("j -> %d \n", j); if (value) printf("value is %d\n", *value); else printf("*value is %p\n", value); return 0; }
/** Helper: find the callack for <b>pid</b>; if there is one, run it, * reporting the exit status as <b>status</b>. */ static void notify_waitpid_callback_by_pid(pid_t pid, int status) { waitpid_callback_t search, *ent; search.pid = pid; ent = HT_REMOVE(process_map, &process_map, &search); if (!ent || !ent->running) { log_info(LD_GENERAL, "Child process %u has exited; no callback was " "registered", (unsigned)pid); return; } log_info(LD_GENERAL, "Child process %u has exited; running callback.", (unsigned)pid); ent->running = 0; ent->userfn(status, ent->userdata); }
void * fp_pair_map_remove(fp_pair_map_t *map, const fp_pair_t *key) { fp_pair_map_entry_t *resolve; fp_pair_map_entry_t search; void *val = NULL; tor_assert(map); tor_assert(key); memcpy(&(search.key), key, sizeof(*key)); resolve = HT_REMOVE(fp_pair_map_impl, &(map->head), &search); if (resolve) { val = resolve->val; tor_free(resolve); } return val; }
/** Public function: Remove this circuit from the HS circuitmap. Clear its HS * token, and remove it from the hashtable. */ void hs_circuitmap_remove_circuit(circuit_t *circ) { tor_assert(the_hs_circuitmap); if (!circ || !circ->hs_token) { return; } /* Remove circ from circuitmap */ circuit_t *tmp; tmp = HT_REMOVE(hs_circuitmap_ht, the_hs_circuitmap, circ); /* ... and ensure the removal was successful. */ if (tmp) { tor_assert(tmp == circ); } else { log_warn(LD_BUG, "Could not find circuit (%u) in circuitmap.", circ->n_circ_id); } /* Clear token from circ */ hs_token_free(circ->hs_token); circ->hs_token = NULL; }
/** Implementation helper for circuit_set_{p,n}_circid_orconn: A circuit ID * and/or or_connection for circ has just changed from <b>old_conn, old_id</b> * to <b>conn, id</b>. Adjust the conn,circid map as appropriate, removing * the old entry (if any) and adding a new one. If <b>active</b> is true, * remove the circuit from the list of active circuits on old_conn and add it * to the list of active circuits on conn. * XXX "active" isn't an arg anymore */ static void circuit_set_circid_orconn_helper(circuit_t *circ, int direction, circid_t id, or_connection_t *conn) { orconn_circid_circuit_map_t search; orconn_circid_circuit_map_t *found; or_connection_t *old_conn, **conn_ptr; circid_t old_id, *circid_ptr; int was_active, make_active; if (direction == CELL_DIRECTION_OUT) { conn_ptr = &circ->n_conn; circid_ptr = &circ->n_circ_id; was_active = circ->next_active_on_n_conn != NULL; make_active = circ->n_conn_cells.n > 0; } else { or_circuit_t *c = TO_OR_CIRCUIT(circ); conn_ptr = &c->p_conn; circid_ptr = &c->p_circ_id; was_active = c->next_active_on_p_conn != NULL; make_active = c->p_conn_cells.n > 0; } old_conn = *conn_ptr; old_id = *circid_ptr; if (id == old_id && conn == old_conn) return; if (_last_circid_orconn_ent && ((old_id == _last_circid_orconn_ent->circ_id && old_conn == _last_circid_orconn_ent->or_conn) || (id == _last_circid_orconn_ent->circ_id && conn == _last_circid_orconn_ent->or_conn))) { _last_circid_orconn_ent = NULL; } if (old_conn) { /* we may need to remove it from the conn-circid map */ tor_assert(old_conn->_base.magic == OR_CONNECTION_MAGIC); search.circ_id = old_id; search.or_conn = old_conn; found = HT_REMOVE(orconn_circid_map, &orconn_circid_circuit_map, &search); if (found) { tor_free(found); --old_conn->n_circuits; } if (was_active && old_conn != conn) make_circuit_inactive_on_conn(circ,old_conn); } /* Change the values only after we have possibly made the circuit inactive * on the previous conn. */ *conn_ptr = conn; *circid_ptr = id; if (conn == NULL) return; /* now add the new one to the conn-circid map */ search.circ_id = id; search.or_conn = conn; found = HT_FIND(orconn_circid_map, &orconn_circid_circuit_map, &search); if (found) { found->circuit = circ; } else { found = tor_malloc_zero(sizeof(orconn_circid_circuit_map_t)); found->circ_id = id; found->or_conn = conn; found->circuit = circ; HT_INSERT(orconn_circid_map, &orconn_circid_circuit_map, found); } if (make_active && old_conn != conn) make_circuit_active_on_conn(circ,conn); ++conn->n_circuits; }