Beispiel #1
0
void hash_update(){
	/*move words from the temporary hash to the permanent hash*/
	word *cw;
	while (twords){
		cw = twords;
		word *tw;
		HASH_FIND(hh, words, cw->s, strlen(cw->s), tw);
		if(tw){
			/*exists; update it*/
			if(cw->h && cw->t) tw->ht += 1;
			else if (cw->h) tw->h += 1;
			else if (cw->t) tw->t += 1;
			tw->occ += cw->occ;
			HASH_DELETE(hh2, twords, cw);
			free(cw->s);
			free(cw);
		}
		else {
			/*not there; add it*/
			HASH_ADD_KEYPTR(hh, words, cw->s, strlen(cw->s), cw);
			cw->ht = 0;
			if(cw->h && cw->t) {
				cw->ht = 1;
				cw->h = 0;
				cw->t = 0;
			}
			HASH_DELETE(hh2, twords, cw);
		}
	}
	
}
Beispiel #2
0
int free_peer_id(int peer_id) {
  struct io_peer *peer;
  HASH_FIND(hh_id, peers_id, &peer_id, sizeof(int), peer);
  if (peer == NULL) {
    fprintf(stderr, "Try to free id %d but doesn't exist\n", peer_id);
    return -1;
  }

  HASH_DELETE(hh_id, peers_id, peer);
  HASH_DELETE(hh_addr, peers_addr, peer);
  return 0;
}
Beispiel #3
0
void sdf_delete_hash_block(sdf_file_t *h, sdf_block_t *b)
{
    sdf_block_t *bb = NULL;

    HASH_FIND(hh1, h->hashed_blocks_by_id, b->id, strlen(b->id), bb);
    if (bb != NULL && b == bb)
        HASH_DELETE(hh1, h->hashed_blocks_by_id, b);

    HASH_FIND(hh2, h->hashed_blocks_by_name, b->name, strlen(b->name), bb);
    if (bb != NULL && b == bb)
        HASH_DELETE(hh2, h->hashed_blocks_by_name, b);
}
Beispiel #4
0
static inline void
coap_delete_payload(coap_payload_t *payload) {
  if (payload) {
    coap_dynamic_uri_t *uri;
    HASH_FIND(hh, test_dynamic_uris, 
	      payload->resource_key, sizeof(coap_key_t), uri);
    if (uri) {
      HASH_DELETE(hh, test_dynamic_uris, uri);
      coap_free(uri);
    }
  }

  HASH_DELETE(hh, test_resources, payload);
  coap_free(payload);
}
/** untrap packets that have become deliverable
  * @arg dst destination with discovery waiting
  * @arg c callback to send the packets
  * @returns count of packets now trapped for this dst
  */
