static int bdb_cache_delete_entry_internal( Cache *cache, Entry *e ) { int rc = 0; /* return code */ /* dn tree */ if ( avl_delete( &cache->c_dntree, (caddr_t) e, entry_dn_cmp ) == NULL ) { rc = -1; } /* id tree */ if ( avl_delete( &cache->c_idtree, (caddr_t) e, entry_id_cmp ) == NULL ) { rc = -1; } if (rc != 0) { return rc; } /* lru */ LRU_DELETE( cache, e ); cache->c_cursize--; /* * flag entry to be freed later by a call to cache_return_entry() */ BEI(e)->bei_state = CACHE_ENTRY_DELETED; return( 0 ); }
static void avl_delete (node* tree) { if (!tree) return; avl_delete (tree -> child [left]); tree -> child [left] = NULL; avl_delete (tree -> child [right]); tree -> child [right] = NULL; free (tree); tree = NULL; }
int hx_idmap_remove_string ( hx_idmap* m, char* n ) { hx_idmap_item i; i.string = n; hx_idmap_item* item = (hx_idmap_item*) avl_delete( m->string2id, &i ); if (item != NULL) { avl_delete( m->id2string, item ); _hx_free_idmap_item( item, NULL ); return 0; } else { return 1; } }
int hx_idmap_remove_id ( hx_idmap* m, uint64_t id ) { hx_idmap_item i; i.id = id; hx_idmap_item* item = (hx_idmap_item*) avl_delete( m->id2string, &i ); if (item != NULL) { avl_delete( m->string2id, item ); _hx_free_idmap_item( item, NULL ); return 0; } else { return 1; } }
void olsr_delete_interface_routes(int if_index) { struct rt_entry *rt; bool triggerUpdate = false; OLSR_FOR_ALL_RT_ENTRIES(rt) { bool mightTrigger = false; struct rt_path *rtp; struct avl_node *rtp_tree_node, *next_rtp_tree_node; /* run through all routing paths of route */ for (rtp_tree_node = avl_walk_first(&rt->rt_path_tree); rtp_tree_node != NULL; rtp_tree_node = next_rtp_tree_node) { /* * pre-fetch the next node before loosing context. */ next_rtp_tree_node = avl_walk_next(rtp_tree_node); rtp = rtp_tree2rtp(rtp_tree_node); /* nexthop use lost interface ? */ if (rtp->rtp_nexthop.iif_index == if_index) { /* remove from the originator tree */ avl_delete(&rt->rt_path_tree, rtp_tree_node); rtp->rtp_rt = NULL; if (rt->rt_best == rtp) { rt->rt_best = NULL; mightTrigger = true; } } } if (mightTrigger) { if (!rt->rt_path_tree.count) { /* oops, all routes are gone - flush the route head */ avl_delete(&routingtree, rt_tree_node); /* do not dequeue route because they are already gone */ } triggerUpdate = true; } } OLSR_FOR_ALL_RT_ENTRIES_END(rt) /* trigger route update if necessary */ if (triggerUpdate) { olsr_update_rib_routes(); olsr_update_kernel_routes(); } }
/****************************************************************************** **函数名称: rtrd_node_to_svr_map_del **功 能: 删除NODE -> SVR映射 **输入参数: ** ctx: 全局对象 ** nodeid: 结点ID ** rsvr_id: 接收服务索引 **输出参数: NONE **返 回: 0:成功 !0:失败 **实现描述: 从链表中找出sck_serial结点, 并删除! **注意事项: **作 者: # Qifeng.zou # 2015.05.30 22:25:20 # ******************************************************************************/ int rtrd_node_to_svr_map_del(rtrd_cntx_t *ctx, int nodeid, int rsvr_id) { int idx; rtrd_node_to_svr_map_t *map; pthread_rwlock_wrlock(&ctx->node_to_svr_map_lock); /* > 查找映射表 */ map = avl_query(ctx->node_to_svr_map, &nodeid, sizeof(nodeid)); if (NULL == map) { pthread_rwlock_unlock(&ctx->node_to_svr_map_lock); log_error(ctx->log, "Query nodeid [%d] failed!", nodeid); return RTMQ_ERR; } /* > 删除处理 */ for (idx=0; idx<map->num; ++idx) { if (map->rsvr_id[idx] == rsvr_id) { map->rsvr_id[idx] = map->rsvr_id[--map->num]; /* 删除:使用最后一个值替代当前值 */ if (0 == map->num) { avl_delete(ctx->node_to_svr_map, &nodeid, sizeof(nodeid), (void *)&map); FREE(map); } break; } } pthread_rwlock_unlock(&ctx->node_to_svr_map_lock); return RTMQ_OK; }
/* internal function for general removing by index */ int remove_book(long index) { Book *D; Book tmp; char *name; char *title; long size = (db.numberOfBooks - 1) * sizeof(Book); title = db.arr[index].title; name = db.arr[index].authors[0].last; /* removing from trees */ avl = avl_delete(db.arr[index].id, avl); trie_title = trie_delete(title, trie_title); trie_name = trie_delete(name, trie_name); /* moving the interesting node at the end */ tmp = db.arr[index]; memmove(db.arr+index, db.arr+index+1, sizeof(Book)*(db.numberOfBooks-index-1)); db.arr[db.numberOfBooks - 1] = tmp; /* first freeing any dynamic memory */ free(db.arr[db.numberOfBooks - 1].authors); /* removing by reallocating by one Book size to free the coresponding * memory of the interesting node */ D = realloc(db.arr, size); if (D) { /* replace and reduce the sum */ db.arr = D; db.numberOfBooks--; return 0; } else return -1; }
/** * @brief test case for random number insert, search and delete. */ void testcase_for_random() { TREE T = avl_init(); int taller = 0, lower = 0; int i = 0, n = 100; int _t = 0; srand(time(NULL)); for (i = 0; i < n; i ++) { _t = rand() % n; printf("avl_insert(&T, %d) = %d\n", _t, avl_insert(&T, _t, &taller)); } for (i = 0; i < n; i ++) { _t = rand() % n; printf("avl_search(T, %d) = %d\n", _t, avl_search(T, _t)); } printf("avl_traveral: "); avl_traveral(T, printout_node); printf("\n"); for (i = 0; i < n; i ++) { _t = rand() % n; printf("avl_delete(&T, %d) = %d\n", _t, avl_delete(&T, _t, &lower)); } printf("avl_traveral: "); avl_traveral(T, printout_node); printf("\n"); avl_destory(T); }
static void *_start_routine(void *arg) { thread_start_t *start = (thread_start_t *)arg; void *(*start_routine)(void *) = start->start_routine; void *real_arg = start->arg; thread_type *thread = start->thread; _block_signals(); /* insert thread into thread tree here */ _mutex_lock(&_threadtree_mutex); thread->sys_thread = pthread_self(); avl_insert(_threadtree, (void *)thread); _mutex_unlock(&_threadtree_mutex); #ifdef THREAD_DEBUG LOG_INFO4("Added thread %d [%s] started at [%s:%d]", thread->thread_id, thread->name, thread->file, thread->line); #endif pthread_setcancelstate (PTHREAD_CANCEL_ENABLE, NULL); free (start); (start_routine)(real_arg); if (thread->detached) { _mutex_lock (&_threadtree_mutex); avl_delete (_threadtree, thread, _free_thread); _mutex_unlock (&_threadtree_mutex); } return NULL; }
void bdb_idl_cache_del_id( struct bdb_info *bdb, DB *db, DBT *key, ID id ) { bdb_idl_cache_entry_t *cache_entry, idl_tmp; DBT2bv( key, &idl_tmp.kstr ); idl_tmp.db = db; ldap_pvt_thread_rdwr_wlock( &bdb->bi_idl_tree_rwlock ); cache_entry = avl_find( bdb->bi_idl_tree, &idl_tmp, bdb_idl_entry_cmp ); if ( cache_entry != NULL ) { bdb_idl_delete( cache_entry->idl, id ); if ( cache_entry->idl[0] == 0 ) { if ( avl_delete( &bdb->bi_idl_tree, (caddr_t) cache_entry, bdb_idl_entry_cmp ) == NULL ) { Debug( LDAP_DEBUG_ANY, "=> bdb_idl_cache_del: " "AVL delete failed\n", 0, 0, 0 ); } --bdb->bi_idl_cache_size; ldap_pvt_thread_mutex_lock( &bdb->bi_idl_tree_lrulock ); IDL_LRU_DELETE( bdb, cache_entry ); ldap_pvt_thread_mutex_unlock( &bdb->bi_idl_tree_lrulock ); free( cache_entry->kstr.bv_val ); free( cache_entry->idl ); free( cache_entry ); } } ldap_pvt_thread_rdwr_wunlock( &bdb->bi_idl_tree_rwlock ); }
static void remove_from_fh (fh_node *fh, client_t *client) { thread_mutex_lock (&fh->lock); avl_delete (fh->clients, client, NULL); fh->refcount--; if (fh->refcount == 0 && fh->finfo.mount) { rate_free (fh->out_bitrate); fh->out_bitrate = rate_setup (10000, 1000); if ((fh->finfo.flags & FS_FALLBACK) == 0) { if (fh->finfo.flags & FS_DELETE) { thread_mutex_unlock (&fh->lock); _delete_fh (fh); return; } else { DEBUG1 ("setting timeout as no clients on %s", fh->finfo.mount); fh->expire = time(NULL) + 10; } } } thread_mutex_unlock (&fh->lock); }
void fserve_shutdown(void) { fserve_running = 0; if (mimetypes) avl_tree_free (mimetypes, _delete_mapping); if (fh_cache) { int count = 20; avl_delete (fh_cache, &no_file, NULL); while (fh_cache->length > 1 && count) { fh_node *fh = fh_cache->root->right->key; if (fh && fh->refcount == 0) { remove_fh_from_cache (fh); continue; } DEBUG1 ("waiting for %u entries to clear", fh_cache->length); thread_sleep (100000); count--; } avl_tree_free (fh_cache, _delete_fh); } thread_spin_destroy (&pending_lock); #ifndef HAVE_PREAD thread_mutex_destroy (&seekread_lock); #endif INFO0("file serving stopped"); }
static int seqmod_op_cleanup( Operation *op, SlapReply *rs ) { slap_callback *sc = op->o_callback; seqmod_info *sm = sc->sc_private; modtarget *mt, mtdummy; Avlnode *av; mtdummy.mt_op = op; /* This op is done, remove it */ ldap_pvt_thread_mutex_lock( &sm->sm_mutex ); av = avl_find2( sm->sm_mods, &mtdummy, sm_avl_cmp ); assert(av != NULL); mt = av->avl_data; /* If there are more, promote the next one */ if ( mt->mt_next ) { av->avl_data = mt->mt_next; mt->mt_next->mt_tail = mt->mt_tail; } else { avl_delete( &sm->sm_mods, mt, sm_avl_cmp ); } ldap_pvt_thread_mutex_unlock( &sm->sm_mutex ); op->o_callback = sc->sc_next; op->o_tmpfree( sc, op->o_tmpmemctx ); return 0; }
/** * Check the version number of all route paths hanging off a route entry. * If a route does not match the current routing tree number, remove it * from the global originator tree for that rt_entry. * Reset the best route pointer. */ static void olsr_delete_outdated_routes(struct rt_entry *rt) { struct rt_path *rtp; struct avl_node *rtp_tree_node, *next_rtp_tree_node; for (rtp_tree_node = avl_walk_first(&rt->rt_path_tree); rtp_tree_node != NULL; rtp_tree_node = next_rtp_tree_node) { /* * pre-fetch the next node before loosing context. */ next_rtp_tree_node = avl_walk_next(rtp_tree_node); rtp = rtp_tree2rtp(rtp_tree_node); /* * check the version number which gets incremented on every SPF run. * comparing for unequalness avoids handling version number wraps. */ if (routingtree_version != rtp->rtp_version) { /* remove from the originator tree */ avl_delete(&rt->rt_path_tree, rtp_tree_node); rtp->rtp_rt = NULL; if (rt->rt_best == rtp) { rt->rt_best = NULL; } } } }
END_TEST START_TEST(test_uuid_tree) { avl_tree_t *tree = avl_uuid_new(); uuid_t u1, u2, u3, u4, u5; uuid_generate(u1); uuid_generate(u2); uuid_generate(u3); uuid_generate(u4); uuid_generate(u5); avl_insert(tree, u1, (void*)1234); avl_insert(tree, u2, (void*)12345); avl_insert(tree, u3, (void*)123456); avl_insert(tree, u4, (void*)1234567); avl_insert(tree, u5, (void*)12345678); fail_unless(avl_find(tree, u1) == (void*)1234, "could not find u1"); fail_unless(avl_find(tree, u2) == (void*)12345, "could not find u2"); fail_unless(avl_find(tree, u3) == (void*)123456, "could not find u3"); fail_unless(avl_find(tree, u4) == (void*)1234567, "could not find u4"); fail_unless(avl_find(tree, u5) == (void*)12345678, "could not find u5"); avl_delete(tree); }
int main(void) { avl_tree *tree; avl_node *cur; tree = avl_create(int_cmp); int nums[] = {58, 98, 43, 74, 74, 65, 93, 81, 76, 6, 78, 73, 62, 84, 48, 21, 15, 41, 36, 98}; // int nums[] = {1,2,3,4,5,6,7}; for(int i = 0; i < 20; i++) { avl_insert(tree, &nums[i]); } for(int i = 0; i < 5; i++) { // bst_print((bst*)tree, tree_print); // printf("\nremoving: %d\n\n", nums[i]); avl_delete(tree, &nums[i]); // bst_print((bst*)tree, tree_print); // printf("\n===========================\n\n"); } bst_print((bst*)tree, tree_print); return 0; }
int sock_del (SOCKET s) { ice_socket_t *is, *ds; xa_debug (3, "DEBUG: sock_del(): Removing socket %d", s); if (!sock_valid (s)) { xa_debug (1, "WARNING: Tried to remove invalid socket %d", s); return -1; } is = sock_find (s); if (!is) { xa_debug (1, "WARNING: Tried to remove a nonlisted socket %d", s); return -1; } thread_mutex_lock (&sock_mutex); ds = avl_delete (sock_sockets, is); if (ds) { nfree (ds); thread_mutex_unlock (&sock_mutex); return 1; } thread_mutex_unlock (&sock_mutex); return -1; }
static void remove_from_fh (fh_node *fh, client_t *client) { thread_mutex_lock (&fh->lock); fh->refcount--; if (fh->clients) { avl_delete (fh->clients, client, NULL); if ((fh->refcount != fh->clients->length && fh->finfo.mount) || ((fh->refcount != fh->clients->length+1) && fh->finfo.mount == NULL)) ERROR3 (" on %s, with ref %d, len %d", fh->finfo.mount, fh->refcount, fh->clients->length); } if (fh->refcount == 0 && fh->finfo.mount) { rate_free (fh->out_bitrate); if ((fh->finfo.flags & FS_FALLBACK) == 0) { fh->out_bitrate = NULL; if (fh->finfo.flags & FS_DELETE) { thread_mutex_unlock (&fh->lock); _delete_fh (fh); return; } DEBUG1 ("setting timeout as no clients on %s", fh->finfo.mount); fh->expire = time(NULL) + 10; } fh->out_bitrate = rate_setup (10000, 1000); } thread_mutex_unlock (&fh->lock); }
static void process_global_event (stats_event_t *event) { stats_node_t *node; /* ICECAST_LOG_DEBUG("global event %s %s %d", event->name, event->value, event->action); */ if (event->action == STATS_EVENT_REMOVE) { /* we're deleting */ node = _find_node(_stats.global_tree, event->name); if (node != NULL) avl_delete(_stats.global_tree, (void *)node, _free_stats); return; } node = _find_node(_stats.global_tree, event->name); if (node) { modify_node_event (node, event); } else { /* add node */ node = (stats_node_t *)calloc(1, sizeof(stats_node_t)); node->name = (char *)strdup(event->name); node->value = (char *)strdup(event->value); avl_insert(_stats.global_tree, (void *)node); } }
/* * Called from a source, who wants to see if the pool has any connections * in stock for it. * Returns NULL on errors. * Assert Class: 3 */ connection_t * pool_get_my_clients (const source_t *source) { avl_traverser trav = {0}; connection_t *clicon = NULL; if (!source) { xa_debug (1, "WARNING: pool_get_my_clients() called with NULL source!"); return NULL; } /* Acquire mutex lock */ pool_lock_write (); /* Search for clients for this source */ while ((clicon = avl_traverse (pool, &trav))) if (clicon->food.client->source == source) break; /* If found, remove it from the pool */ if (clicon) if (avl_delete (pool, clicon) == NULL) xa_debug (1, "WARNING: pool_get_my_clients(): Connection Pool Security Comprimised!"); /* Release mutex lock */ pool_unlock_write (); return clicon; }
/* Delete ITEM from TREE when you know that ITEM must be in TREE. For debugging purposes. */ void * (avl_force_delete) (avl_tree *tree, void *item) { void *found = avl_delete (tree, item); assert (found != NULL); return found; }
/** * Release an olsr ipip tunnel. Tunnel will be deleted * if this was the last user * @param t pointer to olsr_iptunnel_entry */ static void internal_olsr_os_del_ipip_tunnel(struct olsr_iptunnel_entry *t, bool cleanup) { if (!cleanup) { if (t->usage == 0) { return; } t->usage--; if (t->usage > 0) { return; } } olsr_if_set_state(t->if_name, false); if (olsr_cnf->ip_version == AF_INET) { os_ip4_tunnel(t->if_name, NULL); } else { #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,24) os_ip6_tunnel(t->if_name, NULL); #endif } avl_delete(&tunnel_tree, &t->node); if (!cleanup) { olsr_cookie_free(tunnel_cookie, t); } }
/* This removes any source stats from virtual mountpoints, ie mountpoints * where no source_t exists. This function requires the global sources lock * to be held before calling. */ void stats_clear_virtual_mounts (void) { avl_node *snode; avl_tree_wlock (_stats.source_tree); snode = avl_get_first(_stats.source_tree); while (snode) { stats_source_t *src = (stats_source_t *)snode->key; source_t *source = source_find_mount_raw (src->source); if (source == NULL) { stats_node_t *node; avl_tree_wlock (src->stats_tree); node = _find_node (src->stats_tree, "fallback"); if (node == NULL) { /* no source_t and no fallback file stat, so delete */ snode = avl_get_next (snode); avl_delete (_stats.source_tree, src, _free_source_stats); continue; } avl_tree_unlock (src->stats_tree); } snode = avl_get_next (snode); } avl_tree_unlock (_stats.source_tree); }
/* free handle data */ static void free_handle_data(PER_HANDLE_DATA* handle_data) { SOCKET sockfd; assert(handle_data); sockfd = handle_data->socket; avl_delete(default_loop.connection_data, (avl_key_t)sockfd); free(handle_data); }
// erase an entry void avl_erase(sb_avl * instance, void * key) { avl_node * v = avl_finder(key, avl_root(instance), instance->cmp_keys); if ( v == NULL ) { return; } avl_delete(instance, v); }
void connection_release_banned_ip (const char *ip) { if (banned_ip.contents) { global_lock(); avl_delete (banned_ip.contents, (void*)ip, cache_treenode_free); global_unlock(); } }
int DGL_DEL_EDGE_FUNC(dglGraph_s * pgraph, dglInt32_t nEdge) { #if defined(_DGL_V1) pgraph->iErrno = DGL_ERR_NotSupported; return -pgraph->iErrno; #else dglTreeEdge_s *pEdgeItem, findEdgeItem; dglInt32_t *pEdge; if (pgraph->Flags & DGL_GS_FLAT) { pgraph->iErrno = DGL_ERR_BadOnFlatGraph; return -pgraph->iErrno; } if (pgraph->pEdgeTree == NULL) { pgraph->iErrno = DGL_ERR_UnexpectedNullPointer; return -pgraph->iErrno; } findEdgeItem.nKey = nEdge; if ((pEdgeItem = avl_find(pgraph->pEdgeTree, &findEdgeItem)) == NULL) { pgraph->iErrno = DGL_ERR_EdgeNotFound; return -pgraph->iErrno; } pEdge = pEdgeItem->pv; if (DGL_DEL_NODE_INEDGE_FUNC (pgraph, DGL_EDGE_TAILNODE_OFFSET(pEdge), DGL_EDGE_ID(pEdge)) < 0) { return -pgraph->iErrno; } if (DGL_DEL_NODE_OUTEDGE_FUNC (pgraph, DGL_EDGE_HEADNODE_OFFSET(pEdge), DGL_EDGE_ID(pEdge)) < 0) { return -pgraph->iErrno; } /* prioritizer sync */ if (pgraph->nOptions & DGL_GO_EdgePrioritize_COST) { if (dgl_edge_prioritizer_del (pgraph, DGL_EDGE_ID(pEdge), DGL_EDGE_COST(pEdge)) < 0) { return -pgraph->iErrno; } } /* */ pgraph->cEdge--; pgraph->nnCost -= (dglInt64_t) DGL_EDGE_COST(pEdge); avl_delete(pgraph->pEdgeTree, pEdgeItem); dglTreeEdgeCancel(pEdgeItem, NULL); return 0; #endif }
void httpp_deletevar(http_parser_t *parser, const char *name) { http_var_t var; if (parser == NULL || name == NULL) return; var.name = (char*)name; var.value = NULL; avl_delete(parser->vars, (void *)&var, _free_vars); }
void thread_mutex_destroy (mutex_t *mutex) { pthread_mutex_destroy(&mutex->sys_mutex); #ifdef DEBUG_MUTEXES _mutex_lock(&_mutextree_mutex); avl_delete(_mutextree, mutex, _free_mutex); _mutex_unlock(&_mutextree_mutex); #endif }
void thread_join(thread_type *thread) { void *ret; int i; i = pthread_join(thread->sys_thread, &ret); _mutex_lock(&_threadtree_mutex); avl_delete(_threadtree, thread, _free_thread); _mutex_unlock(&_threadtree_mutex); }