int untrap_packets(ara_address_t dst, dessert_meshrxcb_t* c) {
    packettrap_t* mytrap = NULL;
    trapped_packet_t* mypkt = NULL;
    int i = 0;

    pthread_rwlock_wrlock(&traped_packets_lock);
    HASH_FIND(hh, traped_packets, dst, sizeof(dst), mytrap);

    if(mytrap != NULL) {
        HASH_DELETE(hh, traped_packets, mytrap);
    }

    pthread_rwlock_unlock(&traped_packets_lock);

    /* untrap all packets */
    if(mytrap != NULL) {
        for(mypkt = mytrap->pkgs; mypkt->pkg != NULL; mypkt++) {
            if(c != NULL) {
                c(mypkt->pkg, mypkt->len, mypkt->proc, NULL, mypkt->id);
            }

            dessert_msg_destroy(mypkt->pkg);
            dessert_msg_proc_destroy(mypkt->proc);
            i++;
        }

        free(mytrap->pkgs);
        free(mytrap);
    }

    return(i);
}
Beispiel #6
0
int main() {
    int i;
    example_user_t *user, *users=NULL, *ausers=NULL, *tmp;

    /* create elements */
    for(i=0;i<10;i++) {
        user = (example_user_t*)m_malloc(sizeof(example_user_t));
        user->id = i;
        HASH_ADD_INT(users,id,user);
    }

    for(user=users; user; user=(example_user_t*)(user->hh.next)) {
        printf("user %d\n", user->id);
    }

    /* now select some users into ausers */
    HASH_SELECT(ah,ausers,hh,users,evens);
    HASH_SRT(ah,ausers,idcmp);

    for(user=ausers; user; user=(example_user_t*)(user->ah.next)) {
        printf("auser %d\n", user->id);
    }
   
	/* free memory */
	HASH_ITER(ah, ausers, user, tmp) {
		HASH_DELETE(ah, ausers, user);     /* delete; users advances to next */
	}
Beispiel #7
0
/**********************************************************************
Takes a block out of the LRU list and page hash table and sets the block
state to BUF_BLOCK_REMOVE_HASH. */
static
void
buf_LRU_block_remove_hashed_page(
/*=============================*/
	buf_block_t*	block)	/* in: block, must contain a file page and
				be in a state where it can be freed; there
				may or may not be a hash index to the page */
{
	ut_ad(mutex_own(&(buf_pool->mutex)));
	ut_ad(mutex_own(&block->mutex));
	ut_ad(block);

	ut_a(block->state == BUF_BLOCK_FILE_PAGE);
	ut_a(block->io_fix == 0);
	ut_a(block->buf_fix_count == 0);
	ut_a(ut_dulint_cmp(block->oldest_modification, ut_dulint_zero) == 0);

	buf_LRU_remove_block(block);

	buf_pool->freed_page_clock += 1;

	/* Note that if AWE is enabled the block may not have a frame at all */

	buf_block_modify_clock_inc(block);

	if (block != buf_page_hash_get(block->space, block->offset)) {
		fprintf(stderr,
			"InnoDB: Error: page %lu %lu not found"
			" in the hash table\n",
			(ulong) block->space,
			(ulong) block->offset);
		if (buf_page_hash_get(block->space, block->offset)) {
			fprintf(stderr,
				"InnoDB: In hash table we find block"
				" %p of %lu %lu which is not %p\n",
				(void*) buf_page_hash_get
				(block->space, block->offset),
				(ulong) buf_page_hash_get
				(block->space, block->offset)->space,
				(ulong) buf_page_hash_get
				(block->space, block->offset)->offset,
				(void*) block);
		}

#ifdef UNIV_DEBUG
		buf_print();
		buf_LRU_print();
		buf_validate();
		buf_LRU_validate();
#endif
		ut_a(0);
	}

	HASH_DELETE(buf_block_t, hash, buf_pool->page_hash,
		    buf_page_address_fold(block->space, block->offset),
		    block);

	UNIV_MEM_INVALID(block->frame, UNIV_PAGE_SIZE);
	block->state = BUF_BLOCK_REMOVE_HASH;
}
Beispiel #8
0
static void
FcitxNotifyItemRemoveInternal(FcitxNotify *notify, FcitxNotifyItem *item)
{
    if (item->intern_id) {
        HASH_DELETE(intern_hh, notify->intern_table, item);
        item->intern_id = 0;
    }
}
Beispiel #9
0
void _xcb_im_handle_disconnect(xcb_im_t* im,
                               xcb_im_client_table_t* client,
                               const xcb_im_proto_header_t* hdr,
                               uint8_t* data,
                               bool *del)
{
    // disconnect doesn't come with message, so we skip parse.

    if (im->callback) {
        im->callback(im, &client->c, hdr, NULL, im->user_data);
    }

    HASH_DELETE(hh2, im->clients_by_win, client);
    HASH_DELETE(hh1, im->clients_by_id, client);
    xcb_destroy_window(im->conn, client->c.accept_win);
    im->free_list = client;
}
Beispiel #10
0
/**
 * Remove session from storage.
 * @param[in] sess
 */
void session_remove(struct zsession *sess)
{
    size_t sidx = STORAGE_IDX(sess->ip);
    pthread_rwlock_wrlock(&zinst()->sessions_lock[sidx]);
    HASH_DELETE(hh, zinst()->sessions[sidx], sess);
    pthread_rwlock_unlock(&zinst()->sessions_lock[sidx]);
    session_release(sess); // release from session hash
}
Beispiel #11
0
static void
FcitxNotifyItemRemoveGlobal(FcitxNotify *notify, FcitxNotifyItem *item)
{
    if (item->global_id) {
        HASH_DELETE(global_hh, notify->global_table, item);
        item->global_id = 0;
    }
}
Beispiel #12
0
void roster_deinit() {
	roster_item_t* current_item;

	while (roster) {
		current_item = roster;
		HASH_DELETE(hh, roster, current_item);
		roster_item_free(current_item);
	}
}
Beispiel #13
0
/******************** v_cose() ********************************
transmit all the packets not yet transmitted, then close the connection
***************************************************************/
int v_close(int socket) {

	socket_t *so = fd_lookup(socket);
	
	if(so == NULL) {
		printf(_RED_"v_close: socket %d does not exist"_NORMAL_"\n", socket);
		return -EBADF;
	}
#ifdef DEBUG
	printf(_BLUE_"v_close: socket %d "_NORMAL_"\n", socket);
#endif

	//while(!CB_EMPTY(socket->sendw->buf)){
	//	v_shutdown(socket, SHUTDOWN_READ);
	//}
	
	if(so->state == LISTENING) return 0;


	//this hack doesn't work sometimes
	//for example, retransmission queue being empty doesn't always mean
	//that everything has been sent (sent packet might have been in the process of
	//being queued for retransmission)
	
	seg_t *el;
	int count;
	DL_COUNT(so->sendw->retrans_q_head,el,count);
	int sum = count + CB_SIZE(so->sendw->buf) + CB_SIZE(so->recvw->buf)
		+ so->recvw->oor_q_size;
	int newsum = sum;
	//TODO shut down sending window
	while(!CB_EMPTY(so->sendw->buf) || !CB_EMPTY(so->recvw->buf)
		|| count || so->recvw->oor_q_size){

		#ifdef DEBUG
		if(sum != newsum){
			printf(_BRED_"V_CLOSED STALLED-----------\n[retransq %d], [sendwindow %d], [recvwindow %d], [oorq %d]\n"_NORMAL_,
				count, CB_SIZE(so->sendw->buf), CB_SIZE(so->recvw->buf), so->recvw->oor_q_size);
			sum = newsum;
		}
		#endif

		newsum = count + CB_SIZE(so->sendw->buf) + CB_SIZE(so->recvw->buf)
			+ so->recvw->oor_q_size;
		DL_COUNT(so->sendw->retrans_q_head,el,count);
	}

	//TODO memory stuff
	printf(_BRED_"---CANCELING THREAD, DELETING SOCKET---\n"_NORMAL_);
	v_shutdown(socket, SHUTDOWN_BOTH);
	pthread_cancel(so->th);
	HASH_DELETE(hh1, fd_list, so);

	return 0;

}
Beispiel #14
0
void window_destroy(Window id)
{
	window_t *window;
	
	window = window_list_remove(id);
	
	HASH_DELETE(hh, window_map, window);
	
	free(window);
}
Beispiel #15
0
/**
 * Finds an interned string in the interned strings key. If found the string
 * will be "touched", i.e. marked as most recently used. The internedStringsLock
 * MUST be held when calling this function.
 */
static Object* findInternedString(Env* env, const char* s) {
    CacheEntry* cacheEntry;
    HASH_FIND_STR(internedStrings, s, cacheEntry);
    if (cacheEntry) {
        // Touch the string
        HASH_DELETE(hh, internedStrings, cacheEntry);
        HASH_ADD_KEYPTR(hh, internedStrings, cacheEntry->key, strlen(cacheEntry->key), cacheEntry);
        return cacheEntry->string;
    }
    return NULL;
}
Beispiel #16
0
void sdf_hash_block(sdf_file_t *h, sdf_block_t *b)
{
    sdf_block_t *bb = NULL;

    HASH_FIND(hh1, h->hashed_blocks_by_id, b->id, strlen(b->id), bb);
    if (bb != NULL && b != bb) {
        HASH_DELETE(hh1, h->hashed_blocks_by_id, bb);
        bb = NULL;
    }
    if (!bb)
        HASH_ADD_KEYPTR(hh1, h->hashed_blocks_by_id, b->id, strlen(b->id), b);

    HASH_FIND(hh2, h->hashed_blocks_by_name, b->name, strlen(b->name), bb);
    if (bb != NULL && b != bb) {
        HASH_DELETE(hh2, h->hashed_blocks_by_name, bb);
        bb = NULL;
    }
    if (!bb)
        HASH_ADD_KEYPTR(hh2, h->hashed_blocks_by_name, b->name,
                strlen(b->name), b);
}
Beispiel #17
0
char *find_in_cache(char *key)
{
    struct CacheEntry *entry;
    HASH_FIND_STR(cache, key, entry);
    if (entry) {
        // remove it (so the subsequent add will throw it on the front of the list)
        HASH_DELETE(hh, cache, entry);
        HASH_ADD_KEYPTR(hh, cache, entry->key, strlen(entry->key), entry);
        return entry->value;
    }
    return NULL;
}
Beispiel #18
0
static void
pkg_repo_signatures_free(struct sig_cert *sc)
{
	struct sig_cert *s, *stmp;

	HASH_ITER(hh, sc, s, stmp) {
		HASH_DELETE(hh, sc, s);
		free(s->sig);
		if (s->cert_allocated)
			free(s->cert);
		free(s);
	}
Beispiel #19
0
void FcitxIsoCodesFree(FcitxIsoCodes* isocodes)
{
    FcitxIsoCodes639Entry* isocodes639 = isocodes->iso6392B;
    while (isocodes639) {
        FcitxIsoCodes639Entry* curisocodes639 = isocodes639;
        HASH_DELETE(hh1, isocodes639, curisocodes639);
    }
    
    isocodes639 = isocodes->iso6392T;
    while (isocodes639) {
        FcitxIsoCodes639Entry* curisocodes639 = isocodes639;
        HASH_DELETE(hh2, isocodes639, curisocodes639);
        FcitxIsoCodes639EntryFree(curisocodes639);
    }
    FcitxIsoCodes3166Entry* isocodes3166 = isocodes->iso3166;
    while (isocodes3166) {
        FcitxIsoCodes3166Entry* curisocodes3166 = isocodes3166;
        HASH_DEL(isocodes3166, curisocodes3166);
        FcitxIsoCodes3166EntryFree(curisocodes3166);
    }
    
    free(isocodes);
}
Beispiel #20
0
static int
plugin_deregister(const char *key)
{
  plugin_ht_t *item;

  HASH_FIND(hh, plugin_head, key, strlen(key), item);
  if (!item)
    return -1;

  HASH_DELETE(hh, plugin_head, item);

  free(item);

  return 0;
}
Beispiel #21
0
void free_profiler_stats()
{
    int i;
    struct ProfilerEntry *entry, *tmp_entry;
    
    HASH_ITER(hh, profiler_entries, entry, tmp_entry) {
        HASH_DELETE(hh, profiler_entries, entry);
        for (i = 0; i < STAT_WINDOW_COUNT; i++) {
            free(entry->stat->data[i]);
        }
        free(entry->stat->data);
        free(entry->stat->name);
        free(entry->stat);
        free(entry);
    }
Beispiel #22
0
void Sinproc_socket_bound_rm_conn(nitro_inproc_socket_t *b,
                                  nitro_inproc_socket_t *c) {

    pthread_rwlock_wrlock(&b->link_lock);

    HASH_DELETE(bound_hh, b->registry, c);

    if (b->current == c) {
        b->current =  (c->next == c) ? NULL : c->next;
    }

    CDL_DELETE(b->links, c);
    --b->num_links;
    pthread_rwlock_unlock(&b->link_lock);
}
int _mosquitto_socket_close(struct mosquitto *mosq)
#endif
{
	int rc = 0;

	assert(mosq);
#ifdef WITH_TLS
	if(mosq->ssl){
		SSL_shutdown(mosq->ssl);
		SSL_free(mosq->ssl);
		mosq->ssl = NULL;
	}
	if(mosq->ssl_ctx){
		SSL_CTX_free(mosq->ssl_ctx);
		mosq->ssl_ctx = NULL;
	}
#endif

	if((int)mosq->sock >= 0){
#ifdef WITH_BROKER
		HASH_DELETE(hh_sock, db->contexts_by_sock, mosq);
#endif
		rc = COMPAT_CLOSE(mosq->sock);
		_mosquitto_log_printf(NULL,MOSQ_LOG_INFO,"net_mosq.c:mosquitto_socket_close:  socket(%d) closed .... ",mosq->sock);
		mosq->sock = INVALID_SOCKET;
#ifdef WITH_WEBSOCKETS
	}else if(mosq->sock == WEBSOCKET_CLIENT){
		if(mosq->state != mosq_cs_disconnecting){
			mosq->state = mosq_cs_disconnect_ws;
		}
		if(mosq->wsi){
			libwebsocket_callback_on_writable(mosq->ws_context, mosq->wsi);
		}
		mosq->sock = INVALID_SOCKET;
#endif
	}

#ifdef WITH_BROKER
	if(mosq->listener){
		mosq->listener->client_count--;
		assert(mosq->listener->client_count >= 0);
		mosq->listener = NULL;
	}
#endif

	return rc;
}
Beispiel #24
0
static void
fcitx_handler_table_free_key(FcitxHandlerTable *table,
                             FcitxHandlerKey *key_struct)
{
    unsigned int id;
    unsigned int next_id;
    FcitxHandlerObj *obj_struct;
    for (id = key_struct->first;id != FCITX_OBJECT_POOL_INVALID_ID;id = next_id) {
        obj_struct = fcitx_handler_table_get_obj(table, id);
        next_id = obj_struct->next;
        if (table->free_func)
            table->free_func(obj_struct + 1);
        fcitx_obj_pool_free_id(table->objs, id);
    }
    HASH_DELETE(hh, table->keys, key_struct);
    free(key_struct);
}
Beispiel #25
0
void 
hnd_delete_resource(coap_context_t  *ctx, struct coap_resource_t *resource, 
		    coap_address_t *peer, coap_pdu_t *request, str *token,
		    coap_pdu_t *response, void *userdata) {
  rd_t *rd = NULL;

  HASH_FIND(hh, resources, resource->key, sizeof(coap_key_t), rd);
  if (rd) {
    HASH_DELETE(hh, resources, rd);
    rd_delete(rd);
  }
  /* FIXME: link attributes for resource have been created dynamically
   * using coap_malloc() and must be released. */
  coap_delete_resource(ctx, resource->key);

  response->hdr->code = COAP_RESPONSE_CODE(202);
}
Beispiel #26
0
static int
plugin_unload(plugin_handle_ht_t *item)
{
  prc_plugin_sym_t *reg_symi;
  int err;
  char *error;

  {
    prc_plugin_dtor_t *reg_dtor;

    *(void **)(&reg_dtor) = dlsym(item->handle, "prc_dtor");
    if ((error = dlerror()) == NULL) {
      err = (*reg_dtor)();
      if (err < 0) {
        fprintf(stderr, "prc_dtor(): %d\n", err);
        return -1;
      }
    }
  } /* ... */

  {
    for (reg_symi = item->sym; (*reg_symi).key != NULL; reg_symi++) {

      err = plugin_deregister((*reg_symi).key);

      assert(!err);
    }
  } /* ... */

  {
    void *handle;
    handle = item->handle;
    HASH_DELETE(hh, handle_head, item);
    free(item->name);
    free(item);

    err = dlclose(handle);
    if (err < 0) {
      fprintf(stderr, "%s\n", dlerror());
      return -1;
    }
  } /* ... */

  return 0;
}
Beispiel #27
0
/**
 * Adds a string to the cache of interned string. The string must not already be
 * interned.  The internedStringsLock MUST be held when calling this function.
 */
static jboolean addInternedString(Env* env, const char* s,  Object* string) {
    CacheEntry* cacheEntry = allocateMemoryOfKind(env, sizeof(CacheEntry), cacheEntryGCKind);
    if (!cacheEntry) {
        return FALSE;
    }

    cacheEntry->key = s;
    cacheEntry->string = string;
    HASH_ADD_KEYPTR(hh, internedStrings, cacheEntry->key, strlen(cacheEntry->key), cacheEntry);

    // prune the cache to MAX_CACHE_SIZE
    if (HASH_COUNT(internedStrings) >= MAX_CACHE_SIZE) {
        CacheEntry* tmpEntry;
        HASH_ITER(hh, internedStrings, cacheEntry, tmpEntry) {
            // prune the first entry (loop is based on insertion order so this deletes the oldest item)
            HASH_DELETE(hh, internedStrings, cacheEntry);
            break;
        }
Beispiel #28
0
void add_to_cache(char *key, char *value)
{
    struct CacheEntry *entry, *tmp_entry;
    entry = malloc(sizeof(struct CacheEntry));
    entry->key = strdup(key);
    entry->value = strdup(value);
    HASH_ADD_KEYPTR(hh, cache, entry->key, strlen(entry->key), entry);
    
    // prune the cache to MAX_CACHE_SIZE
    if (HASH_COUNT(cache) >= MAX_CACHE_SIZE) {
        while (HASH_ITER(hh, cache, entry, tmp_entry)) {
            // prune the first entry (loop is based on insertion order so this deletes the oldest item)
            HASH_DELETE(hh, cache, entry);
            free(entry->key);
            free(entry->value);
            free(entry);
            break;
        }
    }
}
Beispiel #29
0
static int check_symloop_leave(dirkey_t *dirkey) {
#ifdef _WIN32
    return SYMLOOP_OK;
#else
    symdir_t *item_found = NULL;

    if (dirkey->dev == 0 && dirkey->ino == 0) {
        return SYMLOOP_ERROR;
    }

    HASH_FIND(hh, symhash, dirkey, sizeof(dirkey_t), item_found);
    if (!item_found) {
        log_err("item not found! weird stuff...\n");
        return SYMLOOP_ERROR;
    }

    HASH_DELETE(hh, symhash, item_found);
    free(item_found);
    return SYMLOOP_OK;
#endif
}
Beispiel #30
0
/* called by myclose() on a passive socket */
void _mysock_close_passive_socket(mysock_context_t *ctx)
{
    listen_queue_t *q;

    assert(ctx && ctx->listening && ctx->bound);

    PTHREAD_CALL(pthread_rwlock_wrlock(&listen_lock));
    if ((q = _get_connection_queue(ctx)) != NULL)
    {
        /* close any queued connections that haven't been passed up to the
         * user via myaccept()...
         */
        unsigned int k;
        completed_connect_t *connect_iter;

        for (k = 0; k < q->max_len; ++k)
        {
            if (q->connection_queue[k].sd != -1)
                myclose(q->connection_queue[k].sd);
        }
        free(q->connection_queue);

        for (connect_iter = q->completed_queue; connect_iter; )
        {
            /* note: socket was closed by the preceding loop */
            completed_connect_t *next = connect_iter->next;
            free(connect_iter);
            connect_iter = next;
        }

        PTHREAD_CALL(pthread_cond_destroy(&q->connection_cond));
        PTHREAD_CALL(pthread_mutex_destroy(&q->connection_lock));

        HASH_DELETE(listen_table, ctx->my_sd);
        memset(q, 0, sizeof(*q));
        free(q);
    }
    PTHREAD_CALL(pthread_rwlock_unlock(&listen_lock));
}